Hi, here’s the discussion:
Here’s how one computes the homography using SVD: apriltag/common/homography.c at master · AprilRobotics/apriltag (github.com)
(Note, the compute inverse method doesn’t really work. Use the SVD one).
You can probably ask ChatGPT to turn that code into numpy code in python.
Then use this to turn the homography into your pose: apriltag/common/homography.c at master · AprilRobotics/apriltag (github.com)
Finally then use the code above that I posted:
matd_t *pose = homography_to_pose(det->H, -fx, fy, cx, cy);
lnk_data.x_translation = MATD_EL(pose, 0, 3);
lnk_data.y_translation = MATD_EL(pose, 1, 3);
lnk_data.z_translation = MATD_EL(pose, 2, 3);
lnk_data.x_rotation = fast_atan2f(MATD_EL(pose, 2, 1), MATD_EL(pose, 2, 2));
lnk_data.y_rotation = fast_atan2f(-MATD_EL(pose, 2, 0), fast_sqrtf(sq(MATD_EL(pose, 2, 1)) + sq(MATD_EL(pose, 2, 2))));
lnk_data.z_rotation = fast_atan2f(MATD_EL(pose, 1, 0), MATD_EL(pose, 0, 0));
To get the x/y/z translation and rotation from the post matrix.
Note that the final numbers are in “whatever units”, so, you need to use a scale factor and offset to put them into the correct units. Luckily, the math is linear so one scale factor and offset is all that is needed.