I want my USB camera connected to my PC to work with opencv-python so that I can take real-time videos and display them on the screen.
After testing the operation of the Logicool usb camera to ensure that video shooting and screen display are possible, an error occurred when I ran the program with the ELP camera under the same conditions.
I'm a beginner in the program, so I don't understand the basics, but I appreciate your cooperation.
operating environment
·visual studio 2019
·Python 3.9
·opencv-python 4.5.3.56
·Numpy 1.12.2
Device used
·Logicool C720n
·ELP-USBFHD08S-L36-J
Error Contents
error: (-215: Assertion failed) !_src.empty() in function 'cv::cvtColor'
whole code
import cv2
import numpy as np
cap=cv2.VideoCapture(1)
while(cap.isOpened()):
ret, frame = cap.read()
cv2.imshow("Flame", frame)
if cv2.waitKey(1)&0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
error:(-215:Assertion failed)!_src.empty()
There is a possibility that the frame you want to display is empty.
Instead of displaying it from the first frame, for example, throw it away for about a second from the beginning.
cap=cv2.VideoCapture(1)
for i in range (30):
ret,back=cap.read()#Throw away frames for the first second (30fps)
while(cap.isOpened()):
© 2024 OneMinuteCode. All rights reserved.