Dear Andrew,
I'm developing some application which can recognize the movement of a red colored object. And I went through some articles written based on AForge framework and I developed an application. but its performance is not good as i expect.
find the below code snippet
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AForge.Video.DirectShow;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge;
namespace AF_imgproc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
VideoCaptureDevice vc;
BlobCounter bc;
ColorFiltering colorFiltering;
Threshold thresholdFilter;
Grayscale grayFiter;
Dilatation dialFilter;
Erosion errFilter;
bool isProcessing = false;
private void button1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
colorFiltering = new ColorFiltering(new IntRange(110, 255), new IntRange(0, 60), new IntRange(0, 60));
grayFiter = new Grayscale(0.2125, 0.7154, 0.0721);
dialFilter = new Dilatation();
thresholdFilter = new Threshold(50);
errFilter = new Erosion();
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
vc = new VideoCaptureDevice(videoDevices[0].MonikerString);
vc.DesiredFrameSize = new Size(320, 240);
vc.DesiredFrameRate = 30;
vc.NewFrame += new AForge.Video.NewFrameEventHandler(vc_NewFrame);
vc.Start();
bc = new BlobCounter();
//bc.MaxWidth = 10;
//bc.MinHeight = 10;
bc.ObjectsOrder = ObjectsOrder.Size;
bc.FilterBlobs = true;
}
Bitmap frame;
void vc_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
if (!isProcessing)
{
frame = (Bitmap)eventArgs.Frame.Clone();
//AForge.Imaging.Image.FormatImage(ref frame);
isProcessing = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (isProcessing)
{
if (frame == null) return;
colorFiltering.ApplyInPlace(frame);
frame = grayFiter.Apply(frame);
thresholdFilter.ApplyInPlace(frame);
errFilter.ApplyInPlace(frame);
dialFilter.ApplyInPlace(frame);
bc.ProcessImage(frame);
if (bc.GetObjectsRectangles().Length > 0)
{
Rectangle rect = bc.GetObjectsRectangles()[0];
label1.Left = rect.X + (int)(rect.Width / 2);
label1.Top = rect.Y + (int)(rect.Height / 2);
}
pictureBox1.Image = frame;
isProcessing = false;
}
}
}
}
The problem I found here is, my object is not moving smoothly. sometimes it doesn't move even.
But i found that u have done the same thing for a motion of a
frame under below article.
Motion Detection Algorithms[
^]
I executed your demo project and i found that it works perfectly.
Can u help me to move my object smoothly as u done in yours?
If you have your own way of coding this same scenario...then you are always welcome.
If you could please reply me, because i've been struggling for more than 3 weeks on this matter.
Thank you,
Charith