【发布时间】:2014-03-31 00:54:21
【问题描述】:
我刚开始在 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
当从上面打印变量ret 和frame 时,我得到(False,None),所以它甚至没有正确捕获帧。
究竟是什么问题,我该如何解决? 谢谢。
【问题讨论】: