예제 #1
0
def is_valid_calibration(filename: Path) -> bool:
    if not filename.is_file():
        return False

    # First, Try and parse the file
    try:
        parse_calibration_file(filename)
    except (SystemError, ValueError):
        return False

    with tempfile.NamedTemporaryFile(suffix=".png") as temp_file:
        marker_camera = MarkerCamera(0,
                                     200,
                                     marker_type=MarkerType.APRILTAG_36H11)
        marker_camera.save_frame(Path(temp_file.name))

        image_camera = ImageFileCamera(
            Path(temp_file.name),
            marker_size=200,
            marker_type=MarkerType.APRILTAG_36H11,
            calibration_file=filename,
        )

        # Sanity check the image camera
        if image_camera.get_visible_markers() != [0]:
            return False

        # Then, confirm the detection works
        if len(list(marker_camera.process_frame_eager())) != 1:
            return False

    return True
예제 #2
0
def test_saved_image(temp_image_file, marker_id):
    marker_camera = MarkerCamera(marker_id,
                                 marker_dict=MarkerDict.DICT_6X6_50,
                                 marker_size=200)
    marker_camera.save_frame(temp_image_file)
    image_file_camera = ImageFileCamera(temp_image_file,
                                        marker_dict=MarkerDict.DICT_6X6_50)
    assert image_file_camera.get_visible_markers() == [marker_id]
예제 #3
0
def test_saved_image(
    marker_type: MarkerType, temp_image_file: Path, marker_id: int
) -> None:
    marker_camera = MarkerCamera(marker_id, marker_size=200, marker_type=marker_type)
    marker_camera.save_frame(temp_image_file)
    image_file_camera = ImageFileCamera(
        temp_image_file, marker_type=marker_type, marker_size=200
    )
    assert image_file_camera.get_visible_markers() == [marker_id]
예제 #4
0
def test_marker_size(
    marker_type: MarkerType, temp_image_file: Path, marker_id: int
) -> None:
    class TestCamera(ImageFileCamera):
        def get_marker_size(self, inner_marker_id: int) -> int:
            return inner_marker_id * 10

    marker_camera = MarkerCamera(marker_id, marker_size=200, marker_type=marker_type)
    marker_camera.save_frame(temp_image_file)
    image_file_camera = TestCamera(temp_image_file, marker_type=marker_type)
    marker = next(image_file_camera.process_frame())
    assert marker.size == marker_id * 10
    assert marker.id == marker_id
예제 #5
0
def test_no_markers(temp_image_file: Path) -> None:
    marker_camera = MarkerCamera(
        MAX_ALL_ALLOWED_ID,
        marker_size=100,
        marker_type=MarkerType.ARUCO_4X4,
    )
    marker_camera.save_frame(temp_image_file)

    image_file_camera = ImageFileCamera(
        temp_image_file, marker_type=MarkerType.ARUCO_5X5, marker_size=100
    )

    assert marker_camera.marker_type != image_file_camera.marker_type
    assert image_file_camera.get_visible_markers() == []
예제 #6
0
def test_saved_image_with_annotation(temp_image_file, marker_id):
    marker_camera = MarkerCamera(marker_id,
                                 marker_dict=MarkerDict.DICT_6X6_50,
                                 marker_size=200)
    output_file = temp_image_file
    marker_camera.save_frame(output_file, annotate=True)
예제 #7
0
def test_saved_image_with_annotation(
    temp_image_file: Path, marker_id: int, marker_type: MarkerType
) -> None:
    marker_camera = MarkerCamera(marker_id, marker_size=200, marker_type=marker_type)
    output_file = temp_image_file
    marker_camera.save_frame(output_file, annotate=True)