المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Help with PictureBox.image updating from Webcam capture



C# Programming
01-17-2010, 06:50 PM
Hi ive just started using emguCV the .net implement of openCV

Im very new to c# and coding in general so i decided to do some Video analytics instead of the usual "Hello World" just to break me in.

I have a picture box on my form which shows the camera output

im just after a bit of advice on this bit of code in my project. I cant understand why the code below works and ******* the image fine, yet the code below the code below doesnt, even though in my head it should work fine


private void Form1_Load(object sender, EventArgs e)
{

Capture capture = new Capture(); //create a camera captue
Application.Idle += new EventHandler(delegate(object sender1, EventArgs ef)
{ //run this until application closed
pictureBox1.Image = capture.QueryFrame().ToBitmap(); //draw the image obtained from camera frame
});


}


and my revised version of it doesnt work see below


private void Form1_Load(object sender, EventArgs e)
{

Capture capture = new Capture(); //create a camera captue
while (true)
{
pictureBox1.Image = capture.QueryFrame().ToBitmap(); //draw the image obtained from camera frame
}



}

the first bit of code is pretty much straight off a tut and it works fine but I dont understand what its doing when it does this
Application.Idle += new EventHandler(delegate(object sender1, EventArgs ef)


but if i dont put pictureBox1.Image = capture.QueryFrame().ToBitmap() in a loop it works but obviosly its just a static image. so i thought if I loop it it would just keep *******ing as fast as it can get a frame from the capture.

If anyonce can help me or even understand what im on about it would be much apreciated.