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'