How do I prevent the useb camera from becoming unstable in an OpenCV-Python environment?

Asked 2 years ago, Updated 2 years ago, 90 views

What do you want to do

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.

What's troubling you

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()

python opencv camera

2022-09-30 19:27

1 Answers

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()):


2022-09-30 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.