问题描述
我使用了四组点来获得透视变换矩阵.然后使用warpPerspective
将矩阵A
转换为矩阵B
.来自 Mat A 的点 a.我想在 mat B 中获得新点的位置.但是 warpPerspective
不能这样做,而 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.
这里我想通过warpPerspective
来知道perspectiveTransform
得到的位置是否与矩阵B中的位置相同.
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
有什么区别?
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?
推荐答案
warpPerspective
适用于图像.换句话说,warpPerspective 可以使用 H(Homography 或 warpMatrix)扭曲图像 A 并将结果放在 B 中,因此它具有以下结构:
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
是您要变形的 Mat
,dst
将存储结果.
src
is the Mat
you want to warp, dst
where the result will be stored.
perspectiveTransform
适用于一组点.它将 H(Homography 或 warpMatrix)应用于一组点(例如在 vector
中)并将结果放入另一个 vector
.结果是应用变形后第一个 vector
中的点.它具有以下结构:
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)
其中 src
是输入点,dst
是输入点变形的结果.
where src
is the input points, dst
is the results of warping the input points.
结论:
数学上,他们都做同样的事情,即使用 H 扭曲一组点.
Mathematically, they both do the same thing which is warping a set of point using H.
技术上,warpPerspective
在Mat
的坐标上执行此操作并将像素值(颜色)移动到新像素.perspectiveTransform
,它只是计算点的新坐标并将其存储在新的vector
中.
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
.
这篇关于warpPerspective 和perspectiveTransform 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!