-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera1.py
38 lines (21 loc) · 825 Bytes
/
camera1.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
38
from time import time
from flask import Flask
import cv2
class Camera(object):
# """An emulated camera implementation that streams a repeated sequence of
# files 1.jpg, 2.jpg and 3.jpg at a rate of one frame per second."""
def __init__(self):
# self.video = cv2.VideoCapture('video.mp4') for streaming any video file over the webpage
self.camera = cv2.VideoCapture(0)
def get_frame(self):
# self.frames = [open(f + '.jpg', 'rb').read() for f in ['1', '2', '3']]
while True:
# grab the current frame
(grabbed, frame) = self.camera.read()
#key = cv2.waitKey(1) & 0xFF
#if key==ord("q"):
# break
#else:
return cv2.imencode('.jpg',frame)[1].tobytes()
#camera.release()
#return self.frames[int(time()) % 3]