简体   繁体   English

warpPerspective 和perspectiveTransform 有什么区别?

[英]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 .然后使用warpPerspective将矩阵A转换为矩阵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.来自垫 A 的点 a。我想在垫 B 中获得新点的位置。但warpPerspective不能这样做,而perspectiveTransform warpPerspective可以。

Here I want to know if the position that perspectiveTransform gets is the same as the position in matrix B by using warpPerspective .这里我想通过使用warpPerspective来知道perspectiveTransform变换得到的位置是否与矩阵 B 中的位置相同。

So, what is the difference between warpPerspective and perspectiveTransform ?那么, warpPerspectiveperspectiveTransform之间有什么区别?

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?

warpPerspective works for images. warpPerspective适用于图像。 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:换句话说,warpPerspective 可以使用 H(Homography 或 warpMatrix)扭曲图像 A 并将结果放在 B 中,因此它具有以下结构:

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. src是您要扭曲的Matdst是结果将存储的位置。

perspectiveTransform works for set of points. perspectiveTransform适用于一组点。 It applies the H (Homography or warpMatrix) on set of points (which are in vector for example) and put the results in another vector .它将 H(Homography 或 warpMatrix)应用于一组点(例如在vector中)并将结果放入另一个vector The results are the points in the first vector after applying the warping.结果是应用变形后第一个vector中的点。 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.其中src是输入点, dst是扭曲输入点的结果。

Conclusion :结论

Mathematically , they both do the same thing which is warping a set of point using H.从数学上讲,它们都做同样的事情,即使用 H 扭曲一组点。

Technically , warpPerspective do this on the coordinates of the Mat and move the pixel value(color) to a new pixel.从技术上讲warpPerspectiveMat的坐标上执行此操作并将像素值(颜色)移动到新像素。 perspectiveTransform , it just compute the new coordinate of the point and store it in the new vector . perspectiveTransform vector ,它只是计算点的新坐标并将其存储在新vector

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM