Retrieving the original coordinates of a pixel taken from a warped Image

橙三吉。 提交于 2019-12-12 15:04:37

问题


I have four corners extracted from a sourceImage:

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

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);

Now my question is:

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

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


回答1:


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);

Then you make a SPARSE matrix

Mat PerspectiveCoordinates containing the vector x,y.

Finally you want to call

PerspectiveTransform(PerspectiveCoordinates,OriginalCoordinates,InversewarpPerspectiveMatrix)


来源:https://stackoverflow.com/questions/14343420/retrieving-the-original-coordinates-of-a-pixel-taken-from-a-warped-image

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