为什么RetrieveBgrFrame()返回null?

时间:2013-10-04 13:21:30

标签: c# emgucv

  

对象引用未设置为对象的实例

我的问题是我尝试在视频文件上使用CV(模拟相机)而我无法处理帧,因为RetrieveBgrFrame()不会返回图像。相反,它给出了上述错误。我的代码是:

http://pastebin.com/DNEVwij8

如果您需要其他详细信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

您的问题是字段捕获为空,因为它从未初始化。 代码应如下:

public partial class Form1 : Form
    {
        private Image<Bgr, Byte> imgStat = null;
        private Capture capture = null;
        private bool _captureInProgress = false;
     //   private bool captureInProgress;

        public Form1()
        {
            InitializeComponent();
            imgStat = null;
         }

        public string selectFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            String s = ofd.FileName.Normalize();
            return s;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.capture = new Capture(selectFile());                    
            capture.ImageGrabbed += ProcessFrame;
            capture.Start();
        }

        private void ProcessFrame(object sender, EventArgs e)
        {
            try
            {
                //capture.Grab(); //doesnt help
               // Image<Bgr, byte> beeldje = capture.QueryFrame(); //doesnt work as well
                Image<Bgr, byte> beeldje = capture.RetrieveBgrFrame();

                    DisplayImage(beeldje.ToBitmap());
            }
            catch (Exception er)
            {
               Console.WriteLine(er.Message);
            }
        }

         private delegate void DisplayImageDelegate(Bitmap Image);
         private void DisplayImage(Bitmap Image)
         {
             if (pictureBox1.InvokeRequired)
             {
                 try
                 {
                     DisplayImageDelegate DI = new DisplayImageDelegate(DisplayImage);
                     this.BeginInvoke(DI, new object[] {Image});
                 }
                 catch (Exception ex)
                 {
                 }
             }
             else
             {
                 pictureBox1.Image = Image;
             }
         }
    }
}