Karl Swanson
Karl Swanson

Reputation: 99

Aruco Marker World Coordinates

I've been working with Python's OpenCV library, using ArUco for object tracking.

The goal is to get the x/y/z coordinates at the center of the ArUco marker, and the angle in relation to the calibrated camera.

I am able to display axes on the aruco marker with the code I have so far, but cannot find how to get x/y/z coordinates from the rotation and translation vectors (if that's even the right way to go about it).

This is the line of code which defines the rotation/translation vectors:

rvec, tvec, _ = aruco.estimatePoseSingleMarkers(corners, markerLength, camera_matrix, dist_coeffs) # For a single marker

Any ideas on how to get angle/marker position in the camera world?

Thanks!

Upvotes: 4

Views: 11350

Answers (2)

Komms
Komms

Reputation: 103

As said by chungzuwalla, tvec represents the position of marker center in camera coordinate system and it doesn't change with the rotation of marker at a position. If you want to know about location of corners in camera coordinate system then one needs both rvec and tvec.

Here is a perfect explanation

Aruco markers with openCv, get the 3d corner coordinates?

Upvotes: 2

Karl Swanson
Karl Swanson

Reputation: 99

After some tribulation, I found that the x and y coordinates in aruco can be determined by the average of the corners:

x = (corners[i-1][0][0][0] + corners[i-1][0][1][0] + corners[i-1][0][2][0] + corners[i-1][0][3][0]) / 4
y = (corners[i-1][0][0][1] + corners[i-1][0][1][1] + corners[i-1][0][2][1] + corners[i-1][0][3][1]) / 4

And the angle relative to the camera can be determined by the Rodrigues of the rotation vector, the matrix must be filled prior

rotM = np.zeros(shape=(3,3))
cv2.Rodrigues(rvec[i-1], rotM, jacobian = 0)

Finally, yaw pitch and roll can be obtained by taking the RQ Decompose of the rotation matrix

ypr = cv2.RQDecomp3x3(rotM)

Upvotes: 5

Related Questions