0

I'm working on an AR program. I have done this steps:

  • Detect corners of a chess board with OpenCV
  • Use SolvePNP to find rvec and tvec
  • Apply Rodrigues on rvec to get R_mat
  • Use hconcat(R_mat, tvec, P); to concatenate R_mat and tvec to get Projection matrix
  • Apply decomposeProjectionMatrix on P to get new translation,T2, vector and eulerAngles

now my problem is in translation vectors just tvec[2] or translation over Z-axis is correct and in rotations again in Euler Angles (from decomposeProjectionMatrix) just eulerAngles[2] or rotation around z-axis is correct. I don't know hoa can I get Translation and Rotation related to X-axis and Y-axis correctly. I'm gonna use these in OpenGL to Augment a cube on the pattern. In my code, result of translation over X and Y axis is very larger than windows size; and rotaion around X and Y axis are very small and always near the zero (less than 0.0001)

Any Idea how to get correct meaningful T and R? P.S : I'm using an Identity matrix as camera matrix and zero matrix for dist coeff matrix.

green-dev
  • 103
  • 1
  • 1
  • 8
  • did you find http://answers.opencv.org/question/23089/opencv-opengl-proper-camera-pose-using-solvepnp/ during your research? They say that for example some axis might be inverted. – Micka Apr 20 '16 at 12:36
  • Yes I tried it but did not worked. it's not a negative or positive sign problem. the result I get is really irrelevant. my window size is 640X480 but I get a translation like 6000 ! and also rotations of Y and X is always zero... – green-dev Apr 20 '16 at 12:39
  • the translation is in 3D coordinates, isn't it? So it isn't directly related to the 2D image coordinates. Or am I missing something? In fact I'm not sure why you are using `decomposeProjectionMatrix`? What exactly do you want to achieve there? Imho you should: Compute and compose model-view matrix from solvePnP and use that for projection in openGL more or less directly?! – Micka Apr 20 '16 at 12:47
  • I tried to found out rvec and tvec more deeply. I reprojeced the pattern 3d points from SolvePNP with rvec and tvec and the result was really good! It seems that OpenCV uses a format that I can not Understand. In another attempt I manually set a tvec and rvec and projected a set of points . result was really weird with OpenCV. with a rvec=[1 0 0] and tvec=[ 0 0 0] the points were rotated about 89 degree and for rvec=[10 0 0] the've been rotated 89 degree again! just a little more, say 89.2 degree. what is the problem? – green-dev Apr 20 '16 at 12:51
  • Thancks. But can you be more specific? I'm gonna doing put a 3d cube on a chess board pattern (AR program with 3d model) like this: https://www.youtube.com/watch?v=bmDdfmrZqgA – green-dev Apr 20 '16 at 12:53
  • I didnt try it myself yet, but don't these two links try to do exactly the same? http://answers.opencv.org/question/23089/opencv-opengl-proper-camera-pose-using-solvepnp/ and http://stackoverflow.com/questions/18637494/camera-position-in-world-coordinate-from-cvsolvepnp – Micka Apr 20 '16 at 13:07
  • and in openCV doc there is a hint: An example of how to use solvePNP for planar augmented reality can be found at opencv_source_code/samples/python2/plane_ar.py I didn't have a look at the python code yet, but maybe that gives you more hints. – Micka Apr 20 '16 at 13:12

0 Answers0