简体   繁体   中英

Python & OpenCV : Assertion Failed with IP Camera in Exe File

I'm trying to build a simple code to test my cameras. In my code, I use these lines for webcam;

cam = cv2.VideoCapture(0)
cv2.namedWindow("test")
ret, frame = cam.read()
cv2.imshow("test", frame)

and for IP camera

myip='http://admin:wicaledon@XX.XX.XX.XXX:XXXX/stream/video/mjpeg'
cam = cv2.VideoCapture(str(myip))
cv2.namedWindow("test")
ret, frame = cam.read()
cv2.imshow("test", frame)

In PyCharm, when I run both codes, my cameras works perfectly. Also if I enter myip url in browser, ip camera shows perfectly.

But, when I build an exe file with PyInstaller , only the first code (webcam code) works. The second code shows this error;

cv2.error: OpenCV(4.1.0) C:\\projects\\opencv-python\\opencv\\modules\\highgui\\src\\window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

Where is my fault? Can you fix it please?

I suppose your problem is connected to this issue . There is a workaround suggested in this comment . It suggests to run pyinstaller as

pyinstaller -F --add-data opencv_ffmpeg410_64.dll;. script.py

I've adapted it to your OpenCV version. Make sure this dll exists anywhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM