Ask Your Question
1

How does the perspectiveTransform( ) function work?

asked 2015-02-10 08:33:51 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-02-10 10:46:07 -0500

Eduardo gravatar image

updated 2015-02-10 10:55:08 -0500

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
edit flag offensive delete link more

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 ( 2015-02-10 11:10:13 -0500 )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 ( 2015-02-10 11:33:00 -0500 )edit

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

Potato gravatar imagePotato ( 2015-02-10 13:05:38 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-02-10 08:33:51 -0500

Seen: 6,097 times

Last updated: Feb 10 '15