Click here to Skip to main content
15,936,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 28-Jan-10 18:09pm
v2

Three points


Charithmax wrote:
charith.nishara@gmail.com


This is stupid, it will get you spam


Charithmax wrote:
VideoCaptureDevice vc;
BlobCounter bc;
ColorFiltering colorFiltering;
Threshold thresholdFilter;
Grayscale grayFiter;


your code doesn't do much, it relies on an external component. Therefore, you'll struggle to make it more efficient apart from by doing your testing less often, unless it has options you can set.


Charithmax wrote:
But i found that u have done the same thing for a motion of a frame under below article.
Motion Detection Algorithms[^]


How someone can look at this site and assume that all the articles are written by a paid team, who also work together to answer all the questions, is beyond me. This site's content is provided by volunteers all over the world. The odds of the person who wrote that article seeing this post are close to zero . That's why the article has a forum underneath it for people to post questions to the author.
 
Share this answer
 
Thanks for your all advices....Mr.Christian :thumbsup:
but ur answer doesn't help me to success my work. :confused:


Mr.Andrew.....if you could please attend on this.

Thanks....
Charith
 
Share this answer
 
You must not have understood Christian's answer.

Go to the article in Code Project.
Scroll right down towards the bottom.
You will see an area where you can ask questions or make comments.
THIS is where you ask questions of the author.
Cheers dude.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900