OpenCV Python错误断言失败(scn==3 | | scn==4)

2024-04-18 12:24:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始在Python中使用OpenCV,遇到了一个断言错误。我从tutorial复制了以下代码,但它对我不起作用。在

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),因此它甚至无法正确捕捉帧。在

到底是什么问题,我如何解决? 谢谢您。在


Tags: theimportreleaseifas断言frameopencv