为什么 RetrieveBgrFrame() 返回空值

本文关键字:返回 空值 RetrieveBgrFrame 为什么 | 更新日期: 2023-09-27 18:33:51

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

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

http://pastebin.com/DNEVwij8

如果您需要更多详细信息,请告诉我。

为什么 RetrieveBgrFrame() 返回空值

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

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