繁体   English   中英

使用Emgu(OpenCV)进行转换-仿射/透视图?

[英]Transformations with Emgu (OpenCV) - Affine/perspective?

我目前正在尝试通过使用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其他有用的方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM