Skip to content

Commit c4fcbcc

Browse files
authored
Enable dynamic exposure framerate for camera input and handle subprocess errors (#132)
1 parent 70e2683 commit c4fcbcc

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/om1_vlm/anonymizationSys/face_recog_stream/camera_reader.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import subprocess
45
from typing import Optional
56

67
import cv2
@@ -79,6 +80,31 @@ def open_capture(
7980
self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
8081
self.cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3)
8182

83+
try:
84+
subprocess.run(
85+
[
86+
"v4l2-ctl",
87+
"-d",
88+
device,
89+
"--set-ctrl=exposure_dynamic_framerate=1",
90+
],
91+
check=True,
92+
capture_output=True,
93+
text=True,
94+
)
95+
logging.info("Enabled exposure_dynamic_framerate on %s", device)
96+
except FileNotFoundError:
97+
logging.warning(
98+
"v4l2-ctl not found; install v4l-utils to enable "
99+
"exposure_dynamic_framerate"
100+
)
101+
except subprocess.CalledProcessError as e:
102+
logging.warning(
103+
"Failed to set exposure_dynamic_framerate on %s: %s",
104+
device,
105+
(e.stderr or e.stdout or "").strip(),
106+
)
107+
82108
if not self.cap or not self.cap.isOpened():
83109
raise RuntimeError(f"Failed to open camera device {device}")
84110

0 commit comments

Comments
 (0)