10
10
from enum import Enum
11
11
import serial .tools .list_ports
12
12
from lang_manager import LocaleStringManager as lang
13
+
13
14
from colorama import Fore
14
15
from config import BabbleConfig , BabbleSettingsConfig
15
- from utils .misc_utils import get_camera_index_by_name , list_camera_names , is_nt
16
+ from utils .misc_utils import get_camera_index_by_name , list_camera_names
16
17
17
18
from vivefacialtracker .vivetracker import ViveTracker
18
19
from vivefacialtracker .camera_controller import FTCameraController
@@ -94,7 +95,6 @@ def run(self):
94
95
self .config .capture_source is not None
95
96
and self .config .capture_source != ""
96
97
):
97
- self .current_capture_source = self .config .capture_source
98
98
isSerial = any (x in str (self .config .capture_source ) for x in PORTS )
99
99
100
100
if isSerial :
@@ -103,7 +103,7 @@ def run(self):
103
103
self .cv2_camera = None
104
104
if self .vft_camera is not None :
105
105
self .vft_camera .close ()
106
- self .device_is_vft = False
106
+ self .device_is_vft = False ;
107
107
if (
108
108
self .serial_connection is None
109
109
or self .camera_status == CameraState .DISCONNECTED
@@ -116,7 +116,7 @@ def run(self):
116
116
if self .cv2_camera is not None :
117
117
self .cv2_camera .release ()
118
118
self .cv2_camera = None
119
- self .device_is_vft = True
119
+ self .device_is_vft = True ;
120
120
121
121
if self .vft_camera is None :
122
122
print (self .error_message .format (self .config .capture_source ))
@@ -141,18 +141,18 @@ def run(self):
141
141
self .cv2_camera is None
142
142
or not self .cv2_camera .isOpened ()
143
143
or self .camera_status == CameraState .DISCONNECTED
144
- #or get_camera_index_by_name(self.config.capture_source) != self.current_capture_source
145
- or self .config .capture_source != self .current_capture_source
144
+ or get_camera_index_by_name (self .config .capture_source ) != self .current_capture_source
146
145
):
147
146
if self .vft_camera is not None :
148
147
self .vft_camera .close ()
149
- self .device_is_vft = False
148
+ self .device_is_vft = False ;
150
149
151
150
print (self .error_message .format (self .config .capture_source ))
152
151
# This requires a wait, otherwise we can error and possible screw up the camera
153
152
# firmware. Fickle things.
154
153
if self .cancellation_event .wait (WAIT_TIME ):
155
154
return
155
+
156
156
if self .config .capture_source not in self .camera_list :
157
157
self .current_capture_source = self .config .capture_source
158
158
else :
@@ -163,8 +163,9 @@ def run(self):
163
163
self .current_capture_source , cv2 .CAP_FFMPEG
164
164
)
165
165
else :
166
- self .cv2_camera = cv2 .VideoCapture ()
167
- self .cv2_camera .open (self .current_capture_source )
166
+ self .cv2_camera = cv2 .VideoCapture (
167
+ self .current_capture_source
168
+ )
168
169
169
170
if not self .settings .gui_cam_resolution_x == 0 :
170
171
self .cv2_camera .set (
@@ -180,6 +181,7 @@ def run(self):
180
181
self .cv2_camera .set (
181
182
cv2 .CAP_PROP_FPS , self .settings .gui_cam_framerate
182
183
)
184
+
183
185
should_push = False
184
186
else :
185
187
# We don't have a capture source to try yet, wait for one to show up in the GUI.
@@ -213,14 +215,15 @@ def get_camera_picture(self, should_push):
213
215
return
214
216
self .frame_number = self .frame_number + 1
215
217
elif self .cv2_camera is not None and self .cv2_camera .isOpened ():
216
- ret , image = self .cv2_camera .read () # MJPEG Stream reconnects are currently limited by the hard coded 30 second timeout time on VideoCapture.read(). We can get around this by recompiling OpenCV or using a custom MJPEG stream imp.
218
+ ret , image = self .cv2_camera .read ()
217
219
if not ret :
218
220
self .cv2_camera .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
219
221
raise RuntimeError (lang ._instance .get_string ("error.frame" ))
220
222
self .frame_number = self .cv2_camera .get (cv2 .CAP_PROP_POS_FRAMES ) + 1
221
223
else :
222
224
# Switching from a Vive Facial Tracker to a CV2 camera
223
225
return
226
+
224
227
self .FRAME_SIZE = image .shape
225
228
# Calculate FPS
226
229
current_frame_time = time .time () # Should be using "time.perf_counter()", not worth ~3x cycles?
0 commit comments