mirror of
https://github.com/Project-Babble/ProjectBabble.git
synced 2026-11-29 05:12:46 -08:00
Tweaks for VFT path name issues
This commit is contained in:
1 parent
559fdbe1f8
commit
392e5ae24a
3 files changed
+22
-38
No files matched your search
+11
-19
@@ -97,22 +97,13 @@ class Camera:
|
||||
):
|
||||
isSerial = any(x in str(self.config.capture_source) for x in PORTS)
|
||||
|
||||
# Don't accept numerical values outside the list
|
||||
# Unless it's a serial port. Skip this check if it is
|
||||
try:
|
||||
if not isSerial:
|
||||
number = int(self.config.capture_source)
|
||||
if number > len(self.camera_list):
|
||||
return
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
if isSerial:
|
||||
if self.cv2_camera is not None:
|
||||
self.cv2_camera.release()
|
||||
self.cv2_camera = None
|
||||
if self.vft_camera is not None:
|
||||
self.vft_camera.close()
|
||||
self.device_is_vft = False;
|
||||
if (
|
||||
self.serial_connection is None
|
||||
or self.camera_status == CameraState.DISCONNECTED
|
||||
@@ -121,18 +112,20 @@ class Camera:
|
||||
port = self.config.capture_source
|
||||
self.current_capture_source = port
|
||||
self.start_serial_connection(port)
|
||||
elif ViveTracker.is_device_vive_tracker(self.camera_list[self.config.capture_source]):
|
||||
elif ViveTracker.is_device_vive_tracker(self.config.capture_source):
|
||||
if self.cv2_camera is not None:
|
||||
self.cv2_camera.release()
|
||||
self.cv2_camera = None
|
||||
|
||||
self.device_is_vft = True;
|
||||
|
||||
if self.vft_camera is None:
|
||||
print(self.error_message.format(self.config.capture_source))
|
||||
# capture_source is an index into a list of devices, so it should be treated as such
|
||||
if self.cancellation_event.wait(WAIT_TIME):
|
||||
return
|
||||
try:
|
||||
# Only create the camera once, reuse it
|
||||
self.vft_camera = FTCameraController(self.config.capture_source)
|
||||
self.vft_camera = FTCameraController(get_camera_index_by_name(self.config.capture_source))
|
||||
self.vft_camera.open()
|
||||
should_push = False
|
||||
except Exception:
|
||||
@@ -151,23 +144,22 @@ class Camera:
|
||||
self.cv2_camera is None
|
||||
or not self.cv2_camera.isOpened()
|
||||
or self.camera_status == CameraState.DISCONNECTED
|
||||
or self.config.capture_source != self.current_capture_source
|
||||
or get_camera_index_by_name(self.config.capture_source) != self.current_capture_source
|
||||
):
|
||||
if self.vft_camera is not None:
|
||||
self.vft_camera.close()
|
||||
self.device_is_vft = False;
|
||||
|
||||
print(self.error_message.format(self.config.capture_source))
|
||||
# This requires a wait, otherwise we can error and possible screw up the camera
|
||||
# firmware. Fickle things.
|
||||
if self.cancellation_event.wait(WAIT_TIME):
|
||||
return
|
||||
|
||||
|
||||
if self.config.capture_source not in self.camera_list:
|
||||
self.current_capture_source = self.config.capture_source
|
||||
else:
|
||||
self.current_capture_source = get_camera_index_by_name(
|
||||
self.config.capture_source
|
||||
)
|
||||
self.current_capture_source = get_camera_index_by_name(self.config.capture_source)
|
||||
|
||||
if self.config.use_ffmpeg:
|
||||
self.cv2_camera = cv2.VideoCapture(
|
||||
@@ -220,7 +212,7 @@ class Camera:
|
||||
try:
|
||||
image = None
|
||||
# Is the current camera a Vive Facial Tracker and have we opened a connection to it before?
|
||||
if self.vft_camera is not None and ViveTracker.is_device_vive_tracker(self.camera_list[self.config.capture_source]):
|
||||
if self.vft_camera is not None and self.device_is_vft:
|
||||
image = self.vft_camera.get_image()
|
||||
if image is None:
|
||||
return
|
||||
|
||||
@@ -323,10 +323,7 @@ class CameraWidget:
|
||||
if any(x in str(value) for x in ports):
|
||||
self.config.capture_source = value
|
||||
else:
|
||||
cam = get_camera_index_by_name(value) # Set capture_source to the UVC index. Otherwise treat value like an ipcam if we return none
|
||||
if cam != None:
|
||||
self.config.capture_source = cam
|
||||
elif is_valid_int_input(value):
|
||||
if is_valid_int_input(value):
|
||||
self.config.capture_source = int(value)
|
||||
else:
|
||||
self.config.capture_source = value
|
||||
|
||||
@@ -71,20 +71,16 @@ def is_uvc_device(device):
|
||||
def list_linux_uvc_devices():
|
||||
"""List UVC video devices on Linux (excluding metadata devices)"""
|
||||
try:
|
||||
result = subprocess.run(["v4l2-ctl", "--list-devices"], stdout=subprocess.PIPE)
|
||||
output = result.stdout.decode("utf-8")
|
||||
|
||||
lines = output.splitlines()
|
||||
# v4l2-ctl --list-devices breaks if video devices are non-sequential.
|
||||
# So this might be better?
|
||||
result = glob.glob("/dev/video*");
|
||||
devices = []
|
||||
current_device = None
|
||||
for line in lines:
|
||||
if not line.startswith("\t"):
|
||||
current_device = line.strip()
|
||||
else:
|
||||
if "/dev/video" in line and is_uvc_device(line.strip()):
|
||||
devices.append(
|
||||
line.strip()
|
||||
) # We return the path like '/dev/video0'
|
||||
for line in result:
|
||||
if is_uvc_device(line):
|
||||
devices.append(
|
||||
line
|
||||
) # We return the path like '/dev/video0'
|
||||
|
||||
return devices
|
||||
|
||||
@@ -147,10 +143,9 @@ def get_camera_index_by_name(name):
|
||||
cam_list = list_camera_names()
|
||||
|
||||
# On Linux, we use device paths like '/dev/video0' and match directly
|
||||
# OpenCV expects the actual /dev/video#, not the offset into the device list
|
||||
if os_type == "Linux":
|
||||
for i, device_path in enumerate(cam_list):
|
||||
if device_path == name:
|
||||
return i
|
||||
return int(str.replace(name,"/dev/video",""));
|
||||
|
||||
# On Windows, match by camera name
|
||||
elif is_nt:
|
||||
|
||||
Reference in new issue
Block a user