# Read a video stream from camera (frame by frame)

import cv2

# Capture the device from which you want to read images
cap = cv2.VideoCapture(0) # 0 means default webcam


while True :
    
    ret, frame = cap.read() # ret is true if image is captured properly
    if not ret:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow("Video Frame1", gray_frame)
    # cv2.imshow("Video Frame2", frame)
    
    #Wait for user input - enter q to stop the loop
    key_pressed = cv2.waitKey(1) & 0xFF 
    #cv2.waitKey gives 32bit int
    #0xFF is 8bit ones
    #& gives last bits -> convert 32bits to 8bits since ascii values : 0-255(8bit)
    if key_pressed == ord('q') :
        break

cap.release() # release device
cv2.destroyAllWindows()
9ec1012c4346f520d37e5021a197304f40714c2c
<mask token>

<mask token>
while True:
    ret, frame = cap.read()
    if not ret:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('Video Frame1', gray_frame)
    key_pressed = cv2.waitKey(1) & 255
    if key_pressed == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

<mask token>
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    if not ret:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('Video Frame1', gray_frame)
    key_pressed = cv2.waitKey(1) & 255
    if key_pressed == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

import cv2
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    if not ret:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('Video Frame1', gray_frame)
    key_pressed = cv2.waitKey(1) & 255
    if key_pressed == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

# Read a video stream from camera (frame by frame)

import cv2

# Capture the device from which you want to read images
cap = cv2.VideoCapture(0) # 0 means default webcam


while True :
    
    ret, frame = cap.read() # ret is true if image is captured properly
    if not ret:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow("Video Frame1", gray_frame)
    # cv2.imshow("Video Frame2", frame)
    
    #Wait for user input - enter q to stop the loop
    key_pressed = cv2.waitKey(1) & 0xFF 
    #cv2.waitKey gives 32bit int
    #0xFF is 8bit ones
    #& gives last bits -> convert 32bits to 8bits since ascii values : 0-255(8bit)
    if key_pressed == ord('q') :
        break

cap.release() # release device
cv2.destroyAllWindows()