c#中的EmguCV视频阅读

时间:2018-05-24 04:47:40

标签: c# emgucv

我正在开发一个项目,我需要从opnefile对话加载视频文件,但我不明白该怎么做。加载视频后,我还想停止或暂停视频以进行进一步处理。我正在使用EmguCV 3.0版本。

我的代码在这里。

OpenFileDialog ofd1 = new OpenFileDialog();
            ofd1.Filter = "All Videos Files |*.dat; *.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm";
            ofd1.InitialDirectory = @"C:\";
            ofd1.Title = "Please select a video file.";
            if (ofd1.ShowDialog() == DialogResult.OK)
            {
                vCapture = new Capture(ofd1.FileName.ToString());
                Image<Bgr, byte> img = vCapture.QueryFrame();
            }

下一步如何收集帧流。

1 个答案:

答案 0 :(得分:0)

从EmguCV文档中查看示例代码: http://www.emgu.com/wiki/index.php/Camera_Capture_in_7_lines_of_code

using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using System.Drawing;
using System.Windows.Forms;
...

ImageViewer viewer = new ImageViewer(); //create an image viewer
Capture capture = new Capture(); //create a camera captue
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{  //run this until application closed (close button click on image viewer)
   viewer.Image = capture.QueryFrame(); //draw the image obtained from camera
});
viewer.ShowDialog(); //show the image viewer

这会使您的代码类似于以下内容:

Image<Bgr, byte> img;
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Filter = "All Videos Files |*.dat; *.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm";
ofd1.InitialDirectory = @"C:\";
ofd1.Title = "Please select a video file.";
if (ofd1.ShowDialog() == DialogResult.OK)
{
    vCapture = new Capture(ofd1.FileName.ToString());
    Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
    {            
        img = vCapture.QueryFrame();
    }
}
vCapture.Start(); // play
vCapture.Pause(); // pause

然后,您想将img传递给您用来观看视频的任何内容。