2

I'm trying to determine the orientation of a face in a video.

The video starts with the frontal image of the face, so it has no rotation. In the following frames the head rotates and i'm trying to determine the rotation, which will lead me to determine the face orientation based on the camera position.

I'm using OpenCV and C++ for the job. I'm using SURF descriptors to find points on the face which i use to calculate an homography between the two images. Being the two frames very close to each other, the head rotation will be minimal in that interval and my homography matrix will be close to the identity matrix.

This is my homography matrix:

H = findHomography(k1,k2,RANSAC,8);

where k1 and k2 are the keypoints extracted with SURF.

I'm using decomposeProjectionMatrix to extract the rotation matrix but now i'm not sure how to interpret the rotMatrix. This one too is basically (1 0 0; 0 1 0; 0 0 1) (where the 0 are numbers in a range from e-10 to e-16).

In theory, what is was trying to do was to find the angle of the rotation at each frame and store it somewhere, so that if i get a 1° change in each frame, after 10 frames i know that my head has changed its orientation by 10°.

I spend some time reading everything i could find about QR decomposition, homography matrices and so on, but i haven't been able to get around this. Hence, any help would be really appreciated.

Thanks!

powder
  • 1,163
  • 2
  • 16
  • 32

1 Answers1

0

The upper-left 2x2 of the homography matrix is a 2D rotation matrix. If you work through the multiplication of the matrix with a point (i.e. take R*p), you'll see it's equivalent to:

newX = oldVector dot firstRow
newY = oldVector dot secondRow

In other words, the first row of the matrix is a unit vector which is the x axis of the new head. (If there's a scale difference between the frames it won't be a unit vector, but this method will still work.) So you should be able to calculate

rotation = atan2(second entry of first row, first entry of first row)
Luke
  • 5,329
  • 2
  • 29
  • 34