0

I am working with a point cloud and multiple images. I know the camera's intrinsic and extrinsic parameters. What I want is to find the rotation matrix which will rotate my camera(without changing the position) to view in a certain direction. More specifically, I would fit a plane to the point cloud and then I want to align my camera's viewing direction to view perpendicular to the plane(without changing its position).

Accordingly, I would find the homography transform for the image also, given the rotation matrix for the camera.

Please someone help me with this.

Harshit Agrawal
  • 903
  • 1
  • 7
  • 11
  • Can't you just create a new view-matrix for the camera, which uses the desired position/direction or do you need to have the rotation matrix? Btw are you using some libraries like Direct3D or OpenGL ? – miloszmaki Mar 29 '13 at 14:12
  • No, I am not using any libraries. I want to get the rotation matrix, so that I can project the point cloud on the image to get the depth map corresponding to the image. I hope it makes sense. – Harshit Agrawal Mar 29 '13 at 14:35

2 Answers2

0

Let dir1 be the current direction of the camera and dir2 be target direction of the camera. Calculate normalized direction vectors:

d1 = dir1 / |dir1|
d2 = dir2 / |dir2|

We want to get a matrix which rotates from d1 to d2. In other words, this matrix should perform rotation by an angle of theta about an axis in the direction of u, where:

u = (d1 x d2) / |d1 x d2|       <-- normalized cross product of d1 and d2
sin(theta) = |d1 x d2|          <-- the length of the cross product
cos(theta) = d1 * d2            <-- dot product of d1 and d2

Finally, we plug the above values into this formula (you can read more here), obtaining the requested matrix:

rotation matrix

miloszmaki
  • 1,635
  • 15
  • 21
  • Hi Miloszmaki, I got your response. I have a simpler doubt. We don't have to translate the camera back to origin to perform this rotation, or do we? – Harshit Agrawal Mar 29 '13 at 15:12
  • If your camera is not at the origin, then you have to perform the rotation first, and then do the translation to the target position. – miloszmaki Mar 29 '13 at 15:14
0

Assuming x is the center of the image then say c = [a,b,1] (this is considering the image is a 2D image).

Now you have the intrinsic parameter matrix K and extrinsic-Rotational matrix R

We can find the direction in this style:

temp_X = inverse(K) * c
temp_X = transpose(R) * temp_X
direction = temp_X / norm(temp_X)

final direction = t - direction

I don't know whether this is completely right but you can give it a try.

Math
  • 3,334
  • 4
  • 36
  • 51