getprespectivetransform or alternatives which one is better [closed]

asked 2015-07-08 03:53:32 -0600

Prem gravatar image

updated 2015-07-08 03:55:02 -0600

I have identified a rectangular area in my image space ( programmetically I have fuor points in a vector representing vertices of a rectangle or quadrilateral ) in live camera feed. The shape is unknown in advance but it is known that it is a polygon with 4 vertices. I would like to display an image within that area. Here is my code.

 vector<Point2f> knownLiveFeedPoints; // this vector contains four Point2f Coordinates
 Mat repImage = imread("replace1.jpg");
vector<Point2f> imagePoints = { Point2f(0, 0), Point2f(repImage.cols, 0),
                                         Point2f(repImage.cols, repImage.rows), Point2f(0, repImage.rows), };

Mat transmix = getPerspectiveTransform(imagePoints, knownLiveFeedPoints);
warpPerspective(repImage, cameraFeed, transmix, cameraFeed.size(), cv::INTER_LINEAR, cv::BORDER_TRANSPARENT);

This is working fine. Here I would like to know what is being done by getPrespectiveTransform ( would really appreciate a sample matrix calculation ) and wrapPrespective ? I went through openCV documentation many times but got lost in many alternatives and generic explanation. Can I achieve exactly same functionality using findHomography() ? what would be the difference ? Thanks in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-05 23:41:53.961614

Comments

findHomography is for 3D objects, while warpPerspective is for 2D planar objects. The first one is a more complex version of the second one (in big lines). So I would not suggest you to use the findHomography for a quadrilateral object, except if it is an object that may deform (like a silk, it may get curved or something like that...)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-08 04:25:20 -0600 )edit

@thdrksdfthmn thanks for the explanation. Can you please explain how transmix (in my code) is computed in matrix format? or provide some URL which explains the calculation in simple form with an example.

Prem gravatar imagePrem ( 2015-07-08 04:46:03 -0600 )edit

Have you google it?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-08 04:52:07 -0600 )edit

I need exactly what happens at matrix level, so far couldn't find it over google.

Prem gravatar imagePrem ( 2015-07-08 05:39:07 -0600 )edit

OK, you don't get it from the wikipedia... The idea is that you give the 4 points in the order that you fixed (so, after the projection, you'll get the frontal object); Based on their places, and the expected position, it will compute the angle of rotation (θ), the factor of shearing (k), and the reflection (if there is one). If you want even deeper info, then you shall go in the code, to see exactly how it is done...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-08 06:25:59 -0600 )edit