Different between warpPerspective and perspectiveTransform

杀马特。学长 韩版系。学妹 提交于 2019-12-10 20:13:28

问题


I have used four sets of points to get a PerspectiveTransform matrix t.Then using warpPerspective to tranform Mat A to Mat B. Point a from Mat A .I want to get the new Point a position in Mat B.But warpPerspective() can not do that while perspectiveTransform can. Here i want to know if the position get from perspectiveTransform is same with position in Mat B by using warpPerspective. So , what's the different 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?

回答1:


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.



来源:https://stackoverflow.com/questions/34116357/different-between-warpperspective-and-perspectivetransform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!