[英]How to Make Camera ON / OFF with PictureBox
IDE:Visual Studio 2010 Express
库:Emgu CV 2.2级别:初学者
单击PictureBox时,我已打开Camera,反之亦然,但它给出了错误消息:
Object reference not set to an instance of an object
这里是事件处理程序:
private void pictureBoxCapture_Click(object sender, EventArgs e)
{
try
{
if (Clicked == true) //i dont know how to make it right
{
Application.Idle -= ProcessFrame;
}
else
{
Application.Idle += ProcessFrame;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
致电:
private void ProcessFrame(object sender, EventArgs e)
{
//Cap = new Emgu.CV.Capture();
ImageFrame = Cap.QueryFrame();
pictureBoxCapture.Image = ImageFrame.ToBitmap();
}
如何设置其他可能的参数,有什么建议?
创建一个类级别的布尔变量,然后在您的PictureBox的click事件中切换它。
public partial class Form1 : Form
{
bool Clicked; //Create this Class level variable to be used in your handler
public Form1()
{
InitializeComponent();
}
private void pictureBoxCapture_Click(object sender, EventArgs e)
{
Clicked =! Clicked; //Toggle your Boolean here
try
{
if (Clicked)
{
Application.Idle -= ProcessFrame;
FaceDetect();
}
else
{
Application.Idle += ProcessFrame;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
我希望您的错误不是由Picturebox click事件引发,而是由ProcessFrame()
事件引发。 在删除Application.Idle -= ProcessFrame;
之后,它将具有触发一次的习惯Application.Idle -= ProcessFrame;
但是在event参数中没有可以使用的图像。 而是使用以下代码作为您的ProcessFrame()
事件:
private void ProcessFrame(object sender, EventArgs e)
{
//Cap = new Emgu.CV.Capture();
ImageFrame = Cap.QueryFrame();
//Look for image content if null do nothing
if(ImageFrame != null)
{
pictureBoxCapture.Image = ImageFrame.ToBitmap();
//do any other operations on the image
}
}
干杯,
克里斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.