【问题标题】:get all points of all counters in emgu cv获取 emgu cv 中所有计数器的所有分数
【发布时间】:2017-09-14 10:50:13
【问题描述】:

我想画一个旋转的矩形。精明的图像不是一个计数器,而是一组计数器。所以我想得到所有计数器的所有分数。例如

Points[] pts = points of all counters.

请看附图。

【问题讨论】:

    标签: c# emgucv


    【解决方案1】:

    canny 显示图像中的所有边缘,而不是外部轮廓。这是一种(但不是唯一的)进行对象检测(前景/背景提取)的方法。 以下 sn-p 使用 canny 边缘检测器提取对象 roi(最小区域矩形)。请注意来自 otsu 阈值的 canny thresh 参数。

    希望对您有所帮助。 Detection result

    Image<Gray,byte> imageFullSize = new Image<Gray, byte>(imagePath);
    Rectangle roi = new Rectangle(Your Top Left X,Your Top Left Y,Your ROI Width,Your ROI Height);
    //Now get a roi (No copy, it is a new header pointing original image
    Image<Gray,byte> image = imageFullSize.GetSubRect(roi);
    //Step 1 : contour detection using canny
    //Gaussian noise removal, eliminate background false détections
    image._SmoothGaussian(15);
    //Canny thresh based on otsu threshold value: 
    Mat binary = new Mat();
    double otsuThresh = CvInvoke.Threshold(image, binary, 0, 255, ThresholdType.Binary | ThresholdType.Otsu);
    double highThresh = otsuThresh;
    double lowThresh = otsuThresh * 0.5;
    var cannyImage = image.Canny(lowThresh, highThresh);   
    //Step 2 : contour extraction
    Mat hierarchy=new Mat();
    VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
    CvInvoke.FindContours(cannyImage,contours,hierarchy,RetrType.External,ChainApproxMethod.ChainApproxSimple);
    //Step 3 : contour fusion
    List<Point> points=new List<Point>();
    for(int i = 0; i < contours.Size; i++)
    {
        points.AddRange(contours[i].ToArray());
    }
    
    //Step 4 : Rotated rect
    RotatedRect minAreaRect = CvInvoke.MinAreaRect(points.Select(pt=>new PointF(pt.X,pt.Y)).ToArray());
    Point[] vertices = minAreaRect.GetVertices().Select(pt => new Point((int)pt.X, (int)pt.Y)).ToArray();
    //Step 5 : draw result
    Image <Bgr,byte > colorImageFullSize =new Image<Bgr, byte>(imagePath);
    Image <Bgr,byte > colorImage =colorImageFullSize.GetSubRect(roi);
    colorImage.Draw(vertices,new Bgr(Color.Red),2 );
    

    【讨论】:

    • 谢谢您,先生,它帮助我继续前进。但是我在更换 IC 时遇到了问题。
    • 另外请告诉我如何在这段代码中使用 ROI。谢谢
    • 谢谢你,先生,它帮了我很多。
    猜你喜欢
    • 1970-01-01
    • 2015-09-10
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    相关资源
    最近更新 更多