【问题标题】:How to get coordinates of pixel after shape was rectified?纠正形状后如何获取像素坐标?
【发布时间】:2013-05-16 23:25:32
【问题描述】:

我正在为 OpenCV 使用 EmguCV 包装器,并且正在纠正这个形状:

借助此代码:

 public Image<Bgr,byte> Rectify()
    {
        try
        {
            Image<Bgr, byte> warped_Image = new Image<Bgr, byte>(input_Image.Width, input_Image.Height);

            MCvScalar s = new MCvScalar(0, 0, 0);

            PointF[] dsts = new PointF[4];
            dsts[0] = new PointF(0, 0);
            dsts[2] = new PointF(0, input_Image.Height);
            dsts[3] = new PointF(input_Image.Width, input_Image.Height);
            dsts[1] = new PointF(input_Image.Width, 0);

            HomographyMatrix mywarpmat = CameraCalibration.GetPerspectiveTransform(pnts, dsts);

            Image<Bgr, byte> warped_Image2 = warped_Image.WarpPerspective(mywarpmat, Emgu.CV.CvEnum.INTER.CV_INTER_NN, Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS, new Bgr(0, 0, 0));

            CvInvoke.cvWarpPerspective(input_Image, warped_Image2, mywarpmat, (int)Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, s);

            Image<Bgr, byte> fixedImg = new Image<Bgr, byte>((int)warped_Image2.Width, (int)(warped_Image2.Width / aspectRatio));

            CvInvoke.cvResize(warped_Image2.Ptr, fixedImg.Ptr, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

            return fixedImg;
        }

我得到这个结果(修正后的形状):

我知道两个图像的角坐标(校正前后)。 在校正之前,我知道形状内部的上白线的坐标。 知道校正后如何获得这条白线的坐标吗?

提前谢谢你!

【问题讨论】:

    标签: .net opencv image-processing computer-vision emgucv


    【解决方案1】:

    您已经有了单应矩阵,因此要获得线上的点,只需使用单应变换第一张图像(校正前)的点。这将为您提供校正后图像中的坐标。

    更多详情,请查看homography 的数学定义。基本上,你需要找到直线上的点(或者直线的两个端点),并用齐次坐标表示,类似于文章中定义p_a的方式。然后,您使用单应性变换这些点并通过 Z 坐标进行归一化以获得变换点的图像坐标。这已在文章中定义为 p_b。

    希望这会有所帮助。

    【讨论】:

    • Zaphod,我是图像处理的初学者。所以也许我的问题对你来说似乎很幼稚,如何在单应性的帮助下在图像校正之前转换点?
    【解决方案2】:

    拥有单应矩阵很容易。如您所知,单应矩阵将直线映射为直线,因此您可以简单地投影输入图像线的端点 这是一些普通的伪代码:

     PointF[] pts = new PointF[] { 
                    new PointF(startingLinePoint.x, startingLinePoint.y),
                    new PointF(endingLinePoint.x, endingLinePoint.y)
            };
    
     mywarpmat.ProjectPoints(pts);
    

    Pts 将包含您在投影中搜索的线的起点和终点,然后您必须简单地定义穿过它们的线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2018-02-13
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多