我正在使用以下代码:
def gen_frames(): # generate frame by frame from camera
while True:
# Capture frame-by-frame
success, frame = camera.read() # read the camera frame
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
#frame_resized = cv2.resize(frame,None,fx=0.75,fy=0.75)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
我收到一个错误:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
TypeError: Expected Ptr<cv::UMat> for argument 'src'
这是正常的,因为帧数组被转换为字节。但这对于 Flask 中的视频输入来说是必需的:
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen_frames(),
mimetype='multipart/x-mixed-replace; boundary=frame')
我应该如何使其发挥作用?
暮色呼如
相关分类