问题
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