Fix unable to set camera width/height to non-default (#1225)
This commit is contained in:
@@ -225,16 +225,19 @@ class OpenCVCamera(Camera):
|
|||||||
def _validate_width_and_height(self) -> None:
|
def _validate_width_and_height(self) -> None:
|
||||||
"""Validates and sets the camera's frame capture width and height."""
|
"""Validates and sets the camera's frame capture width and height."""
|
||||||
|
|
||||||
success = self.videocapture.set(cv2.CAP_PROP_FRAME_WIDTH, float(self.capture_width))
|
width_success = self.videocapture.set(cv2.CAP_PROP_FRAME_WIDTH, float(self.capture_width))
|
||||||
actual_width = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_WIDTH)))
|
height_success = self.videocapture.set(cv2.CAP_PROP_FRAME_HEIGHT, float(self.capture_height))
|
||||||
if not success or self.capture_width != actual_width:
|
|
||||||
raise RuntimeError(f"{self} failed to set capture_width={self.capture_width} ({actual_width=}).")
|
|
||||||
|
|
||||||
success = self.videocapture.set(cv2.CAP_PROP_FRAME_HEIGHT, float(self.capture_height))
|
actual_width = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_WIDTH)))
|
||||||
actual_height = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
if not width_success or self.capture_width != actual_width:
|
||||||
if not success or self.capture_height != actual_height:
|
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"{self} failed to set capture_height={self.capture_height} ({actual_height})."
|
f"{self} failed to set capture_width={self.capture_width} ({actual_width=}, {width_success=})."
|
||||||
|
)
|
||||||
|
|
||||||
|
actual_height = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||||||
|
if not height_success or self.capture_height != actual_height:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"{self} failed to set capture_height={self.capture_height} ({actual_height=}, {height_success=})."
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user