-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcamera.py
55 lines (44 loc) · 1.53 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import cv2
import threading
#from tf_pose_estimation.run_v3 import PoseEstimator
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
(self.grabbed, self.frame) = self.video.read()
self.stopped = False
#self.estimator = PoseEstimator()
#def _configure(self):
# self.estimator.configure()
def __del__(self):
self.video.release()
def start(self):
video_thread = threading.Thread(target=self.update)
video_thread.daemon = True
video_thread.start()
return self
def update(self):
print("read")
# keep looping infinitely until the thread is stopped
while True:
# if the thread indicator variable is set, stop the thread
if self.stopped:
return
# otherwise, read the next frame from the stream
(self.grabbed, self.frame) = self.video.read()
def read(self):
img = cv2.resize(self.frame, (576, 432))
img = cv2.flip( img, 1)
#img = estimator.aruco_tracking(img, estimator.mtx, estimator.dist, None)
return img
def stop(self):
# indicate that the thread should be stopped
self.stopped = True
'''
def get_frame(self, estimator):
success, image = self.video.read()
img = cv2.resize(image, (432, 384))
img = cv2.flip( img, 1)
img = estimator.predict(img)
ret, jpeg = cv2.imencode('.jpg', img)
return jpeg.tobytes()
'''