0

你调用的对象是空的

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

http://pastebin.com/DNEVwij8

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

4

1 回答 1

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;
             }
         }
    }
}
于 2013-10-04T13:25:02.370 回答