我从 sourceImage 中提取了四个角:
src_vertices[0] = corners[upperLeft];
src_vertices[1] = corners[upperRight];
src_vertices[2] = corners[downLeft];
src_vertices[3] = corners[downRight];
这四个角像这样变形为 destinationImage:
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 中检索该点的坐标
换句话说,我想使用 warpPerspectiveMatrix 来完成与 getPerspectiveTransform 相反的工作
最佳答案
您需要逆透视变换。如果您的原始变换是 S->S',您需要变换矩阵 S'->S
Mat InversewarpPerspectiveMatrix = getPerspectiveTransform(dst_vertices, src_vertices);
然后你做一个稀疏矩阵
Mat PerspectiveCoordinates containing the vector x,y.
终于要打电话了
PerspectiveTransform(PerspectiveCoordinates,OriginalCoordinates,InversewarpPerspectiveMatrix)
关于image-processing - 检索从变形图像中获取的像素的原始坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14343420/