python 调用api 传递布尔_如何将捕获图像作为二进制数据直接传递给API调用(Microsoft Cognitive Services)中使用Python进行处理...

我正在使用微软的认知服务,用python语言进行面部和情绪识别。

现在,首先我用opencv从网络摄像头捕捉图像,并将其保存在文件夹中,在API post请求中,我传递图像地址进行处理,然后获得所需的输出。

现在我想节省处理时间,想从相机捕捉图像,直接发送给处理而不需要保存。如何使用python实现这一点?

请帮助我成为编程领域的新手。在

我的代码是:while(True):

ret,img=cam.read()

faces=faceDetect.detectMultiScale(img,1.3,5)

for(x,y,w,h) in faces:

sampleNumber=sampleNumber+1

cv2.imwrite("dataset/User."+str(id)+"."+str(sampleNumber)+".jpg",img)

cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)

cv2.waitKey(10)

cv2.imshow("Face",img)

img_filename = "C:/Users/Robot 2/Desktop/codes_msc/dataSet/User."+str(id)+"."+str(sampleNumber)+".jpg"

with open(img_filename, 'rb') as f:

img_data = f.read()

header =

{

# Request headers for detection

'Content-Type': 'application/octet-stream',

'Ocp-Apim-Subscription-Key': subscription_key

}

r = requests.post(api_url,

params=params,

headers=header,

data=img_data)

#Here i don't want to pass img_data as an address i just want to pass image captured

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值