使用emgucv库进行人脸检测. [英] face detection using emgucv library.

查看:199
本文介绍了使用emgucv库进行人脸检测.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用emgu cv开放库中的haar检测器进行人脸检测.
使用语言C#.

I am doing face detection using haar detector from emgu cv open library.
Using the language C#.

public Form1()
{
    InitializeComponent();
    try
    {
        haar = new HaarCascade("C:\\Program Files\\emgucv2.1.0.793\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml");
        
        capture = new Capture(0);
    }
    catch
    {
    }
}

private void timer1_Tick(object sender, EventArgs e)
{
    {
        Image<bgr,> image = capture.QueryFrame();
    Bitmap original = image.ToBitmap(pictureBox1.Width,pictureBox1.Height);



它在运行时给出错误.
它运行时不会在图片框中显示图像,并且在行中给出空引用异常:



It is giving error at run time.
It does not show image in the picture box when it runs and gives null reference exception in line:

Image<bgr,> image = capture.QueryFrame();


我已经使用断点来检测错误,它会转到Haar行,但不会进入捕获行capture = new capture(0).

谁能告诉我为什么在运行时无法在图片框中捕获图像的错误?
我在Windows XP和Windows 7中都使用emgucv库尝试了此操作.


I have used breakpoints to detect errors, it is going to the Haar line but it not entering in capture line capture= new capture(0).

Can anyone tell me the error why image is not been captured in picture box at run time?
I tried this using emgucv liberary in win XP as well as window 7.

推荐答案

catch块总是错误的.
及时发现错误,否则您将永远不知道真正的问题.

干杯
Empty catch blocks are always wrong.
Catch the error as it happens, otherwise you''ll never know the real problem.

Cheers


我对您在面部检测中使用的库一无所知,但我认为您的问题出在计时器上.在代码capture = new Capture(0)行之后分配滴答事件处理程序,因为滴答可能在初始化捕获之前运行
I don''t know anything about the library you are using on face detection, but I think your problem is with the timer. Asign the tick event handler after the line of code capture = new Capture(0), because probably tick runs before you initialize capture
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);


并删除上面的线形设计器...


在设计器Enabled = false
中设置 并在捕获=新捕获后的代码中将其设置为enabled = true


and remove the above line form designer...

or
set in designer Enabled = false
and in code after capture = new capture set it to enabled = true


这是一个有根据的猜测(假设我还没有遇到EMGUCV库),但是根据您的意思:
我已经使用断点来检测错误,它正在进入Haar行,但未进入捕获行capture = new capture(0)."
似乎创建新的HaarCascade不会立即返回,因此您没有达到捕获实例的创建.

由于您正在使用计时器,因此我的处理方式是:
1)从表单构造函数中删除捕获和级联创建.<​​br/> 2)在第一个计时器刻度上,暂停计时器,显示请稍候"消息并创建级联.级联完成后,请重新启用计时器,并删除消息.然后创建捕获实例并继续.

我无法检查级联会发生什么,因为EMGU CV网站没有响应,但是无论如何它应该有示例.看看他们在做什么.
This is an educated guess (given I have not met the EMGUCV library), but from what you say :
"I have used breakpoints to detect errors, it is going to the Haar line but it not entering in capture line capture= new capture(0)."
It would seem that creating a new HaarCascade does not return immediately, so you are not reaching the capture instance creation.

Since you are working in a timer, the way I would handle it is:
1) Remove the capture and cascade creation from the form constructor.
2) On the first timer tick, suspend the timer, display a "please wait" message and create the cascade. Re-enable the timer when the cascade is complete, and remove the message. Then create the capture instance and continue.

I can''t check what should happen with teh cascade, because the EMGU CV website is not responding, but it should have samples there anyway. Have a look and see what they do.


这篇关于使用emgucv库进行人脸检测.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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