def test_process_eager_frame_without_calibrations(marker_type: MarkerType) -> None:
    marker_camera = MarkerCamera(
        MAX_ALL_ALLOWED_ID, marker_size=200, marker_type=marker_type
    )
    marker_camera.calibration_params = None
    with pytest.raises(MissingCalibrationsError):
        list(marker_camera.process_frame_eager())
Beispiel #2
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
Beispiel #3
0
class EagerMarkerTestCase(MarkerTestCase):
    def setUp(self) -> None:
        self.marker_camera = MarkerCamera(
            self.MARKER_ID,
            marker_size=self.MARKER_SIZE,
            marker_type=MarkerType.ARUCO_6X6,
        )
        self.markers = list(self.marker_camera.process_frame_eager())
        self.marker = self.markers[0]

    @patch("cv2.aruco.estimatePoseSingleMarkers")
    def test_doesnt_calculate_pose(self, pose_mock: Any) -> None:
        assert self.marker._tvec is not None
        assert self.marker._rvec is not None
        pose_mock.assert_not_called()

    def test_is_eager(self) -> None:
        self.assertIsInstance(self.marker, EagerMarker)
Beispiel #4
0
class EagerMarkerTestCase(MarkerTestCase):
    def setUp(self):
        self.marker_camera = MarkerCamera(
            self.MARKER_ID,
            marker_dict=MarkerDict.DICT_6X6_50,
            marker_size=self.MARKER_SIZE,
        )
        self.markers = list(self.marker_camera.process_frame_eager())
        self.marker = self.markers[0]

    def test_is_eager(self):
        self.assertTrue(self.marker._is_eager())

    @patch("cv2.aruco.estimatePoseSingleMarkers")
    def test_doesnt_calculate_pose(self, pose_mock):
        assert self.marker._tvec is not None
        assert self.marker._rvec is not None
        pose_mock.assert_not_called()
Beispiel #5
0
def test_process_frame_eager(benchmark: Callable,
                             marker_camera: MarkerCamera) -> None:
    frame = marker_camera.capture_frame()
    benchmark(lambda: list(marker_camera.process_frame_eager(frame=frame)))