从文件中捕获

时间:2015-12-27 09:19:04

标签: c# opencv capture

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

嗨,我正在尝试使用combobox和trackbar捕获视频文件。首先,我必须说我是C#的新手。所以我觉得有点卡住了。

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

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

1 个答案:

答案 0 :(得分:0)

  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#之间的代码有不同的结构。