└── main.py /main.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | from PIL import ImageGrab 4 | import numpy as np 5 | import cv2 6 | from win32api import GetSystemMetrics 7 | 8 | width = GetSystemMetrics(0) 9 | height = GetSystemMetrics(1) 10 | time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S') 11 | file_name = f'{time_stamp}.mp4' 12 | fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') 13 | captured_video = cv2.VideoWriter(file_name, fourcc, 20.0, (width, height)) 14 | 15 | webcam = cv2.VideoCapture(1) 16 | 17 | while True: 18 | img = ImageGrab.grab(bbox=(0, 0, width, height)) 19 | img_np = np.array(img) 20 | img_final = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) 21 | _, frame = webcam.read() 22 | fr_height, fr_width, _ = frame.shape 23 | img_final[0:fr_height, 0: fr_width, :] = frame[0: fr_height, 0: fr_width, :] 24 | cv2.imshow('Secret Capture', img_final) 25 | 26 | # cv2.imshow('webcam', frame) 27 | 28 | captured_video.write(img_final) 29 | if cv2.waitKey(10) == ord('q'): 30 | break --------------------------------------------------------------------------------