本文介绍了为什么RetrieveBgrFrame()返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My problem is that I try to use CV on a videofile (to simulate a camera) and I can't handle the frames, because RetrieveBgrFrame() doesn't return an image. Instead it gives the above error. My code is:

请告诉我是否需要其他详细信息。

Please tell me if you need additional details.

推荐答案

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

Your problem is that the field capture is null, because it is never initialized.The code should be as follows:

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

这篇关于为什么RetrieveBgrFrame()返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 04:43