魂断冥殇 2016-04-21 14:48 采纳率: 0%
浏览 2441

emgucv Caputre类在打开摄像头的情况下,关闭子窗口,会产生中断错误

这是子窗口关闭时,调用的代码


        private void VideoWnd_FormClosing(object sender, FormClosingEventArgs e)
        {
            capture.Pause();
            capture.Stop();
           for(int i=0;i<999999999;i++)
            {
                if (capture._grabState == Emgu.CV.Capture.GrabState.Stopped)
                    capture.Dispose();
            }

        }

修改Capture类的结构体,查看_grabState字段始终未stopping状态

下面为Capture类中线程运行代码

 private void Run()
        {
            try
            {
                while (_grabState == GrabState.Running || _grabState == GrabState.Pause)
                {
                    if (_grabState == GrabState.Pause)
                    {
                        _pauseEvent.WaitOne();
                    }
                    else if (IntPtr.Zero.Equals(_ptr) || !Grab())    
                    {
                        //capture has been released, or
                        //no more frames to grab, this is the end of the stream. 
                        //We should stop.
                        _grabState = GrabState.Stopping;
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Capture error", e);
            }
            finally
            {
                _grabState = GrabState.Stopped;
            }
        }

在子窗口中添加按钮,关闭摄像头能够正常工作。
在摄像头打开的情况下,直接点击关闭按钮,无论怎样都会产生catch错误,
错误为:引用已经释放的对象,ImageBox

1.理论上不是我在VideoWnd_FormClosing事件中调用了capture.stop()方法,线程不就应该调用finally中的代码么,但是直到for循环结束,线程都没有调用。不知道为什么

  • 写回答

1条回答

  • devmiao 2016-04-21 14:49
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型