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?
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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With