手势识别服务器很快就报错 502
通过网络摄像头,每秒检测2次画面中的手势
无论我降低到多少fps,还是很快就报错502
b'\r\n502 Bad Gateway\r\n\r\n
502 Bad Gateway
\r\nnginx\r\n\r\n\r\n'直接用手势api的
import requests
import base64
import cv2
import time
def draw_rectangle(current_frame, start_pt, end_pt):
color = (255, 0, 0)
thickness = 2
the_processed_frame = cv2.rectangle(current_frame, start_pt, end_pt, color, thickness)
return the_processed_frame
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/gesture"
cap = cv2.VideoCapture(0)
frame_rate = 2
prev = 0
# f = open('5.jpg', 'rb')
while (True):
time_elapsed = time.time() - prev
ret, frame = cap.read()
if time_elapsed > 1. / frame_rate:
prev = time.time()
print(prev)
retval, buffer = cv2.imencode('.jpg', frame)
img = base64.b64encode(buffer)
params = {"image": img}
access_token = '*******'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
try:
if response.ok:
print(response)
display_frame = frame
if 'result' not in response.json():
print(response.json())
else:
result = response.json()['result']
for every_result in result:
if every_result['classname'] == 'Five':
print(every_result)
start_pt_x = every_result['left']
start_pt_y = every_result['top']
end_pt_x = every_result['width'] + start_pt_x
end_pt_y = every_result['height'] + start_pt_y
start_pt = (start_pt_x, start_pt_y)
end_pt = (end_pt_x, end_pt_y)
display_frame = draw_rectangle(frame, start_pt, end_pt)
else:
print('none')
except:
display_frame = frame
print(response.content)
cv2.imshow('frame', display_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
接口成功失败都是json内容返回才对。
貌似以前在交流群有别的Python开发者 循环调用百度接口就会导致502。Java循环调用就没出现这个问题。在QPS保证的情况下。
https://xasgkfp.diytrade.com/
http://xasgkfp.diytrade.com/
http://xakfp.simplesite.com/
http://cdfapiao.simplesite.com/
https://xasgkfp.diytrade.com
http://xasgkfp.diytrade.com
谢谢