【问题标题】:C# AForge.Net image processing drawing on imageC# AForge.Net 图像处理在图像上绘图
【发布时间】:2016-04-25 15:56:40
【问题描述】:

我正在使用这个例子: http://www.aforgenet.com/framework/features/blobs_processing.html

我尝试使用最后一个示例,并在单击按钮后在图片框中显示输出:

using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Math.Geometry;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Image_Processing_testings
{
public partial class Form1 : Form
{
    Bitmap image = null;
    public Form1()
    {
        InitializeComponent();
        Bitmap bitmap = new Bitmap("C:\\Users\\user\\Desktop\\test.png");
        Bitmap gsImage = Grayscale.CommonAlgorithms.BT709.Apply(bitmap);

        DifferenceEdgeDetector filter = new DifferenceEdgeDetector();
        image = filter.Apply(gsImage);



        // process image with blob counter
        BlobCounter blobCounter = new BlobCounter();
        blobCounter.ProcessImage(image);
        Blob[] blobs = blobCounter.GetObjectsInformation();

        // create convex hull searching algorithm
        GrahamConvexHull hullFinder = new GrahamConvexHull();

        // lock image to draw on it
        BitmapData data = image.LockBits(
            new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadWrite, image.PixelFormat);
        int i = 0;
        // process each blob
        foreach (Blob blob in blobs)
        {
            List<IntPoint> leftPoints, rightPoints, edgePoints = new List<IntPoint>();

            // get blob's edge points
            blobCounter.GetBlobsLeftAndRightEdges(blob,
                out leftPoints, out rightPoints);

            edgePoints.AddRange(leftPoints);
            edgePoints.AddRange(rightPoints);

            // blob's convex hull
            List<IntPoint> hull = hullFinder.FindHull(edgePoints);


            Drawing.Polygon(data, hull, Color.Red);
            i++;
        }

        image.UnlockBits(data);


        MessageBox.Show("Found: " + i + " Objects");
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        pictureBox1.Image = image;
    }
}
}

结果是我得到了过滤后的图像,但上面没有任何多边形。

我数了一下blob的数量,这张照片得到了3个:

【问题讨论】:

  • 您提供的链接中的示例假定白色像素属于对象,黑色像素属于背景。您提供的图像正好相反。因此,在应用算法之前反转图像,看看它是否有效。
  • 没问题。您介意我添加答案以便您投票并接受吗? :) 我不介意得到代表。
  • 当然!没问题。再次感谢。
  • 太棒了。非常感谢!一切顺利。

标签: c# image-processing drawing aforge


【解决方案1】:

您提供的链接中的示例假定白色像素属于对象,黑色像素属于背景。您提供的图像正好相反。因此,在应用算法之前反转图像应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 2010-10-04
    • 2011-05-16
    相关资源
    最近更新 更多