refactor(cameras): remove tmp video capture in connect
This commit is contained in:
parent
cdcb27f908
commit
e42485c837
|
@ -308,17 +308,11 @@ class OpenCVCamera(Camera):
|
|||
)
|
||||
|
||||
camera_idx = f"/dev/video{self.camera_index}" if platform.system() == "Linux" else self.camera_index
|
||||
# First create a temporary camera trying to access `camera_index`,
|
||||
# and verify it is a valid camera by calling `isOpened`.
|
||||
tmp_camera = cv2_sdk.VideoCapture(camera_idx, backend)
|
||||
is_camera_open = tmp_camera.isOpened()
|
||||
# Release camera to make it accessible for `find_camera_indices`
|
||||
tmp_camera.release()
|
||||
del tmp_camera
|
||||
|
||||
# If the camera doesn't work, display the camera indices corresponding to
|
||||
# valid cameras.
|
||||
if not is_camera_open:
|
||||
self.camera = cv2_sdk.VideoCapture(camera_idx, backend)
|
||||
|
||||
if not self.camera.isOpened():
|
||||
self.camera.release() # Release the failed attempt
|
||||
# Verify that the provided `camera_index` is valid before printing the traceback
|
||||
cameras_info = find_cameras(cv2_sdk=cv2_sdk)
|
||||
available_cam_ids = [cam["index"] for cam in cameras_info]
|
||||
|
@ -330,11 +324,6 @@ class OpenCVCamera(Camera):
|
|||
|
||||
raise OSError(f"Can't access OpenCVCamera({camera_idx}).")
|
||||
|
||||
# Secondly, create the camera that will be used downstream.
|
||||
# Note: For some unknown reason, calling `isOpened` blocks the camera which then
|
||||
# needs to be re-created.
|
||||
self.camera = cv2_sdk.VideoCapture(camera_idx, backend)
|
||||
|
||||
if self.fps is not None:
|
||||
self.camera.set(cv2_sdk.CAP_PROP_FPS, self.fps)
|
||||
if self.capture_width is not None:
|
||||
|
|
Loading…
Reference in New Issue