Home > Enterprise >  I am trying to capture video from my webcam using opencv_python
I am trying to capture video from my webcam using opencv_python

Time:10-05

I am trying to run code to show the video output of my webcam and all I am getting is a single picture. Here is my code:

import cv2
captureDevice = cv2.VideoCapture(0)
while True:
    check, frame=captureDevice.read()
    print(check)
    print(frame)
    gray=cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
    cv2.imshow('Capturing', gray)
    key=cv2.waitKey(1)
    if key==ord('q'):
        break
captureDevice.release()
cv2.destroyAllWindows()

CodePudding user response:

gray=cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)

you are using a variable gray you would have defined elsewhere. Ideally this should throw error. (Try restarting your notebook and you will see) Change it to:

gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  • Related