'Capturing video using OpenCV

I am having an issue capturing the video feed, my camera light goes on and then off when i run this code. I tried using different values as well. And my camera seems to be working. but this code is not.

import cv2

cap = cv2.VideoCapture(0) # zero instead of one

while True:
    ret, frame = cap.read()

    if not ret: # exit loop if there was problem to get frame to display
        break

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source