slayer2309
slayer2309

Reputation: 113

Pose of camera from the pose of marker

I am currently working on a task to localize a vehicle using computer vision. I am using OpenCV with C++. I implemented ArUco marker to get the pose of the camera placed on the vehicle.

I used of the following function to estimate pose of the marker :

cv::aruco::estimatePoseSingleMarkers(markerCorners, markerLength, camMatrix, distCoeffs, rvecs,tvecs)

Later I found out that rvecs and tvecs are 1x1 arrays with 3 channels (openCVDataType=CV_8UC3).

Now, I get R(3x3) matrix from cv::Rodrigues function say it's Ri.

In order to get the pose of the camera w.r.t to marker, after a considerable amount of research I found out that the inverse transforms have to be taken. I got inverse if Ri.

Now to get inverse of translation vector it is just the multiplication of the above inverse with the translation vector (tvecs).

I am fairly new to c++ and my issues are:

  1. Is my approach correct in finding the pose of camera w.r.t marker?
  2. I am unable to change the tvecs into a mat object so that there is no multiplication error.

Upvotes: 3

Views: 3907

Answers (2)

Saikat halder
Saikat halder

Reputation: 618

Method of Rodriguez provides you a rotation matrix. Make a 4*4 transformation matrix with the help of rotation matrix and translation matrix. Inversing the transformation matrix will provide the pose of the camera with respect to marker. For the equations, just google, it's quite simple and available. You need to extract rotation and translation from the inverse transformation matrix.

Upvotes: 0

tenta4
tenta4

Reputation: 312

Method estimatePoseSingleMarkers uses cv::solvePnP method within. That's why for camera pose estimation you need to perform next:

Mat R;
cv::Rodrigues(rvec, R); // calculate your object pose R matrix

camR = R.t();  // calculate your camera R matrix

Mat camRvec;
Rodrigues(R, camRvec); // calculate your camera rvec

Mat camTvec= -camR * tvec; // calculate your camera translation vector

It seems that it fits your guesses

Upvotes: 1

Related Questions