├── README.md └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # webcamfun 2 | 3 | open any webcam using python. 4 | 5 | Run facebook using webcam. 6 | 7 | Detail explanation [here](https://www.youtube.com/watch?v=xumx-_FGLaU) 8 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import pyautogui 4 | 5 | cap = cv2.VideoCapture(1) 6 | 7 | yellow_lower = np.array([22, 93, 0]) 8 | yellow_upper = np.array([45, 255, 255]) 9 | prev_y = 0 10 | 11 | while True: 12 | ret, frame = cap.read() 13 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 14 | mask = cv2.inRange(hsv, yellow_lower, yellow_upper) 15 | contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 16 | 17 | for c in contours: 18 | area = cv2.contourArea(c) 19 | if area > 300: 20 | x, y, w, h = cv2.boundingRect(c) 21 | cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) 22 | if y < prev_y: 23 | pyautogui.press('space') 24 | 25 | prev_y = y 26 | cv2.imshow('frame', frame) 27 | if cv2.waitKey(10) == ord('q'): 28 | break 29 | 30 | cap.release() 31 | cv2.destroyAllWindows() --------------------------------------------------------------------------------