SciKit-Surgery / scikit-surgerycalibration

scikit-surgery-calibration provides algorithms designed for the calibration of surgical instruments
http://scikit-surgery.github.io/scikit-surgery/
Other
7 stars 1 forks source link

Image is undistorted/warped twice in detect_points_in_stereo_canonical_space if using dot detector #33

Open tdowrick opened 3 years ago

tdowrick commented 3 years ago

Iterative calibration calls detect_points_in_stereo_canonical_space(), which has this bit of code:

    for j, _ in enumerate(left_images):
        left_undistorted = cv2.undistort(
            left_images[j],
            left_camera_matrix,
            left_distortion_coeffs,
            left_camera_matrix
        )
        left_ids, left_obj_pts, left_img_pts = \
            left_point_detector.get_points(left_undistorted)

        if left_ids is not None \
                and left_ids.shape[0] >= minimum_points_per_frame \
                and right_ids is not None \
                and right_ids.shape[0] >= minimum_points_per_frame:

            left_common_points = match_points_by_id(left_ids,
                                                    left_img_pts,
                                                    reference_ids,
                                                    reference_image_points)
            left_homography, _ = \
                cv2.findHomography(left_common_points[0:, 0:2],
                                   left_common_points[0:, 2:4])
            left_warped = cv2.warpPerspective(left_undistorted,
                                              left_homography,
                                              reference_image_size,)

            left_ids, left_obj_pts, left_img_pts = \
                left_point_detector.get_points(left_warped)

The image is undistorted and warped. However, the get_points() function for dotty_grid_point_detector also undistorts and warps the image, so we end up with something like this, which messes up the rest of the processing:

image

Other point detectors (charuco etc) are unaffected as they don't undistort or warp the input image.

MattClarkson commented 3 years ago

Hold on ...