-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
35 lines (28 loc) · 1022 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
import cv2
import threading
from api import object_counting_api
class VideoCamera(object):
def __init__(self):
# Open a camera
self.cap = cv2.VideoCapture(input_video)
def __del__(self):
self.cap.release()
def get_frame(self):
ret, frame = self.cap.read()
if ret:
ret, jpeg = cv2.imencode('.jpg', frame)
# Record video
# if self.is_record:
# if self.out == None:
# fourcc = cv2.VideoWriter_fourcc(*'MJPG')
# self.out = cv2.VideoWriter('./static/video.avi',fourcc, 20.0, (640,480))
# ret, frame = self.cap.read()
# if ret:
# self.out.write(frame)
# else:
# if self.out != None:
# self.out.release()
# self.out = None
return jpeg.tobytes()
else:
return None