refactor: enhance mock camera classes and update camera detection logic

This commit is contained in:
2025-10-09 18:47:17 +02:00
parent ca25b06f99
commit c815762f72
3 changed files with 119 additions and 17 deletions

View File

@@ -28,24 +28,18 @@ class OpenCvCamera(BaseCamera):
def detect():
camera_list = enumerate_cameras(cv2.CAP_ANY)
result = {}
seen_ports = set()
for camera in camera_list:
# unikamy duplikatów tego samego /dev/videoX albo tej samej ścieżki na Windows/macOS
if camera.path in seen_ports:
continue
cap = cv2.VideoCapture(camera.index, camera.backend) # próbujemy otworzyć
ret, frame = cap.read()
cap = cv2.VideoCapture(camera.index, camera.backend)
# ret, frame = cap.read()
cap.release()
if ret and frame is not None and frame.size > 0:
result[camera.index] = {
"name": camera.name,
"port": camera.path,
"backend": camera.backend,
}
seen_ports.add(camera.path)
# if ret and frame is not None and frame.size > 0:
result[camera.index] = {
"name": camera.name,
"port": camera.path,
"backend": camera.backend,
}
return result