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

你可能感兴趣的:(编程相关,opencv,计算机视觉,人工智能,python)