First time here? Check out the FAQ!

Ask Your Question
2

How does the perspectiveTransform( ) function work?

asked Feb 10 '15

Potato gravatar image

In the tutorial -> http://docs.opencv.org/doc/tutorials/...
I understand that the syntax for this function is as follows: perspectiveTransform(obj_corners, scene_corners, H);
Where obj_corners and scene_corners are vectors of Points and obj_corners contains 4 points of the object to be found and H is the homography matrix. My question is, what exactly does this function do?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
5

answered Feb 10 '15

Eduardo gravatar image

updated Feb 10 '15

Hi,

You should first read about the homography concept, for example : https://en.wikipedia.org/wiki/Homogra... or http://people.scs.carleton.ca/~c_shu/...

Basically, the matrix H contains the geometric transformation to pass from a view to another view assuming a planar surface in space.

In the tutorial, after the matching of the keypoints, you estimate the homography H using a RANSAC method (a robust method to estimate the homography without (trying to not) taking care of the possible outliers) with :

> Mat H = findHomography( obj, scene, CV_RANSAC );

So :

perspectiveTransform( obj_corners, scene_corners, H);

will just calculate the coordinates of the box corners in the current view / scene to draw the bounding box.

Edit: The function calculates for each corners (if I am not wrong) :

w = H_31 * obj_corners[i].x + H_32 * obj_corners[i].y + H_33 * 1
scene_corners[i].x = (H_11 * obj_corners[i].x + H_12 * obj_corners[i].y + H_13 * 1) / w
scene_corners[i].y = (H_21 * obj_corners[i].x + H_22 * obj_corners[i].y + H_23 * 1) / w
Preview: (hide)

Comments

Great, That simplifies a lot of things. When you say that the homography is 'estimated', does that mean that it is not always accurate? Similarly, I have seen that a function warpPerspective( ) also uses the H. Would you happen to know how that works? ---> http://ramsrigoutham.com/2012/11/22/p...

Potato gravatar imagePotato (Feb 10 '15)edit
2

warpPerspective use the same principle than perspectiveTransform but with an image (the box in the tutorial will be warped to the box as you can seen it in the scene image). It is not always accurate for different reasons:

  • first, the matching of the keyppoints is not accurate (e.g. false / bad matching)
  • some other reasons may occured (general scenario, not only in the case of the tutorial): coordinates in images are not accurate, camera distorsion, image noise, numerical errors, etc.
Eduardo gravatar imageEduardo (Feb 10 '15)edit

That clears a lot of things up. Thank you for you help!

Potato gravatar imagePotato (Feb 10 '15)edit

Question Tools

1 follower

Stats

Asked: Feb 10 '15

Seen: 25,214 times

Last updated: Feb 10 '15