Fix camera capture reliability and rewrite tracking for available mediapipe/hardware
This commit is contained in:
+34
-1
@@ -2,6 +2,7 @@ import numpy as np
|
||||
import json
|
||||
import cv2
|
||||
import threading
|
||||
import time
|
||||
|
||||
from dataclasses import dataclass, field, asdict
|
||||
from typing import List, Optional, Tuple, Dict
|
||||
@@ -122,7 +123,39 @@ class CameraObject():
|
||||
#self.capture = cv2.VideoCapture(self.index, cv2.CAP_DSHOW)
|
||||
self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 2048.0)
|
||||
self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1536.0)
|
||||
|
||||
|
||||
def open(self, width: int = 1920, height: int = 1080, max_attempts: int = 5) -> bool:
|
||||
"""
|
||||
Open this camera on demand via MSMF. Only MSMF has been able to open all
|
||||
6 cameras on this rig at all (DSHOW hits a hard concurrent-instance limit
|
||||
around 2-3 devices on this hardware) - the tradeoff is MSMF cameras should
|
||||
not be kept open simultaneously in large numbers, so callers are expected
|
||||
to open() right before use and close() right after.
|
||||
"""
|
||||
if self.capture is not None:
|
||||
return True
|
||||
|
||||
for attempt in range(1, max_attempts + 1):
|
||||
capture = cv2.VideoCapture(self.index, cv2.CAP_MSMF)
|
||||
if capture.isOpened():
|
||||
capture.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
||||
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
||||
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
|
||||
self.capture = capture
|
||||
self.pxWidth = width
|
||||
self.pxHeight = height
|
||||
return True
|
||||
|
||||
capture.release()
|
||||
time.sleep(0.3 * attempt)
|
||||
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
if self.capture is not None:
|
||||
self.capture.release()
|
||||
self.capture = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Hand2D():
|
||||
|
||||
Reference in New Issue
Block a user