-
Notifications
You must be signed in to change notification settings - Fork 1
/
pg_rgb.py
52 lines (45 loc) · 1.4 KB
/
pg_rgb.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
import flycapture2 as fc2
import numpy as np
import cv2
from threading import Thread
class ImageThread(Thread):
def __init__(self, ctrl = None):
Thread.__init__(self)
self.ctrl = ctrl
def run(self):
self._run()
def _run(self, keep = True):
print fc2.get_library_version()
c = fc2.Context()
if (c.get_num_of_cameras() < 1): return
c.connect(*c.get_camera_from_index(0))
m, f = c.get_video_mode_and_frame_rate()
print(c.get_format7_configuration())
c.start_capture()
im = fc2.Image()
while True:
c.retrieve_buffer(im)
a = np.array(im)
a = cv2.resize(a, (640,480))
a = cv2.flip(a, 0)
if self.ctrl:
self.ctrl.lock.acquire()
self.ctrl.imageQueue.append(a)
self.ctrl.haveImage = True
self.ctrl.lock.release()
self.ctrl.event()
#cv2.imshow('rgb1', a)
#cv2.waitKey(1)
else:
cv2.imshow('rgb', a)
if not keep:
key = cv2.waitKey()
break
else:
key = cv2.waitKey(1)
if key & 0xFF == ord('q'): break
c.stop_capture()
c.disconnect()
if __name__ == "__main__":
im = ImageThread()
im._run(False)