0

First Pose

Second Pose

Two cameras are fixed to rod. Distance is constant between two cameras. These two cameras are not the identical, so they should not be considered as a stereo. I measure distance between two cameras center by using marker(solvePnP). The distance should be constant and equal for all pose but while I am moving the rod, calculated distance is changing. What could be causing the error?

while(camera1.isGrabbing() and camera2.isGrabbing()):
    found,rvec_1,tvec_1 = cv2.solvePnP(object_3d_points, camera1_object_2d_points, camera1_matrix, camera1_dist_coefs)
    rotM_1 = cv2.Rodrigues(rvec_1)[0]
    camera1_Position = -np.matrix(rotM_1).T * np.matrix(tvec_1)

    found,rvec_2,tvec_2 = cv2.solvePnP(object_3d_points, camera2_object_2d_points, camera2_matrix, camera2_dist_coefs)
    rotM_2 = cv2.Rodrigues(rvec_2)[0]
    camera2_Position = -np.matrix(rotM_2).T * np.matrix(tvec_2)

    p1 = np.array([camera1_Position[0], camera1_Position[1], camera1_Position[2]])
    p2 = np.array([camera2_Position[0], camera2_Position[1], camera2_Position[2]])
    squared_distance = np.sum((p1-p2)**2, axis=0)
    dis = np.sqrtsquared_distance 
    print("Distance:>",dis)  
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Mercol K
  • 9
  • 2

1 Answers1

1

In your case it might be the matter of camera calibration. As you assumed, calculated distance between cameras should be constant, but it would only happen in a perfect world, with a perfect camera model. With opencv you are using a simplified pinhole camera model, which has some limitations, so that you have to expect errors in your results. SolvePnp function is prone to calibration inaccuracies, so you should probably focus on this part to improve the results. Here you can find some tips for calibration process: https://dsp.stackexchange.com/questions/1567/how-do-i-get-the-most-accurate-camera-calibration Nevertheless, you will never get zero-error (constant) distance.

You should also provide us with some numerical data of your station, like camera resolution, lens focal length, geometry and estimated(physicly measured, expected value) and calculated distance, so we could tell if you may expect better results.

KatangaDev
  • 11
  • 1