【问题标题】:Capture From File从文件中捕获
【发布时间】:2015-12-27 09:19:03
【问题描述】:
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);

【问题讨论】:

  • 你有什么问题?
  • 为了继续我的项目,所有代码都应该是正确的,我犯了错误。在 C# 中,我无法使用 Marshal,也无法使用 CV_CAP_PROP_FRAME_COUNT 获取帧数,​​它应该有所不同,但我不知道。我还需要使用 emgu cv 吗?我正在使用 opencvsharp 开发我的项目。
  • 可以打印文件名吗?也许它只是没有完整路径的文件名?
  • 我试图构建程序只是字符串字符串文件名; CvCapture cap = CvCapture.FromFile(fileName);
  • 未分配的局部变量错误我正在服用 VS2013

标签: c# opencv capture


【解决方案1】:
  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#之间的代码有不同的结构。

【讨论】:

    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多