如何使用Aforge将多个过滤器应用于图像

时间:2015-03-27 09:21:57

标签: c# filter aforge colorfilter

我可以单独过滤红色和蓝色但我想同时过滤两个..所以我的代码是这样的

//FOR RED COLOR
ColorFiltering filter = new ColorFiltering();
filter.Red = new IntRange(100, 255);
filter.Green = new IntRange(0, 75);
filter.Blue = new IntRange(0, 75);
filter.ApplyInPlace(image1);
MyDraw(image1);


// FOR BLUE COLOR
EuclideanColorFiltering filter2 = new EuclideanColorFiltering();
filter2.CenterColor = new RGB(Color.FromArgb(9, 39, 101));
filter2.Radius = 50;
filter2.ApplyInPlace(image1);

MyDraw(image1);


public void MyDraw(Bitmap image)
{
BlobCounter blobCounter = new BlobCounter();
blobCounter.MinWidth = 2;
blobCounter.MinHeight = 2;
blobCounter.FilterBlobs = true;
blobCounter.ObjectsOrder = ObjectsOrder.Size;

Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
Bitmap grayImage = grayFilter.Apply(image);

blobCounter.ProcessImage(grayImage);
Rectangle[] rects = blobCounter.GetObjectsRectangles();
foreach (Rectangle recs in rects)
{

    if (rects.Length > 0)
    {
        Rectangle objectRect = rects[0];
        //Graphics g = Graphics.FromImage(image);
        Graphics g = pictureBox1.CreateGraphics();
        reception = "Cam," + objectRect.X + "," + objectRect.Y;
        Console.WriteLine("X: " + objectRect.X + "   Y:" + objectRect.Y.ToString());

        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
        {

            g.DrawRectangle(pen, objectRect);
        }
        int objectX = objectRect.X + (objectRect.Width / 2);
        int objectY = objectRect.Y + (objectRect.Height / 2);
        g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
        g.Dispose();
    }
}
}

所以我想识别网络摄像头上的蓝色和红色形状,并在识别的形状周围绘制一个矩形。现在,我可以做成红色或蓝色。但我想同时识别红色和蓝色

如何添加多个过滤器?

0 个答案:

没有答案