-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmorse_camera.py
32 lines (26 loc) · 894 Bytes
/
morse_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
import cv2
import time
from morse_log import log
class Camera():
# Constructor...
def __init__(self):
w = 640 # Frame width...
h = 480 # Frame hight...
fps = 20.0 # Frames per second...
resolution = (w, h) # Frame size/resolution...
self.cap = cv2.VideoCapture(0) # Prepare the camera...
print("Camera warming up ...")
time.sleep(1)
# Prepare Capture
self.ret, self.frame = self.cap.read()
# Frame generation for Browser streaming
def get_frame(self):
success, image = self.cap.read()
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
def __del__(self):
self.cap.release()
cv2.destroyAllWindows()
print("Camera disabled and all output windows closed")
log("Camera disabled and all output windows closed")
return ()