c# - 如何使用 PictureBox 打开/关闭相机

标签 c# algorithm emgucv

IDE:Visual Studio 2010 Express
库:Emgu CV 2.2 级别:初学者

我在单击 PictureBox 时打开了相机,反之亦然,但它给出了错误:

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();
}

如何设置 if else 参数,有什么建议吗?

最佳答案

创建一个类级别的 bool 变量,然后在 PictureBox 的点击事件中切换它。

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);
        }
    }
}

关于c# - 如何使用 PictureBox 打开/关闭相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22367162/

相关文章:

c# - 如何在emgu-cv C#中将 mask 设置为GrabCut方法?

c# - 匹配图像并使用 SURF 确定最佳匹配

c# - Azure Webjob失败退出代码-1073740940

algorithm - 有趣的排序问题

c# - .net 集合内存优化 - 这种方法有效吗?

Java替换字符串中的一个字符

algorithm - 时间复杂度递归关系

c# - emguCV 3.1 - 人脸检测

c# - WCF中获取回调 channel 的IP地址

c# - C# Windows 窗体鼠标事件问题中的自定义控件