js-aruco icon indicating copy to clipboard operation
js-aruco copied to clipboard

How to calculate pitch/yaw/roll of offset object?

Open boonkey opened this issue 6 years ago • 5 comments

Hi! I have a question regarding pose: I want to calculate the angles of a marker. This is fairly simple using the rotation matrix when the object is right in front of the camera, but I'm having a hard time doing it when the marker is offset to the center of the camera.

i.e. If the marker in question is directly in front of the camera, I can use the rotation matrix directly to calculate the marker's rotation relative to the camera position. My problem begins when I "pull" the marker along the X-axis (right/left), without rotating it. if the initial angle was 45 deg (when the marker was directly in front of the camera) and then I moved it left a few cm, but haven't rotated it, I need my angle measurement to return the same 45 deg as it did earlier.

How can I calculate it using the data js-aruco provides?

Thank you very much for your help, Dan

boonkey avatar Sep 04 '19 10:09 boonkey

I don't understand your question. You can use the translation matrix, not only the rotation one. Sorry, maybe I missing something from your question.

Have you take a look to the source code of the samples? The documentation in the main page of the project has relevant information too.

jcmellado avatar Sep 04 '19 11:09 jcmellado

I'll try and explain my issue better using pictures (which I took from your example page). both picture A and picture B has the same marker, at the same distance from the camera, facing the same direction. The same goes for pictures C and D.

The only difference between pictures A and C are the angle of the marker in respect to the camera. The same goes for pictures B and D.

I need to "project" the yaw angles in pictures B and D, so they show the same values as pictures A and C respectively.

i.e. I want the yaw angle in picture B to show 0 deg, while the yaw angle in picture D to show 45 deg.

Thanks for the help and fast response, Dan

dans problem

boonkey avatar Sep 04 '19 11:09 boonkey

  • Both pose estimations for the Picture B have an error of 5 and a yaw of 43. If you take a look to the blue squares in that picture, they are quite similar to the blue square of the Picture D. That is, you say that the marker is facing the camera, but the library is detecting that it is rotated.

  • The best pose estimation for the Picture D has an error of 0 and a yaw of 49. Ok, 49 is not 45, but it's quite similar.

That example use very little pixels to calculate the square. The video is recorded to a resolution of 320x240 and the marker is expected to have about 35 millimeters or so. Take a look to the debug-posit.html file. One pixel more or less and you should not have a perfect square. The library will think that it is rotated.

Maybe you should play with that parameters and increment the resolution.

jcmellado avatar Sep 04 '19 16:09 jcmellado

Unfortunately for me, neither increasing the resolution (up to 800x600) nor playing with parameters has changed calculations results for me.

the calculations for yaw remains very good when the marker is directly in front of the camera (like in pictures A and C) and 'random' when it's offset to it (as in pictures B and D).

Might it be that the calculation itself is wrong? I try to do it as you calculated in debug-posit.html: yaw = -Math.atan2(pose.bestRotation[0][2], pose.bestRotation[2][2]); should I maybe use another formula?

Thanks, Dan

boonkey avatar Sep 05 '19 13:09 boonkey

I don't think that the result is random. Blue square in pictures B and D are quite similar.

BTW, there are two implementations of the POSIT algorithm.

Have you tried to replace <script type="text/javascript" src="posit1.js"></script> with <script type="text/javascript" src="posit2.js"></script>?

jcmellado avatar Sep 05 '19 13:09 jcmellado