用平面上的4个点进行图像去畸变/去弯曲

4
我想使用Python(OpenCV / PIL等)对图像进行去畸变。我有4个点,它们应该在一个平面上形成一个矩形。
在GIMP中,我可以使用反向校正手动去除图像的畸变,但我想编写一个程序,不依赖于GIMP。
我找到的所有函数都依赖于变换矩阵,因此我想了解如何计算正确的矩阵。
感谢您的帮助。
2个回答

3

计算此矩阵,使用:

cv2.getPerspectiveTransform(src, dst)

使用src包含您的4个点的列表,使用dst包含新图像的角落。注意,它们必须按正确的顺序排列。

1
我不使用Python,但以下是C++的答案,应该是一样的:
transformationMatrix= cv::getPerspectiveTransform(source , dst_pnt);  // getting the transformation matrix 

cv::warpPerspective(src, quad, transformationMatrix,perspectiveSize,1); // warping


.........................
unwarping 

cv::Matx33f unwarp = transformMatrix;
    cv::Point3f homogeneous = unwarp.inv() *pTmp; // pTmp is a point in your transformaed frame 

cv::Mat unwarpFrame =  unwarp.inv() * srcFrame;   // in case of a frame 
enter code here

谢谢!实际上帮助我找到了正确的变形函数。 - gspoosi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接