【发布时间】:2020-04-22 20:20:38
【问题描述】:
我知道这是opencv的错误,也知道Flask和opencv无关。但是,请坚持到最后。 只有在流式传输 CV 帧时,我才会遇到这个非常奇怪的错误:
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream: Device or resource busy
我的代码:
// my camera_detector class does some AI works on the camera frame, other than that nothing special
camera = camera_detector(my_arguments)
@app.route('/')
def index():
return render_template('index.html')
def gen(camera):
while True:
print('getting frame')
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/feed')
def video_feed():
return Response(gen(camera), mimetype='multipart/x-mixed-replace; boundary=frame')
现在这就是为什么我说这只发生在 Flask 上,如果我像这样抓住相机框架:
while True:
frame = camera.get_frame()
不用烧瓶,一切都运行得很好 o_0
如果有什么不同,我在 pi4 上使用 python3.7。在将帧返回到 Flask 之前,我的相机还对 open cv、绘制框、标签产生的 camera_frame 进行了一些 AI 工作:
def get_frame(self):
ret, frame = self.camera.read()
# processing, does AI works, draw boxes and labels
ret, jpeg = cv2.imencode('.jpg', frame)
return jpeg.tobytes()
[编辑]相机信息如果有帮助:
{20-04-22 15:39}raspberrypi:~/detect pi% v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'YUYV' (YUYV 4:2:2)
[1]: 'MJPG' (Motion-JPEG, compressed)
[已解决]:下面为感兴趣的人提供答案。
【问题讨论】:
标签: opencv flask python-3.7 raspberry-pi4