OpenCV Python错误声明失败(scn == 3 || scn == 4) [英] OpenCV Python Error Assertion failed (scn == 3 || scn == 4)

查看:396
本文介绍了OpenCV Python错误声明失败(scn == 3 || scn == 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在Python中玩弄OpenCV,并且遇到了断言错误.我从教程中复制了以下代码a>,但对我不起作用.

I just started playing around with OpenCV in Python and am running into an assertion error. I copied the following code from a tutorial, but it's not working for me.

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0) # use first webcam
if not cap.isOpened(): cap.open()

while True:
   # capture frame-by-frame
   ret, frame = cap.read()

   # our operations on the frame come here
   gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)

# display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) & 0xFF == ord('q'):
    break
# when everything is done, release the capture
cap.release()
cv.destroyAllWindows()

运行时,我得到OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor

从上方打印变量retframe时,我得到了(False,None),因此它甚至无法正确捕获帧.

When printing the variables ret and frame from above, I get (False,None), so it's not even capturing the frame correctly.

问题到底是什么?如何解决? 谢谢.

What exactly is the issue, and how can I resolve it? Thank you.

推荐答案

ret, frame = cap.read()之后,添加if not ret: continue.

某些凸轮驱动器返回无效的第一帧.

Some cam-drivers return an invalid first frame.

这篇关于OpenCV Python错误声明失败(scn == 3 || scn == 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆