我在python 3和ide spider中使用请求模块。当我选择帧分辨率1920X1080和帧速率25 fps时,它毫无问题地运行到网页上。但这是我的python代码出现的延迟。当我更改帧速率10 fps或分辨率1280x720时,它可以正常运行
r = requests.get(url, auth=HTTPDigestAuth('username', 'pass'),
stream=True)
def get_frame_from_stream(r):
if(r.status_code == 200):
bytes=b''
for chunk in r.iter_content(chunk_size=None):
bytes += chunk
a = bytes.find(b'\xff\xd8')
b = bytes.find(b'\xff\xd9')
if a != -1 and b != -1:
jpg = bytes[a:b+2]
bytes = bytes[b+2:]
frame=cv2.imdecode(np.frombuffer
jpg,dtype=np.uint8)cv2.IMREAD_COLOR)
cv2.imshow('Live',frame)
time.sleep(0.004)
if cv2.waitKey(1) == 27:
exit(0)
else:
print('status code error',r.status_code)