Added continous hand tracking
This commit is contained in:
@@ -4,7 +4,7 @@ import os
|
||||
from Tbd.helper import CameraObject
|
||||
from UI.UILogger import UILogger
|
||||
|
||||
from PySide6.QtCore import Qt, QTimer
|
||||
from PySide6.QtCore import Qt, QTimer, QThread, Signal
|
||||
from PySide6.QtGui import QImage, QPixmap
|
||||
from PySide6.QtWidgets import QLineEdit
|
||||
from PySide6.QtGui import QIntValidator
|
||||
@@ -12,6 +12,35 @@ from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QPushButton, QHBoxLa
|
||||
from typing import List
|
||||
|
||||
|
||||
class LoadCamerasWorker(QThread):
|
||||
"""
|
||||
Opens/verifies/closes each camera off the UI thread - camera.open() does
|
||||
MSMF format negotiation with retries+sleeps, which used to block the Qt
|
||||
event loop (window shows as "Not Responding") for the whole duration.
|
||||
"""
|
||||
cameraOpened = Signal(object)
|
||||
logMessage = Signal(str)
|
||||
|
||||
def __init__(self, indexToAdd: List[int]):
|
||||
super().__init__()
|
||||
self.indexToAdd = indexToAdd
|
||||
|
||||
def run(self):
|
||||
for index in self.indexToAdd:
|
||||
camera = CameraObject(capture=None, index=index)
|
||||
|
||||
if not camera.open():
|
||||
self.logMessage.emit(f"cam{index}: failed to open, skipping.")
|
||||
continue
|
||||
|
||||
ret, frame = camera.capture.read()
|
||||
if ret:
|
||||
self.logMessage.emit(f"cam{index}: verified, frame shape={frame.shape}")
|
||||
else:
|
||||
self.logMessage.emit(f"cam{index}: opened but failed to read a frame.")
|
||||
|
||||
camera.close()
|
||||
self.cameraOpened.emit(camera)
|
||||
|
||||
|
||||
class SetupPage(QWidget):
|
||||
@@ -91,31 +120,22 @@ class SetupPage(QWidget):
|
||||
self.logger.log("Path not found")
|
||||
|
||||
indexToAdd = [1, 2, 3, 4, 5, 6]
|
||||
|
||||
#indexToAdd = [0, 3]
|
||||
# Cameras are verified one at a time and left closed afterwards - this
|
||||
# hardware can't sustain many concurrent capture graphs (confirmed via
|
||||
# both CAP_DSHOW and a raw DirectShow graph), so callers open a camera
|
||||
# right before they need it (CameraSetupWidget.Start, calibration capture)
|
||||
# and close it right after, instead of keeping all 6 open simultaneously.
|
||||
for index in indexToAdd:
|
||||
camera = CameraObject(capture=None, index=index)
|
||||
self.loadBTN.setEnabled(False)
|
||||
self._loadWorker = LoadCamerasWorker(indexToAdd)
|
||||
self._loadWorker.logMessage.connect(self.logger.log)
|
||||
self._loadWorker.cameraOpened.connect(self._onCameraLoaded)
|
||||
self._loadWorker.finished.connect(lambda: self.loadBTN.setEnabled(True))
|
||||
self._loadWorker.start()
|
||||
|
||||
if not camera.open():
|
||||
self.logger.log(f"cam{index}: failed to open, skipping.")
|
||||
continue
|
||||
|
||||
ret, frame = camera.capture.read()
|
||||
if ret:
|
||||
self.logger.log(f"cam{index}: verified, frame shape={frame.shape}")
|
||||
else:
|
||||
self.logger.log(f"cam{index}: opened but failed to read a frame.")
|
||||
|
||||
camera.close()
|
||||
|
||||
self.cameraList.append(camera)
|
||||
self._cameraList_changed()
|
||||
|
||||
return
|
||||
def _onCameraLoaded(self, camera: CameraObject):
|
||||
self.cameraList.append(camera)
|
||||
self._cameraList_changed()
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user