diff --git a/sksurgeryimage/calibration/dotty_grid_point_detector.py b/sksurgeryimage/calibration/dotty_grid_point_detector.py index b009753..06decfe 100644 --- a/sksurgeryimage/calibration/dotty_grid_point_detector.py +++ b/sksurgeryimage/calibration/dotty_grid_point_detector.py @@ -356,6 +356,16 @@ def _internal_get_points(self, image): img_points[counter][0] = distorted_x img_points[counter][1] = distorted_y + unique_ids, unique_idxs, counts = \ + np.unique(indexes, return_index=True, return_counts=True) + + unique_ids = unique_ids[counts==1] + unique_idxs = unique_idxs[counts==1] + + indexes = indexes[unique_idxs] + object_points = object_points[unique_idxs] + img_points = img_points[unique_idxs] + return indexes, object_points, img_points # If we didn't find all points, of the fit was poor, diff --git a/tests/calibration/test_dotty_grid_detector_metal.py b/tests/calibration/test_dotty_grid_detector_metal.py index e355612..3041c79 100644 --- a/tests/calibration/test_dotty_grid_detector_metal.py +++ b/tests/calibration/test_dotty_grid_detector_metal.py @@ -27,8 +27,7 @@ def test_metal_1a(setup_dotty_metal_model_OR): number_of_points = tdgu.__check_real_OR_image(model_points, img_path, 'tests/data/calib-ucl-circles/10_54_44/viking.calib.left.intrinsics.txt', - 'tests/data/calib-ucl-circles/10_54_44/viking.calib.left.distortion.txt', - True + 'tests/data/calib-ucl-circles/10_54_44/viking.calib.left.distortion.txt' ) assert (326 == number_of_points) diff --git a/tests/calibration/test_dotty_grid_point_detector.py b/tests/calibration/test_dotty_grid_point_detector.py index 69d8e43..2396294 100644 --- a/tests/calibration/test_dotty_grid_point_detector.py +++ b/tests/calibration/test_dotty_grid_point_detector.py @@ -117,7 +117,7 @@ def test_dotty_uncalibrated_5(setup_dotty_calibration_model): 'tests/data/calib-ucl-circles/calib.left.intrinsics.txt', 'tests/data/calib-ucl-circles/calib.left.distortion.txt', ) - assert(357 == number_of_points) + assert(355 == number_of_points) def test_dotty_uncalibrated_6(setup_dotty_calibration_model): @@ -127,7 +127,7 @@ def test_dotty_uncalibrated_6(setup_dotty_calibration_model): 'tests/data/calib-ucl-circles/calib.right.intrinsics.txt', 'tests/data/calib-ucl-circles/calib.right.distortion.txt', ) - assert(356 == number_of_points) + assert(354 == number_of_points) def test_dotty_uncalibrated_7(setup_dotty_calibration_model): @@ -555,3 +555,14 @@ def test_metal_6(setup_dotty_metal_model): ) assert (224 == number_of_points) +def test_all_unique_points_detected(setup_dotty_metal_model_OR): + # Test an image on which the dot detector was previously detecting multiple instances of the same dot. + model_points = setup_dotty_metal_model_OR + + number_of_points = tdgu.__check_real_OR_image(model_points, + 'tests/data/calib-ucl-circles/detecting_same_point_twice_dots.png', + 'tests/data/calib-ucl-circles/10_54_44/viking.calib.left.intrinsics.txt', + 'tests/data/calib-ucl-circles/10_54_44/viking.calib.right.distortion.txt' + ) + + assert(number_of_points) == 366 diff --git a/tests/calibration/test_dotty_grid_utils.py b/tests/calibration/test_dotty_grid_utils.py index 7febf4a..4df7d6d 100644 --- a/tests/calibration/test_dotty_grid_utils.py +++ b/tests/calibration/test_dotty_grid_utils.py @@ -64,7 +64,6 @@ def __check_real_OR_image(model_points, image_file_name, intrinsics_file_name, distortion_file_name, - is_metal=False ): logging.basicConfig(level=logging.DEBUG) image = cv2.imread(image_file_name) @@ -73,9 +72,7 @@ def __check_real_OR_image(model_points, size = (2600, 1900) fiducials = [133, 141, 308, 316] - if is_metal: - fiducials = [133, 141, 308, 316] - size = (2600, 1900) + detector = DottyGridPointDetector(model_points, fiducials, diff --git a/tests/data/calib-ucl-circles/detecting_same_point_twice_dots.png b/tests/data/calib-ucl-circles/detecting_same_point_twice_dots.png new file mode 100644 index 0000000..87f54b3 Binary files /dev/null and b/tests/data/calib-ucl-circles/detecting_same_point_twice_dots.png differ