Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between warpPerspective and perspectiveTransform?

I have used four sets of points to get a perspective transform matrix. Then using warpPerspective to transform the matrix A to matrix B. Point a from Mat A. I want to get the new point a position in mat B. But warpPerspective cannot do that, while perspectiveTransform can.

Here I want to know if the position that perspectiveTransform gets is the same as the position in matrix B by using warpPerspective.

So, what is the difference between warpPerspective and perspectiveTransform?

Mat trans = getPerspectiveTransform(dst, gpsPoints);
warpPerspective(A, B, trans, image.size());
Point2f a = Point2f(..., ...);         //were known
vector<Point2f> obj(1);
obj[0] = a;
vector<Point2f> b; 
perspectiveTransform(obj, b, trans);//if the new point in B is c, is c equals to b?
like image 574
kookoo121 Avatar asked Dec 06 '15 10:12

kookoo121


People also ask

What is warp perspective?

We make use of a function called warpPerspective() function to fit the size of the resulting image by using the getPerspectiveTransform() function to the size of the original image or video. The warpPerspective() function returns an image or video whose size is the same as the size of the original image or video.

How does OpenCV perspective transform work?

A perspective transformation is simply a fractional linear equation that is solved from a matrix formation. The fractional linear equation is of the form that is linear in the numerator and linear in the denominator, i.e. first order terms at the highest in both numerator and denominator.

What is a perspective transform?

Fundamentally, it is a transformation of a frame of reference that allows a more “democratic” way of perceiving and acting in the world. Perspective transformation implies not just a change of perception but action as well because it is not enough to see the world differently; one must act differently in it.

What is warping in OpenCV?

In this tutorial, I will show you image warping in OpenCV. Perspective view warping is to convert or perspective correction of images from angle to birds eye view transform. To convert image to birds eye view I will be using warp perspective OpenCV function.


1 Answers

warpPerspective works for images. In other words, warpPerspective can warp image A and put the result in B using the H (Homography or warpMatrix) so it has the following struct:

void warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())

src is the Mat you want to warp, dst where the result will be stored.

perspectiveTransform works for set of points. It applies the H (Homography or warpMatrix) on set of points (which are in vector for example) and put the results in another vector. The results are the points in the first vector after applying the warping. it has the following struct:

void perspectiveTransform(InputArray src, OutputArray dst, InputArray m)

where src is the input points, dst is the results of warping the input points.

Conclusion:

Mathematically, they both do the same thing which is warping a set of point using H.

Technically, warpPerspective do this on the coordinates of the Mat and move the pixel value(color) to a new pixel. perspectiveTransform, it just compute the new coordinate of the point and store it in the new vector.

like image 62
Humam Helfawi Avatar answered Oct 21 '22 08:10

Humam Helfawi