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 分钟前
pytorch的张量数据结构以及各种操作函数的底层原理
人工智能·pytorch·python
盘古开天166619 分钟前
Gemma4本地部署,零成本打造私有 AI 助手
人工智能·本地部署·智能体·gemma4·ai私有助理
浔川python社20 分钟前
张雪机车:以热爱为轮,让中国摩托驰骋世界之巅
python
zl_dfq27 分钟前
Python学习5 之【字符串】
python·学习
夜影风27 分钟前
算力租赁产业链全景分析:解构AI时代的“算力电厂”
人工智能·算力租赁
MediaTea28 分钟前
AI 术语通俗词典:矩阵乘法
人工智能·线性代数·矩阵
NHuan^_^31 分钟前
SpringBoot3 整合 SpringAI 实现ai助手(记忆)
java·人工智能·spring boot
Binary_ey33 分钟前
光刻技术第22期 | 贝叶斯压缩感知光源优化的优化技术及对比分析
人工智能·深度学习·机器学习
奔跑草-33 分钟前
【AI日报】每日AI最新消息2026-04-07
人工智能·大模型·github·开源软件