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

相关推荐
xyz_CDragon18 小时前
从 RTL 到 GDSII:人与 AI 协作,用开源 EDA 工具链完成 SHA-256 芯片的 SoC 集成与签核全流程(附完整流程+代码)
人工智能·开源·芯片设计·开源 eda·caravel
咕咕AI学堂18 小时前
检索引擎深度对比:Elasticsearch vs Milvus vs Redis 在 RAG 中的定位
人工智能
Java牛马18 小时前
AI Agent 技术栈梳理(Skill / 蒸馏 / MCP / Harness)
人工智能·ai agent·蒸馏·skill·mcp·harness
IT_陈寒18 小时前
Vue的computed属性把我坑惨了,原来我一直用错姿势
前端·人工智能·后端
千维百策66618 小时前
降低 AI 辅助开发摩擦的五种模式
人工智能
大鹏说大话18 小时前
从爬虫到决策引擎:大数据下自媒体如何用Python挖掘用户痛点
开发语言·爬虫·python
Niuguangshuo18 小时前
silero-vad:超轻量级开源 VAD 实践指南
开发语言·python
有脚就行19 小时前
第38篇-LLM-API网关进阶-流式代理与内容安全
人工智能
AI英德西牛仔19 小时前
从Excel乱象到批量交付:秘塔Excel与“AI导出鸭”PC版的底层重构逻辑
人工智能·重构·excel·deepseek·ai导出鸭
w57w00019 小时前
AI可见度监测方案选型:电商、媒体公关、全球市场等场景的差异化需求与避坑指南
人工智能