Get the relative position of the camera with extrinsic parameter but z-axis not facing to the camera

644 Views Asked by At

Object: I'm trying to get the relative position of the two camera's with calibration.
I'm using openCV to achieve this goal.

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

if ret == True:
    corners2 = cv2.cornerSubPix(cam1_img,corners,(11,11),(-1,-1), criteria)
    # Find the rotation and translation vectors.
    ret, rvecs, tvecs = cv2.solvePnP(objp, corners2, mtx, dist)

    # Project 3D points to image plane
    imgpts, jac = cv2.projectPoints(axisBoxes, rvecs, tvecs, mtx, dist)
    img = drawBoxes(cam1_img,corners2,imgpts)
    cv2.imwrite(f'result_img.jpg',img)

This is how I get the result of the rvecs, tvecs(rotation and translation vectors) I try to draw the result with this

R, _ = cv2.Rodrigues(rvecs)
offset = tvecs.T

R2, _ = cv2.Rodrigues(rvecs2)
offset2 = tvecs2.T

ax = pr.plot_basis(ax)
ax = pr.plot_basis(ax,R,offset)
ax = pr.plot_basis(ax,R2,offset2)

Then the result is as below.
enter image description here

Some how the front(blue line) is not facing to the origin basis
so I try to rotate the camera position with z-axis with 180 degree of angle.

R->[[ 0.287 -0.958  0.017]
 [ 0.365  0.125  0.923]
 [-0.886 -0.259  0.385]]
offset->[[ 3.182 12.088 62.537]]

My Rotation and offset vector looks like this.

  1. why the camera front(blue line) is not facing to the origin basis?
1

There are 1 best solutions below

0
On

You are using a square checker board pattern and since it is symmetric it has an ambiguity of 90 degree i.e. if you rotate the pattern by 90 degree it will appear exactly the same to the camera. So use a checker board pattern with even and odd number of rows and cols. You can have a look at this page to generate the required calibration pattern.

https://docs.opencv.org/4.x/da/d0d/tutorial_camera_calibration_pattern.html