perfanalytics / pose2sim

Markerless kinematics with any cameras — From 2D Pose estimation to 3D OpenSim motion
https://perfanalytics.github.io/pose2sim/
BSD 3-Clause "New" or "Revised" License
274 stars 50 forks source link

Prb in calibratioin #87

Closed ANaaim closed 7 months ago

ANaaim commented 7 months ago

Hello,

I think there is an error in calibration.py at line 691

Why in extrinsic method we have

 imgp, objp_not_used = findCorners(img_vid_files[0], extrinsics_corners_nb, objp=object_coords_3d, show=show_reprojection_error)

and not

 imgp, objp = findCorners(img_vid_files[0], extrinsics_corners_nb, objp=object_coords_3d, show=show_reprojection_error)

obj_not_used should be objp no ?


            # Find corners or label by hand
            if extrinsics_method == 'board':
                imgp, objp_not_used = findCorners(img_vid_files[0], extrinsics_corners_nb, objp=object_coords_3d, show=show_reprojection_error)
                if imgp == []:
                    logging.exception('No corners found. Set "show_detection_extrinsics" to true to click corners by hand, or change extrinsic_board_type to "scene"')
                    raise ValueError('No corners found. Set "show_detection_extrinsics" to true to click corners by hand, or change extrinsic_board_type to "scene"')

            elif extrinsics_method == 'scene':
                imgp, objp = imgp_objp_visualizer_clicker(img, imgp=[], objp=object_coords_3d, img_path=img_vid_files[0])
                if imgp == []:
                    logging.exception('No points clicked (or fewer than 6). Press \'C\' when the image is displayed, and then click on the image points corresponding to the \'object_coords_3d\' you measured and wrote down in the Config.toml file.')
                    raise ValueError('No points clicked (or fewer than 6). Press \'C\' when the image is displayed, and then click on the image points corresponding to the \'object_coords_3d\' you measured and wrote down in the Config.toml file.')
                if len(objp) < 10:
                    logging.info(f'Only {len(objp)} reference points for camera {cam}. Calibration of extrinsic parameters may not be accurate with fewer than 10 reference points, as spread out as possible.')

            elif extrinsics_method == 'keypoints':
                logging.info('Calibration based on keypoints is not available yet.')

            # Calculate extrinsics
            mtx, dist = np.array(K[i]), np.array(D[i])
            _, r, t = cv2.solvePnP(np.array(objp), imgp, mtx, dist)
            r, t = r.flatten(), t.flatten()
davidpagnon commented 7 months ago

Hi, I haven't tested it but it reasonably seems like you are right! Are you using a checkerboard to calibrate the extrinsic parameters? I do not generally recommend this as I feel like you would get suboptimal results, but since I have not tested it often, it may be a bug that I have missed. I supposed you have tried with objp instead and that it works better?

As usual, thank you for testing the code and spotting mistakes for me :)

ANaaim commented 7 months ago

Yep I tried and it worked so I will do a PR if needed.

davidpagnon commented 7 months ago

Sure, that would be great!

ANaaim commented 7 months ago

linked to #91

ANaaim commented 7 months ago

Can be closed as PR was merged.