I am beginner in CV. My camera crash every time. I mean camera light is ON but the there is no camera display Could someone help me? Here is the code
import cv2 as cv
import numpy as np
cap=cv.VideoCapture(0)
# read webcam untill the end
while (cap.isOpened()):
# capture frame by frame
ret,frame=cap.read()
if ret == True:
# to display frame
cv.imshow("Frame",frame)
else:
break
cv.waitKey(1)
cap.release()
cv.destroyAllWindows()
CodePudding user response:
i think you put waitKey in wrong place, I hope below code will work !
import cv2 as cv
cap = cv.VideoCapture(0)
# read webcam untill the end
while (cap.isOpened()):
# capture frame by frame
ret, frame = cap.read()
if ret == True:
# to display frame
cv.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv.destroyAllWindows()
CodePudding user response:
@tahir mehmood. I modified your code, and I tested it. Worked well.
import cv2 as cv
import numpy as np
cap=cv.VideoCapture(0)
# read webcam untill the end
while (cap.isOpened()):
# capture frame by frame
ret,frame=cap.read()
if not ret:
break
cv.imshow("Frame",frame)
cv.waitKey(1)
cap.release()
cv.destroyAllWindows()