从文件捕获

本文关键字:文件 | 更新日期: 2023-09-27 18:28:05

else if (comboBox1.Text == "Capture From File")
{   
     OpenFileDialog openFile = new OpenFileDialog();
     openFile.Filter = "AVI files (*.avi)|*.txt|All files (*.*)|*.*";
     openFile.FilterIndex = 2;
     openFile.RestoreDirectory = true;
     openFile.FileName ="";
     if ( openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK )
     {      
         char fileName = (char*)Marshal.StringToHGlobalAnsi(openFile.FileName).ToPointer();                 
         CvCapture  cap = CvCapture.FromFile(fileName);
         trackBar1.Minimum = 0;
         trackBar1.Maximum = (int)Cv.GetCaptureProperty(cap, CV_CAP_PROP_FRAME_COUNT);
         btnStart.Text = "Stop";
         timer1.Start();
     }              
}

嗨,我正在尝试使用组合框和跟踪栏捕获视频文件。首先,我不得不说我是C#新手。所以我觉得有点卡住了。

首先,在我开始在 C# 上开发程序后,我在C++中使用这些代码。我在这里收到错误Marshal.StringToHGlobalAnsi,虽然我想尝试在这里获取跟踪栏的帧数

trackBar1.Maximum = (int)Cv.GetCaptureProperty(cap, CV_CAP_PROP_FRAME_COUNT);

从文件捕获

  if (comboBox1.Text == "Capture From File")
        {
            if (btnStart.Text.Equals("Start"))
            {
                OpenFileDialog openFile = new OpenFileDialog();
                openFile.Filter = "AVI files (*.avi)|*.txt|All files (*.*)|*.*";
                openFile.FilterIndex = 2;
                openFile.RestoreDirectory = true;
                openFile.FileName = "";
                if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ca = new CvCapture(openFile.FileName);
                    trackBar1.Minimum = 0;
                    trackBar1.Maximum = (int)ca.GetCaptureProperty(CaptureProperty.FrameCount);
                    btnStart.Text = "Stop";
                    timer1.Start();
                }
            }

我已经解决了我的问题,只是那个时候我不知道 c++ 和 c# 之间具有不同结构的代码。