|
|
|
@@ -29,6 +29,14 @@ from lerobot.common.cameras.opencv import OpenCVCamera, OpenCVCameraConfig
|
|
|
|
|
from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError
|
|
|
|
|
|
|
|
|
|
# NOTE(Steven): Consider improving the assert coverage
|
|
|
|
|
TEST_ARTIFACTS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "artifacts", "cameras")
|
|
|
|
|
DEFAULT_PNG_FILE_PATH = os.path.join(TEST_ARTIFACTS_DIR, "fakecam_sd_160x120.png")
|
|
|
|
|
TEST_IMAGE_PATHS = [
|
|
|
|
|
os.path.join(TEST_ARTIFACTS_DIR, "fakecam_sd_160x120.png"),
|
|
|
|
|
os.path.join(TEST_ARTIFACTS_DIR, "fakecam_hd_320x180.png"),
|
|
|
|
|
os.path.join(TEST_ARTIFACTS_DIR, "fakecam_fullhd_480x270.png"),
|
|
|
|
|
os.path.join(TEST_ARTIFACTS_DIR, "fakecam_square_128x128.png"),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_class_implementation():
|
|
|
|
@@ -38,7 +46,7 @@ def test_base_class_implementation():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_connect():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
|
|
|
|
|
camera.connect(do_warmup_read=False)
|
|
|
|
@@ -47,7 +55,7 @@ def test_connect():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_connect_already_connected():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
camera.connect(do_warmup_read=False)
|
|
|
|
|
|
|
|
|
@@ -65,7 +73,7 @@ def test_connect_invalid_camera_path():
|
|
|
|
|
|
|
|
|
|
def test_invalid_width_connect():
|
|
|
|
|
config = OpenCVCameraConfig(
|
|
|
|
|
index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png",
|
|
|
|
|
index_or_path=DEFAULT_PNG_FILE_PATH,
|
|
|
|
|
width=99999, # Invalid width to trigger error
|
|
|
|
|
height=480,
|
|
|
|
|
)
|
|
|
|
@@ -75,15 +83,7 @@ def test_invalid_width_connect():
|
|
|
|
|
camera.connect(do_warmup_read=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"index_or_path",
|
|
|
|
|
[
|
|
|
|
|
"tests/artifacts/cameras/fakecam_sd_640x480.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_hd_1280x720.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_fullhd_1920x1080.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_square_512x512.png",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.parametrize("index_or_path", TEST_IMAGE_PATHS)
|
|
|
|
|
def test_read(index_or_path):
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=index_or_path)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
@@ -95,7 +95,7 @@ def test_read(index_or_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_read_before_connect():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(DeviceNotConnectedError):
|
|
|
|
@@ -103,7 +103,7 @@ def test_read_before_connect():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_disconnect():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
camera.connect(do_warmup_read=False)
|
|
|
|
|
|
|
|
|
@@ -113,22 +113,14 @@ def test_disconnect():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_disconnect_before_connect():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(DeviceNotConnectedError):
|
|
|
|
|
_ = camera.disconnect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"index_or_path",
|
|
|
|
|
[
|
|
|
|
|
"tests/artifacts/cameras/fakecam_sd_640x480.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_hd_1280x720.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_fullhd_1920x1080.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_square_512x512.png",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.parametrize("index_or_path", TEST_IMAGE_PATHS)
|
|
|
|
|
def test_async_read(index_or_path):
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=index_or_path)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
@@ -143,7 +135,7 @@ def test_async_read(index_or_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_async_read_timeout():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
camera.connect(do_warmup_read=False)
|
|
|
|
|
|
|
|
|
@@ -154,22 +146,14 @@ def test_async_read_timeout():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_async_read_before_connect():
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path="tests/artifacts/cameras/fakecam_sd_640x480.png")
|
|
|
|
|
config = OpenCVCameraConfig(index_or_path=DEFAULT_PNG_FILE_PATH)
|
|
|
|
|
camera = OpenCVCamera(config)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(DeviceNotConnectedError):
|
|
|
|
|
_ = camera.async_read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"index_or_path",
|
|
|
|
|
[
|
|
|
|
|
"tests/artifacts/cameras/fakecam_sd_640x480.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_hd_1280x720.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_fullhd_1920x1080.png",
|
|
|
|
|
"tests/artifacts/cameras/fakecam_square_512x512.png",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.parametrize("index_or_path", TEST_IMAGE_PATHS)
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"rotation",
|
|
|
|
|
[
|
|
|
|
|