문제

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

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top