错误详情:
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)
点击运行,喔~成功了,这也是奇葩的坑...
时间: 2024-10-11 03:04:04