錯誤詳情:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261
源碼:
import cv2 as cv clicked = False def onMouse(event,x,y,flags,param): global clicked if event == cv.EVENT_LBUTTONUP: clicked = True capture = cv.VideoCapture(0) capture.open(0) success, frame = capture.read() cv.namedWindow('mywin')
cv.setMouseCallback('mywin',onMouse)
while cv.waitKey(1)==-1 andnot clicked:
cv.imshow("mywin",frame)
success, frame = capture.read()
cv.destroyAllWindows()
capture.release()
在控制台敲入上面的命令就可以看到視頻,debug也可以,就是直接運行不行,一直報上面的錯誤,success一直為false
找網上的資料,基本上是說release和debug時OpenCV執行的dll文件(opencv_ffmpeg.dll 32位)不同導致的,也不知道到哪去設置這玩意兒......
郁悶了很久,我想是不是視頻設備需要延時,因為我在命令行上敲和在debug運行的時候都是在capture.open(0)這地方有逗留的,
所以就在下面加了行time.sleep(1)
點擊運行,喔~成功了,這也是奇葩的坑...