运动检测-AForge [英] Motion Detection-AForge

查看:118
本文介绍了运动检测-AForge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的安德鲁,

我正在开发一些可以识别红色物体运动的应用程序.我浏览了一些基于AForge框架编写的文章,并开发了一个应用程序.但是它的表现不如我预期.

找到下面的代码片段

使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Text;
使用System.Windows.Forms;
使用AForge.Video.DirectShow;
使用AForge.Imaging;
使用AForge.Imaging.Filters;
使用AForge;

命名空间AF_imgproc
{
公共局部类Form1:Form
{
公共Form1()
{
InitializeComponent();
}

VideoCaptureDevice vc;
BlobCounter bc;
ColorFiltering colorFiltering;
阈值thresholdFilter;
灰度grayFiter;

膨胀DialFilter;

侵蚀errFilter;

bool isProcessing = false;



private void button1_Click(对象发送者,EventArgs e)
{

}

私有void Form1_Load(对象发送者,EventArgs e)
{
colorFiltering =新的ColorFiltering(新的IntRange(110,255),新的IntRange(0,60),新的IntRange(0,60));

grayFiter =新的灰度(0.2125,0.7154,0.0721);
DialFilter = new Dilatation();
thresholdFilter =新阈值(50);
errFilter = new Erosion();

FilterInfoCollection videoDevices =新的FilterInfoCollection(FilterCategory.VideoInputDevice);

vc = new VideoCaptureDevice(videoDevices [0] .MonikerString);
vc.DesiredFrameSize = new Size(320,240);
vc.DesiredFrameRate = 30;

vc.NewFrame + =新的AForge.Video.NewFrameEventHandler(vc_NewFrame);

vc.Start();

bc = new BlobCounter();
//bc.MaxWidth = 10;
//bc.MinHeight = 10;
bc.ObjectsOrder = ObjectsOrder.Size;
bc.FilterBlobs = true;
}

位图框架;

无效vc_NewFrame(对象发送者,AForge.Video.NewFrameEventArgs eventArgs)
{
如果(!isProcessing)
{

框架=(位图)eventArgs.Frame.Clone();
//AForge.Imaging.Image.FormatImage(ref frame);
isProcessing = true;
}



}

private void timer1_Tick(对象发送者,EventArgs e)
{
如果(isProcessing)
{


如果(frame == null)返回;

colorFiltering.ApplyInPlace(frame);

frame = grayFiter.Apply(frame);

thresholdFilter.ApplyInPlace(frame);

errFilter.ApplyInPlace(frame);
DialFilter.ApplyInPlace(frame);

bc.ProcessImage(frame);

如果(bc.GetObjectsRectangles().长度> 0)
{
矩形rect = bc.GetObjectsRectangles()[0];


label1.Left = rect.X +(int)(rect.Width/2);
label1.Top =矩形Y +(int)(矩形高度/2);
}

pictureBox1.Image =框架;

isProcessing = false;
}
}



}
}


我在这里发现的问题是,我的物体无法平稳移动.有时甚至不动.

但是我发现您在下面的文章中为框架的运动做了同样的事情.
运动检测算法 [

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

推荐答案

三点


Three points


Charithmax写道:
Charithmax wrote:

charith.nishara@gmail.com

charith.nishara@gmail.com



这很愚蠢,会让您收到垃圾邮件




This is stupid, it will get you spam


Charithmax写道:
Charithmax wrote:

VideoCaptureDevice vc;
BlobCounter bc;
ColorFiltering colorFiltering;
阈值thresholdFilter;
灰度grayFiter;

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写道:
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.


感谢您的所有建议....克里斯蒂安先生:thumbsup:
但是您的回答并不能帮助我成功地完成工作. :confused:


安德鲁先生.....如果可以的话,请参加.

谢谢......
Charith
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


您一定不了解Christian的回答.

转到Code Project中的文章.
向右向下滚动到底部.
您将看到一个可以提出问题或发表评论的区域.
这是您向作者提问的地方.
干杯.
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.


这篇关于运动检测-AForge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆