Falsh 发送图片的两种方法

复制代码
import requests
import json
import cv2
import time
info={
    "a":"a",
    "imgsize":640
}

image=cv2.imread("1.jpg")

stime=time.time()
cv2.imwrite("1.jpg",image)

with open("1.jpg","rb") as f:
    files={"file":("123.jpg",f,"image/jpg")}
    image=cv2.imread("1.jpg")
    res=requests.post("http://127.0.0.1:10086/photo",data=info,files=files)
    print(res.content)
etime=time.time()
print(etime-stime)


time.sleep(10)


stime=time.time()
files={"file":("123.jpg",cv2.imencode(".jpg",image)[1].tobytes(),"image/jpg")}
image=cv2.imread("1.jpg")
res=requests.post("http://127.0.0.1:10086/photo",data=info,files=files)
print(res.content)
etime=time.time()
print(etime-stime)


time.sleep(10)


stime=time.time()
cv2.imwrite("1.jpg",image)
files={"file":("123.jpg",cv2.imencode(".jpg",image)[1].tobytes(),"image/jpg")}
image=cv2.imread("1.jpg")
res=requests.post("http://127.0.0.1:10086/photo",data=info,files=files)
print(res.content)
etime=time.time()
print(etime-stime)

运行时间对比:

b'{"code":200}\n'

0.22995924949645996

b'{"code":200}\n'

0.11100244522094727

b'{"code":200}\n'

0.17018818855285645

相关推荐
会编程的吕洞宾9 分钟前
Spring AI 2.0 MCP 客户端实战:让 Java AI 应用接入现成工具
java·人工智能·经验分享·后端·spring
星恒随风2 小时前
从0实现C++ AI大模型接入SDK(八):SessionManager会话管理——智能指针、原子操作、线程安全与懒加载机制
linux·服务器·开发语言·c++·人工智能
XW9632582 小时前
除湿机行业组织能力与人才地图报告
大数据·服务器·网络·数据结构·数据库·人工智能
Csvn2 小时前
WorkBuddy 使用指南:上下文、记忆、检索与任务交接单
人工智能
Csvn2 小时前
WorkBuddy 使用指南:技能、专家、连接器
人工智能
AI创界者2 小时前
Python 进阶实战(七十一章):研发效能度量、自动化质量门禁与工程规范落地实战
人工智能·python·aigc
硅谷秋水2 小时前
Genesis World 1.0
机器学习·计算机视觉·机器人
yingjie1103 小时前
快榜GEO|官网 AI 可读性自查 12 项(附 Python 检测脚本)
开发语言·人工智能·python
tryCbest3 小时前
Python 爬虫扩展篇(二):验证码的检测与人工介入——把“拦路虎”当作信号,而不是要征服的对手
开发语言·爬虫·python