1

I have used this code as a basis to detect my rectangular target in a scene. I use ORB and Flann Matcher. I have been able to draw the bounding box of the detected target in my scene successfully using the findHomography() and perspectiveTransform() functions.
The reference image (img_object in the above code) is a straight view of only the rectangular target. Now the target in my scene image may be tilted forwards or backwards. I want to find out the angle by which it has been tilted. I have read various posts and came to the conclusion that the homography returned by findHomography() can be decomposed to the rotation matrix and translation vector. I have used code from https:/gist.github.com/inspirit/740979 recommended by this link translated to C++. This is the Zhang SVD decomposition code got from the camera calibration module of OpenCV. I got the complete explanation of this decomposition code from O'Reilly's Learning OpenCV book.
My questions are :

  1. Am I correct in assuming that the decomposed rotation matrix I get will tell me the angle at which my target has been tilted?
  2. Secondly can I use the Homography obtained from findHomography() in as input to this decomposition module and expect the correct output? Or is there something I am missing?
  3. Is there any other way I can achieve the same?

Lastly, I am coding on a mobile platform so I am concerned about the performance too. I would be glad if you can point me in the right direction.

Thanks in advance for your time and replies.

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
user2958957
  • 61
  • 1
  • 8
  • why dont you create your own homography with known parameters (scale, translation and rotation and perspective parameters) and try the decomposition on such a matrix? you will see whether the correct parameters will be extracted. – Micka Feb 06 '14 at 10:03
  • the problem is not with the homography decomposition..am fairly sure that is working properly.what i want to know is in my case,can i give the homography returned by findHomography() after applying the ORB detection to this module?Will the rotation matrix give me the angle at which my target is rotated? – user2958957 Feb 10 '14 at 05:22

1 Answers1

0

Zhang's calibration procedure will produce a rotation matrix. That's representable as 3 (Euler) angles, not one. Or, equivalently (via Rodriguez's formula), as one unit vector and an angle of rotation about that vector - i.e. three numbers again.

Unless your camera and target are very carefully positioned with respect to each other, there is no reason to expect that there be just one non-zero angle of rotation.

Francesco Callari
  • 11,300
  • 2
  • 25
  • 40
  • Thanks for your answer.i can understand that there will be minor angle values on the other 2 axes too.Can you elaborate more on the Rodriguez's formula?The target moves towards or away from the camera for me.So this rotation matrix is capable of giving me that rotation too? – user2958957 Feb 10 '14 at 05:24
  • For Rodriguez's formula, see e.g. wikipedia: http://en.wikipedia.org/wiki/Axis_angle - OpenCV has code to do the conversions to/from rotation matrices. I don't understand your second question: rotation associated to a motion toward or away from the camera? That's a translation, not a rotation. – Francesco Callari Feb 10 '14 at 13:44
  • sorry i was not clear.By the forward / backward tilt or the towards / away from camera, i meant that my target rotates about the x axis in the opencv axes system as given in [link](http://stackoverflow.com/questions/9081900/reference-coordinate-system-changes-between-opencv-opengl-and-android-sensor) so that means i will get a rotation in that axis. – user2958957 Feb 11 '14 at 09:08
  • Yes, in that case the axis-angle representation is a vector parallel to the x axis, with an angle representing the rotation about it, positive when it is counterclockwise w.r.t. the axis (as seen "with your eyes on the arrow tip and your feet on the feather"). However, in practice the axis will not be exactly parallel to the camera x axis, unless you very carefully manufactured the setup to be so. – Francesco Callari Feb 11 '14 at 13:40