Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In line 7: You can't do this if/else block conditionif cv2.waitKey(1) :. It will shut down in 1 seconds. Correct way to do this.

import cv2 as cv

cap=cv.VideoCapture(0)
while(True):
    ret,frame=cap.read()
    gray = cv.cvtColor(frame ,cv.COLOR_BGR2GRAY)
    cv.imshow('frame',gray)
    key = cv.waitKey(1)
    if key == 27:
        break
cap.release()
cv.destroyAllWindows()

Btw, I'm using Raspberry pi 4 w/4gb, opencv 4.1.0, Thonny3.2, python 3.7.3.