[SOLVED]Assertion Error in Video Capturing ? [closed]
I've just started with openCV and trying to capture frames from webcam. But when I run the code the script catures the first frame and then Execption occurs.
import cv2, time
a = 1
while True:
a = a + 1
video = cv2.VideoCapture(0, cv2.CAP_DSHOW)
check, frame = video.read()
print(frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #This is the Erroneous line
cv2.imshow("Capture", gray)
key = cv2.waitKey(1)
if key == ord("q"):
break
print(a)
video.release()
cv2.destroyAllWindows()
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
video = cv2.VideoCapture(0, cv2.CAP_DSHOW)
-- this has to go before the loop.also, the
check
value is there for a reason ....try, and come again
Code :
when
cv2.VideoCapture(0, cv2.CAP_DSHOW)
inside the loop it will call camera everytime to capture image. so it should be declared outside the loop.Is your code working or not?
Thanks. It's working Now !!