[Python] Finding rotation vectors and translation vectors given 3D points, 2D points, camera...

Discussão em 'Python' iniciado por Stack, Julho 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have 16 3D points, 16 2D points, a camera matrix, and distortion coefficients. Using that information, I'm trying to compute the new rotation vectors and translation vectors. Here is the code being used.

    success, rvec, tvec = cv2.solvePnP(points_3d, points_2d, camera_mat, dist_coeffs, cv2.SOLVEPNP_SQPNP)


    However, when I calculate the reprojection error given points_3d and points_2d using this method:

    def get_reproj_error(self, obj_points, actual_img_points):
    """Measures how accurate the calibration parameters are based of the arguments passed to this method"""
    reproj_error = 0
    for i, (rvec, tvec) in enumerate(zip(self._rvecs, self._tvecs)):
    imgpoints2, _ = cv2.projectPoints(obj_points, rvec, tvec, self._camera_matrix, self._dist_coeffs)
    imgpoints2 = np.reshape(imgpoints2, (len(imgpoints2), 2))
    error = np.linalg.norm(actual_img_points - imgpoints2) / len(imgpoints2)
    reproj_error += error

    reproj_error /= len(obj_points)
    return reproj_error


    Note: acutal_img_points has a shape of (11, 16, 2), due to there being 11 images and 16 image points for each image. It contains the image points used for the solvePnP() function, and obj_points is the same as points_3d from the solvePnP() function

    I get a reprojection error of around 4.6. I'm not sure if that's good or bad, but when I see the results when plotting, the points computed from the computed rotation vectors and translation vectors do not match the original 2D points at all.

    Is there a better way of computing the rotation vectors and translation vectors given the arguments mentioned above? If you need anything more to help me solve this, please let me know.

    Continue reading...

Compartilhe esta Página