import cv2
import numpy as np

# Initialize the camera
cap = cv2.VideoCapture('/dev/video0')
print('opened')

c = 0
ret, frame = cap.read()
hei, wid = frame.shape[:2]
whiteimg = np.ones([hei, wid],dtype=np.uint8)*255
while True:
    
    # Capture frame-by-frame
    #   red is true if cuccess, frame is ndarray[dhei,dwidth,3] of uint8
    ret, frame = cap.read()

    # Change the frame
    frame[:hei//2,:,0] = whiteimg[:hei//2,:]-frame[:hei//2,:,0]
    frame[:,:wid//2,1] = whiteimg[:,:wid//2]-frame[:,:wid//2,1]
    frame[:,wid//4:3*wid//4,2] = whiteimg[:,:wid//2]-frame[:,wid//4:3*wid//4,2]

    # Display the resulting frame
    cv2.imshow('frame', frame)  

    # Check for user input to change the image
    if cv2.waitKey(1) == ord('q'):
        break

    # print and increase counter
    print(c)
    c+=11
    
# Release the capture and close windows
cap.release()
cv2.destroyAllWindows()
