swatbotics / apriltag

Extensions and tweaks to APRIL Robotics Laboratory apriltag C software
https://april.eecs.umich.edu/software/apriltag.html
Other
169 stars 63 forks source link

how to find pose data from 3x3 homography matrix ? #14

Open maharshi114 opened 6 years ago

maharshi114 commented 6 years ago

first of all, thank you for writing an April Tag code in python. My camera calibration values are fx, fy, cx, cy = (1600.686892782011, 1598.3654331406094, 640, 480) Homography: [[ 2.92529352e-01 1.25090562e-01 5.47693202e+00] [-5.70424844e-01 4.61686531e-01 3.91037508e+00] [-4.98269301e-04 -4.78715645e-04 1.06762929e-02]] Center: [512.99941666 366.26712251] Corners: [[434.15356445 344.89123535] [529.65270996 270.08859253] [607.72912598 391.94927979] [496.40701294 462.09399414]] my homography matrix is accurate or not? because of the Homography matrix value change continuously. if this matrix is accurate then how to find Pose data from the 3x3 matrix?

mzucker commented 6 years ago

Hi, please read through issue #10 – I hope you will find some helpful information there. Let me know if you still have questions after reading it.

maharshi114 commented 6 years ago

Thank you for quick replay. somehow I manage to print pose matrix using camtest.py code Detection 1 of 1: Family: tag36h11 ID: 2 Hamming error: 0 Goodness: 0.0 Decision margin: 60.6518554688 Homography: [[-2.63700683e-02 -7.44275243e-01 1.26088787e+00] [ 6.93561147e-01 -7.26055716e-02 2.31620847e+00] [-3.56854414e-06 -1.90672384e-04 9.19281710e-03]] Center: [137.16011768 251.95850647] Corners: [[216.41851807 180.59469604] [210.96052551 328.61419678] [ 54.4800148 326.40319824] [ 60.2931366 172.11759949]] Pose: [[-0.12400197 -0.86445901 -0.48716951 -0.41820917] [ 0.95202461 0.0347795 -0.3040387 -0.18913546] [ 0.2797725 -0.50149876 0.81867353 1.33183182] [ 0. 0. 0. 1. ]] InitError: 11.5416902905 FinalError: 1.26238447089

as according to issue #10, the three values in the 4x4 pose matrix ( -0.41820917, -0.18913546, 1.33183182 ) show me the X, Y, and Z positions respectively.

but the value of Z is wrong in my case. The actual distance in my case is 0.9 meter. my tag size is 0.16 meter. after some observation, I figure out the in homography matrix the last value in matrix "9.19281710e-03" show me the accurate number in distance. Just multiplicate with 100 so final value (9.19281710e-03*100) = 0.919 meters with 1 to 2 mm accuracy.

so my question is, Why Pose matrix X, Y, and Z values show me wrong?
and what is homography matrix actually shows?

mzucker commented 6 years ago

This article I wrote describes what a homography matrix is: https://mzucker.github.io/2016/10/11/unprojecting-text-with-ellipses.html

The homography matrix will not in general correspond directly to physical measurements because it is a product of the camera intrinsics and the pose of the tag. In this case, I believe the fact that the bottom-right entry resembles the distance you measured is a coincidence.

What are the dimensions (resolution) of the images you are detecting tags in, and how did you obtain the calibration values listed above?

maharshi114 commented 6 years ago

calibration values are find via calibrate_camera.py code. Click the image of the chessboard via Logitech C270 camera and run calibrate_camera.py code. camera resolution = 640x480 pixels

mzucker commented 6 years ago

I don't trust the camera calibration values you provided for that camera. For the vast majority of desktop webcams you would expect to see focal lengths (fx, fy) on the order of image width and optical center (cx, cy) towards the center of the image. So for that camera, I would expect fx,fy to be in the 500-800 range, and the (cx, cy) point to be much closer to (320, 240) (that is 640/2, 480/2).

If you attach your chessboard calibration images here, I can try verifying your calibration values.

mzucker commented 6 years ago

I can't access that image on Google drive, but github accepts attachments to replies.

Note you must use multiple images to calibrate the camera. One is not sufficient! See for example https://github.com/swatbotics/apriltag/tree/master/images/mapping_feb_2014/calibration

maharshi114 commented 6 years ago

sorry for google drive link. here it is the image file.
im3

mzucker commented 6 years ago

Right, the problem as I mentioned above is that you are only using a single image file. See the example images I linked to in my last message to get an idea of the number and variety of images you should be using.

maharshi114 commented 6 years ago

Ok got it. Thank you.. sir

mzucker commented 6 years ago

I would recommend in the range of 10-20 images. You will not get good data with 2 or 3 images.

maharshi114 commented 6 years ago

Ok sir ..