-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpseye.py
101 lines (82 loc) · 2.46 KB
/
pseye.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
DeepLabCut Toolbox (deeplabcut.org)
© A. & M. Mathis Labs
Licensed under GNU Lesser General Public License v3.0
"""
import cv2
from imutils import rotate_bound
import numpy as np
import pseyepy
from dlclivegui.camera import Camera, CameraError
class PSEyeCam(Camera):
@staticmethod
def arg_restrictions():
return {
"device": [i for i in range(pseyepy.cam_count())],
"resolution": [[320, 240], [640, 480]],
"fps": [30, 40, 50, 60, 75, 100, 125],
"colour": [True, False],
"auto_whitebalance": [True, False],
}
def __init__(
self,
device=0,
resolution=[320, 240],
exposure=100,
gain=20,
rotate=0,
crop=None,
fps=60,
colour=False,
auto_whitebalance=False,
red_balance=125,
blue_balance=125,
green_balance=125,
display=True,
display_resize=1.0,
):
super().__init__(
device,
resolution=resolution,
exposure=exposure,
gain=gain,
rotate=rotate,
crop=crop,
fps=fps,
use_tk_display=display,
display_resize=display_resize,
)
self.colour = colour
self.auto_whitebalance = auto_whitebalance
self.red_balance = red_balance
self.blue_balance = blue_balance
self.green_balance = green_balance
def set_capture_device(self):
if self.im_size[0] == 320:
res = pseyepy.Camera.RES_SMALL
elif self.im_size[0] == 640:
res = pseyepy.Camera.RES_LARGE
else:
raise CameraError(f"pseye resolution {self.im_size} not supported")
self.cap = pseyepy.Camera(
self.id,
fps=self.fps,
resolution=res,
exposure=self.exposure,
gain=self.gain,
colour=self.colour,
auto_whitebalance=self.auto_whitebalance,
red_balance=self.red_balance,
blue_balance=self.blue_balance,
green_balance=self.green_balance,
)
return True
def get_image_on_time(self):
frame, _ = self.cap.read()
if self.rotate != 0:
frame = rotate_bound(frame, self.rotate)
if self.crop:
frame = frame[self.crop[2] : self.crop[3], self.crop[0] : self.crop[1]]
return frame
def close_capture_device(self):
self.cap.end()