如何获取像素的形状后的坐标已纠正? [英] How to get coordinates of pixel after shape was rectified?

查看:666
本文介绍了如何获取像素的形状后的坐标已纠正?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为OpenCV使用EmguCV封装,我正在整理这个形状:

  public Image< ; Bgr,byte> Rectify()
{
try
{
图像< 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);

图像< 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);

图像< 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;
}

我得到这个结果



>



我知道角点坐标两个图像(整改前后)。
在整改之前,我知道形状内的上白线的坐标。
任何想法如何在纠正后得到这个白线的坐标?



提前感谢!

解决方案

使用单应性矩阵很容易。因为你知道单应性矩阵将直线映射到直线,所以你可以简单地投影输入图像线的端点
这里是一些香草伪代码:

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

mywarpmat.ProjectPoints(pts);

将包含您正在搜索的行的起点和终点在投影中,你必须简单地定义通过它们的线。


I'm using EmguCV wrapper for OpenCV and I'm rectifing this shape:

with help of this code:

 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;
        }

I get this result(rectified shape):

I know the corners coordinates both of the images (before and after rectification). Before the rectification I knew coordinates of the upper white line that inside the shape. Any idea how can i get the coordinates of this white line after rectification?

Thank you in advance!

解决方案

Having homography matrix it's quite easy. As you know an homography matrix maps straight line into straight line, so you can simply project the endpoints of your input image line Here's some vanilla pseudocode :

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

 mywarpmat.ProjectPoints(pts);

Pts will contained the starting and ending point of the line you are searching in the projected then you have to simply define line passing through them.

这篇关于如何获取像素的形状后的坐标已纠正?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆