How to use an OpenCV rotation and translation vector with OpenGL ES in Android?

后端 未结 2 1783
春和景丽
春和景丽 2020-12-08 01:19

I\'m am working on a basic augmented reality application on Android. What I did so far is detect a square with opencv and then using cvFindExtrinsicCameraParams2() I calcula

2条回答
  •  一生所求
    2020-12-08 02:10

    Okay after some more testing I finally managed to get it to work. While I don't understand it... it does 'work'. For anyone who will need to do this in the future here is my solution.

    float rv[3]; // the rotation vector
    float rotMat[9]; // rotation matrix
    float tv[3]; // translation vector.
    
    
    rv[1]=-1.0f * rv[1]; rv[2]=-1.0f * rv[2];
    //Convert the rotation vector into a matrix here.
    
    //Complete matrix ready to use for OpenGL
    float RTMat[] = {rotMat[0], rotMat[3], rotMat[6], 0.0f,
                     rotMat[1], rotMat[4], rotMat[7], 0.0f,
                     rotMat[2], rotMat[5], rotMat[8], 0.0f,
                     tv[0], -tv[1], -tv[2], 1.0f};
    

    As genpfault said in his comment everything needs to be transposed since OpenGL since OpenGL needs a column-major order. (Thanks for the comment, I saw that page earlier already.) Furthermore the y and z rotation angle as well as the y and z translation need to be multiplied by -1. This is what I find a bit weird. Why only those and not the x values too?

    This works as it should I guess. But corners the don't match exactly. I guess this is caused by some wrong openGLView configurations. So even though I am still not a 100% happy with my solution I guess it is the answer to my question.

提交回复
热议问题