1

Say we have a robot\car\NPC\iPhone with a camera view. We controll all of its moves in a 3d space. Here is the algorithm we perform: capture a frame; move\rotate camera (save position and rotation diff: X, Y, Z; aX, aY aZ); capture new frame; do StereoBM. Now We want to perform opencv reprojectImageTo3D on a StereoBM result. It requieres a Q – 4 \times 4 perspective transformation matrix. I wonder how having translation and rotation diff (6 float values) can we get that 4 \times 4 perspective transformation matrix with out any image processing?

DuckQueen
  • 772
  • 10
  • 62
  • 134

1 Answers1

1

As shown in the documentation for reprojectImageTo3D, you can obtain the 4x4 perspective transform Q from stereoRectify.

However, if you want to create your own matrix, have a look here to see how 3D transformations can be written in a 4x4 matrix (though note that they're using the usual mathematical form, which is transposed from what is typical in computer vision), and here for an OpenCV example with the correct transposition in C++.

Basically you'll need to write the three separate rotation matrices and the translational matrix, and combine them all (via multiplication) to get your final 4x4 transformation matrix.

alkasm
  • 22,094
  • 5
  • 78
  • 94
  • I was looking into C++ version, and it seems like their 4x4 Translation matrix is mainly composed from digits `1`, `0` and `dx,dy,dz` - no respect for rotation. Is it Ok? – DuckQueen Jun 06 '17 at 15:11
  • Right...the translation matrix is just the translation. However it is multiplied by the rotation matrix. You can just take the three rotation matrices, multiply them together, and then add those three values to the fourth column. – alkasm Jun 06 '17 at 19:48