我目前正在尝试通过使用 EMGU 来实现转换,尽管我似乎无法理解它是如何工作的(而且网上似乎没有任何示例)。
我已经得到了我的图像,其中包含我希望转换的 4 个点,尽管我不知道还需要哪些其他变量,但它要求“mapMat”?
这是我到目前为止所拥有的:
float[,] tmp = {
{bottomLeft.x, bottomLeft.y},
{topLeft.x, topLeft.y},
{topRight.x, topRight.y},
{bottomRight.x, bottomRight.y}
};
Matrix<float> sourceMat = new Matrix<float>(tmp);
float[,] target = {
{0, height},
{0, 0},
{width, 0},
{width, height}
};
Matrix<float> targetMat = new Matrix<float>(target);
//mapMat = just a placeholder matrix?
Matrix<float> mapMat = new Matrix<float>(target);
CvInvoke.cvGetAffineTransform(sourceMat.Ptr, targetMat.Ptr, mapMat.Ptr);
但这不起作用。我也不确定仿射变换是否是最理想的解决方案?我也读过一些有关 FindHomography 的内容以及透视变换,但不确定它们是否适用于此处。
我希望实现的目标转变是这样的:
http://img832.imageshack.us/img832/5157/targettransform.png
任何帮助将不胜感激,
谢谢
最佳答案
首先简单介绍一下:
- 如果您想要仿射变换(正如您的图片所示),您至少需要 3 个点对,因为您有 6 个参数需要估计
- 如果您想要更通用的变换,即单应性,您至少需要 4 个点对,因为您有 8 个参数需要估计
因此,假设您有 4 个源角和目标角,并且您想要估计透视变换,此代码应该执行您想要的操作:
PointF[] pts1 = new PointF[4];
PointF[] pts2 = new PointF[4];
HomographyMatrix homography;
for (int i = 0; i < 4; i++)
{
pts1[i] = new PointF (sourceCorner[i].X, sourceCorner[i].Y);
pts2[i] = new PointF (destCorner[i].X, destCorner[i].Y);
}
homography = CameraCalibration.GetPerspectiveTransform(pts1, pts2);
查看 CameraCalibration 了解其他有用的方法
关于c# - 使用 Emgu (OpenCV) 进行变换 - 仿射/透视?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4916012/