-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
37 lines (31 loc) · 867 Bytes
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cv2
import mediapipe as mp
import numpy as np
import time
import signal
import sys
from multiprocessing import Queue, Event
from pynput import keyboard as kb
import config
import json
def record(frame_queue: Queue, pause_event: Event):
def handler(signum, frame):
cap.release()
cv2.destroyAllWindows()
cv2.waitKey(1)
sys.exit()
signal.signal(signal.SIGINT, handler)
cap = cv2.VideoCapture(0)
n_frames = 0
print("Taking photo of the keyboard...")
time.sleep(2)
ret, frame = cap.read()
frame_queue.put(((cap.get(3), cap.get(4)), cv2.flip(frame, 1)))
print("Done!")
while True:
if not pause_event.is_set():
ret, frame = cap.read()
n_frames += 1
if not ret:
break
frame_queue.put((time.time(), cv2.flip(frame, 1)))