2017-07-13 154 views
1

我想制作面部识别系统。现在,我试图运行相机,但是我很难进入相机。这里是我的代码:使用Emgu CV运行相机CV

public partial class Camera : Form 
{ 
    private Capture capture; 
    private HaarCascade haarCascade; 
    Timer timer; 

    public Camera() 
    { 
     InitializeComponent(); 
    } 

    private void pictureBox1_Click(object sender, EventArgs e) 
    { 
     capture = new Capture(); 
     haarCascade = new HaarCascade(@"haarcascade_frontalface_alt_tree.xml"); 
     timer = new Timer(); 
     timer.Tick += new EventHandler(timer1_Tick); 
     timer.Interval = new TimeSpan(0, 0, 0, 0, 1); 
     timer.Start(); 
    }   
} 

这是在timer.Interval = new TimeSpan(0, 0, 0, 0, 1);的错误。

以下是错误:

Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'System.TimeSpan' to 'int' Attendance_Marking_System c:\users\redpranger\documents\visual studio 2017\Projects\Attendance_Marking_System\Attendance_Marking_System\Camera.cs 34 Active

回答

2

Timer.Interval PropertyDouble类型,而不是一个Timespan的属性。

这里的属性的定义:

Gets or sets the interval, expressed in milliseconds, at which to raise the Elapsed event.

设置间隔为1秒(1000毫秒),设定这样的:

timer.Interval = 1000; 

或者在你的榜样,在1毫秒:

timer.Interval = 1; 
1
timer.Interval = new TimeSpan(0, 0, 0, 0, 1).TotalMilliseconds; 

或者你可以尝试

timer.Interval = 1; // 1ms 

你不需要刷新相机各1毫秒我不认为你的相机有那么多的FPS 所以30ms的将是你的情况 精做尝试

timer.Interval = 30; // for 30 ms 
+0

尽管您的答案在技术上是正确的,但我没有看到使用创建结构来获得毫秒。 – Abbas

+1

你说得对,实际上他不需要使用TimeSpan。 我只是写了它,让他明白,如果他想给这个间隔的值,他需要使用TotalMiliseconds属性来转换它 – Esperadoce

0

答案很简单, 所有你需要做的就是

设置间隔为1秒(1000毫秒),设定这样的:

timer.Interval = 1000;