C#a org.Net图像处理在图像上绘制

C#a org.Net图像处理在图像上绘制,c#,image-processing,drawing,aforge,C#,Image Processing,Drawing,Aforge,我用这个例子: 我尝试使用上一个示例,并在单击按钮后在图片框中显示输出: 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 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;
    }
}
}
使用一个rge;
使用快速成像;
使用热成像滤光片;
使用forge.Math.Geometry;
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用系统、绘图、成像;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间图像\u处理\u测试
{
公共部分类Form1:Form
{
位图图像=空;
公共表格1()
{
初始化组件();
位图位图=新位图(“C:\\Users\\user\\Desktop\\test.png”);
位图gsImage=Grayscale.CommonAlgorithms.BT709.Apply(位图);
DifferenceEdgeDetector过滤器=新的DifferenceEdgeDetector();
image=filter.Apply(gsImage);
//用blob计数器处理图像
BlobCounter BlobCounter=新BlobCounter();
blobCounter.ProcessImage(图像);
Blob[]blobs=blobCounter.GetObjectsInformation();
//创建凸壳搜索算法
GrahamConvexHull hullFinder=新GrahamConvexHull();
//锁定图像以在其上绘制
BitmapData数据=image.LockBits(
新矩形(0,0,image.Width,image.Height),
ImageLockMode.ReadWrite、image.PixelFormat);
int i=0;
//处理每个blob
foreach(水滴中的水滴)
{
列出左点、右点、边点=新列表();
//获取水滴的边缘点
blobCounter.GetBlobLeftandRightEdge(blob,
输出左点,输出右点);
edgePoints.AddRange(左点);
edgePoints.AddRange(右点);
//水滴凸壳
列表外壳=hullFinder.FindHull(边点);
图形。多边形(数据、外壳、颜色。红色);
i++;
}
图像。解锁位(数据);
Show(“发现:+i+”对象);
}
私有无效按钮1\u单击\u 1(对象发送者,事件参数e)
{
pictureBox1.图像=图像;
}
}
}
结果是,我得到的图像过滤后,但没有任何多边形上

我数了数水滴的数量,这张照片得到了3个:


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

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