I'm new to python and opencv. I have tried capturing video using cv2.VideoCapture(0), as I have my default video camera as my laptop camera. coded using pycharm and tried all the basic troubleshooting to fix the error. below is my code. but i tried for cv2.imread('a.jpg') it's working and able to see the pic
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()```
getting error like this
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/user2/PycharmProjects/FaceDetect/faceDetect.py", line 6, in <module>
cv2.imshow('frame', frame)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'