10
10
from enum import Enum
11
11
import serial .tools .list_ports
12
12
from lang_manager import LocaleStringManager as lang
13
-
14
13
from colorama import Fore
15
14
from config import BabbleConfig , BabbleSettingsConfig
16
15
from utils .misc_utils import get_camera_index_by_name , list_camera_names , is_nt
@@ -95,6 +94,7 @@ def run(self):
95
94
self .config .capture_source is not None
96
95
and self .config .capture_source != ""
97
96
):
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
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
145
146
):
146
147
if self .vft_camera is not None :
147
148
self .vft_camera .close ()
148
- self .device_is_vft = False ;
149
+ self .device_is_vft = False
149
150
150
151
print (self .error_message .format (self .config .capture_source ))
151
152
# This requires a wait, otherwise we can error and possible screw up the camera
152
153
# firmware. Fickle things.
153
154
if self .cancellation_event .wait (WAIT_TIME ):
154
155
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,9 +163,8 @@ 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 .current_capture_source
168
- )
166
+ self .cv2_camera = cv2 .VideoCapture ()
167
+ self .cv2_camera .open (self .current_capture_source )
169
168
170
169
if not self .settings .gui_cam_resolution_x == 0 :
171
170
self .cv2_camera .set (
@@ -181,7 +180,6 @@ def run(self):
181
180
self .cv2_camera .set (
182
181
cv2 .CAP_PROP_FPS , self .settings .gui_cam_framerate
183
182
)
184
-
185
183
should_push = False
186
184
else :
187
185
# We don't have a capture source to try yet, wait for one to show up in the GUI.
@@ -215,15 +213,14 @@ def get_camera_picture(self, should_push):
215
213
return
216
214
self .frame_number = self .frame_number + 1
217
215
elif self .cv2_camera is not None and self .cv2_camera .isOpened ():
218
- ret , image = self .cv2_camera .read ()
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.
219
217
if not ret :
220
218
self .cv2_camera .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
221
219
raise RuntimeError (lang ._instance .get_string ("error.frame" ))
222
220
self .frame_number = self .cv2_camera .get (cv2 .CAP_PROP_POS_FRAMES ) + 1
223
221
else :
224
222
# Switching from a Vive Facial Tracker to a CV2 camera
225
223
return
226
-
227
224
self .FRAME_SIZE = image .shape
228
225
# Calculate FPS
229
226
current_frame_time = time .time () # Should be using "time.perf_counter()", not worth ~3x cycles?
@@ -361,4 +358,4 @@ def push_image_to_queue(self, image, frame_number, fps):
361
358
f'{ Fore .YELLOW } [{ lang ._instance .get_string ("log.warn" )} ] { lang ._instance .get_string ("warn.backpressure1" )} { qsize } . { lang ._instance .get_string ("warn.backpressure2" )} { Fore .RESET } '
362
359
)
363
360
self .camera_output_outgoing .put ((self .clamp_max_res (image ), frame_number , fps ))
364
- self .capture_event .clear ()
361
+ self .capture_event .clear ()
0 commit comments