检索从变形图像获取的像素的原始坐标

问题描述:

我从 sourceImage 中提取了四个角:

src_vertices[0] = corners[upperLeft];
src_vertices[1] = corners[upperRight];   
src_vertices[2] = corners[downLeft];
src_vertices[3] = corners[downRight];

这四个角像这样扭曲到 destinationImage :

These four corners are warped to destinationImage like that:

dst_vertices[0] = Point(0,0);
dst_vertices[1] = Point(width, 0); 
dst_vertices[2] = Point(0, height);
dst_vertices[3] = Point(width, height);

Mat warpPerspectiveMatrix = getPerspectiveTransform(src_vertices, dst_vertices);
cv::Size size_d =  Size(width, height);
cv::Mat DestinationImage(width,height,CV_8UC3);
warpPerspective(sourceImage, destinationImage, warpPerspectiveMatrix, size_d, INTER_LINEAR, BORDER_CONSTANT);

现在我的问题是:

我从 destinationImage 中获取了一个点p(x,y),如何在原始sourceImage中获取该点的坐标

I have a point p(x,y) taken from the destinationImage how can I retrieve the coordinates of this point in the original sourceImage

换句话说,我想使用warpPerspectiveMatrix来做getPerspectiveTransform的相反工作

In other words I want to use warpPerspectiveMatrix to do the opposite work of getPerspectiveTransform

您需要反向透视变换.如果原始转换为S-> S',则需要转换矩阵S'-> S

You want the inverse perspective transform. If your original transform is S->S', you want the transform matrix S'->S

Mat InversewarpPerspectiveMatrix = getPerspectiveTransform(dst_vertices, src_vertices);

然后创建一个SPARSE矩阵

Then you make a SPARSE matrix

Mat PerspectiveCoordinates containing the vector x,y.

最后你想打电话

PerspectiveTransform(PerspectiveCoordinates,OriginalCoordinates,InversewarpPerspectiveMatrix)