mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-25 10:46:01 +00:00
(depth image processing): excluding depth frames from the RGB to BGR image processing (#4135)
* (depth image processing): excluding depth frames from the RGB to BGR image processing * test(update): updating tests to include RGB/BGR conversion checks
This commit is contained in:
@@ -26,7 +26,7 @@ import cv2
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from lerobot.cameras.configs import Cv2Rotation
|
||||
from lerobot.cameras.configs import ColorMode, Cv2Rotation
|
||||
from lerobot.cameras.opencv import OpenCVCamera, OpenCVCameraConfig
|
||||
from lerobot.utils.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError
|
||||
|
||||
@@ -132,6 +132,28 @@ def test_read(index_or_path):
|
||||
assert isinstance(img, np.ndarray)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("index_or_path", TEST_IMAGE_PATHS, ids=TEST_IMAGE_SIZES)
|
||||
def test_color_mode_conversion(index_or_path):
|
||||
"""RGB and BGR reads of the same frame must differ only by a channel-axis reversal."""
|
||||
rgb_config = OpenCVCameraConfig(index_or_path=index_or_path, color_mode=ColorMode.RGB, warmup_s=0)
|
||||
bgr_config = OpenCVCameraConfig(index_or_path=index_or_path, color_mode=ColorMode.BGR, warmup_s=0)
|
||||
with OpenCVCamera(rgb_config) as rgb_cam:
|
||||
rgb = rgb_cam.read()
|
||||
with OpenCVCamera(bgr_config) as bgr_cam:
|
||||
bgr = bgr_cam.read()
|
||||
|
||||
assert rgb.shape == bgr.shape
|
||||
np.testing.assert_array_equal(rgb, bgr[..., ::-1])
|
||||
|
||||
|
||||
def test_postprocess_invalid_color_mode():
|
||||
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
||||
camera = OpenCVCamera(config)
|
||||
camera.color_mode = "invalid"
|
||||
with pytest.raises(ValueError):
|
||||
camera._postprocess_image(np.zeros((120, 160, 3), dtype=np.uint8))
|
||||
|
||||
|
||||
def test_read_before_connect():
|
||||
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user