カメラ入力解像度のデフォルトをフルHDに変更
動画圧縮機能の追加
This commit is contained in:
1 parent
ca10876101
commit
6d6b6a0ede
4 files changed
+27
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
"""OpenCV camera and video input abstraction."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
@@ -8,6 +9,8 @@ import numpy as np
|
||||
from .config_loader import InputSettings
|
||||
from .exceptions import CameraOpenError, FrameReadError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Camera:
|
||||
"""Read frames from a camera device or video file."""
|
||||
@@ -32,9 +35,24 @@ class Camera:
|
||||
self.release()
|
||||
raise CameraOpenError(f"Could not open {self.config.type} input: {source}")
|
||||
if self.config.type == "camera":
|
||||
# The pixel format must be set before the resolution: many webcams only offer
|
||||
# Full HD at a usable frame rate in MJPG, and fall back to a lower mode otherwise.
|
||||
if self.config.fourcc:
|
||||
self._capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*self.config.fourcc))
|
||||
self._capture.set(cv2.CAP_PROP_FRAME_WIDTH, self.config.width)
|
||||
self._capture.set(cv2.CAP_PROP_FRAME_HEIGHT, self.config.height)
|
||||
self._capture.set(cv2.CAP_PROP_FPS, self.config.fps)
|
||||
actual_w, actual_h = self.get_actual_width(), self.get_actual_height()
|
||||
logger.info(
|
||||
"Camera opened: requested %dx%d@%.1f fourcc=%s, actual %dx%d@%.1f",
|
||||
self.config.width, self.config.height, self.config.fps, self.config.fourcc or "default",
|
||||
actual_w, actual_h, self.get_actual_fps(),
|
||||
)
|
||||
if (actual_w, actual_h) != (self.config.width, self.config.height):
|
||||
logger.warning(
|
||||
"Camera resolution differs from the request: requested %dx%d, got %dx%d",
|
||||
self.config.width, self.config.height, actual_w, actual_h,
|
||||
)
|
||||
|
||||
def read(self) -> np.ndarray | None:
|
||||
if self._capture is None or not self._capture.isOpened():
|
||||
|
||||
Reference in new issue
Block a user