【问题标题】:How To Extract specific Frame using AForge Library如何使用 AForge 库提取特定帧
【发布时间】:2014-01-04 04:58:39
【问题描述】:

我正在尝试从视频文件中提取特定帧。当我使用 aforge 库播放视频文件时,我有一个我想要的帧。我调用一个新帧事件,如果新帧与我的特定帧匹配,那么它会向我显示一条消息:“帧匹配”。此特定帧随机出现在视频文件中。这是我的代码:

private void Form1_Load(object sender, EventArgs e)
{
    IVideoSource videoSource = new FileVideoSource(@"e:\media\test\a.mkv");
    playerControl.VideoSource = videoSource;
    playerControl.Start( );
    videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(Video_NewFrame );
}

private void Video_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
    //Create Bitmap from frame
    Bitmap FrameData = new Bitmap(eventArgs.Frame);
    //Add to PictureBox
    pictureBox1.Image   = FrameData;
    //compare current frame to specific fram
    if (pictureBox1.Image == pictureBox2.Image)
    {
        MessageBox.Show("Frame Match");  
    }
}

pictureBox2.image 是我要匹配的固定框架。当我播放视频文件并提取新帧时,此代码运行良好,但我无法将新帧与特定帧进行比较。请指导我如何实现这一目标。

【问题讨论】:

    标签: c# video image-processing video-capture video-processing


    【解决方案1】:

    你可以看看: https://github.com/dajuric/accord-net-extensions

    var capture = new FileCapture(@"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv");
    capture.Open();
    capture.Seek(<yourFrameIndex>, SeekOrigin.Begin);
    var image = capture.ReadAs<Bgr, byte>();
    

    或者您可以使用标准的 IEnumerable,例如:

    var capture = new FileCapture(@"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv");
    capture.Open();
    var image = capture.ElementAt(<yourFrameIndex>); //will actually just cast image
    

    包括示例。

    移至:https://github.com/dajuric/dot-imaging

    【讨论】:

    • 真的很好,@dajuric!我现在正在尝试执行此操作,但我似乎无法将返回类型转换为 ImageSource 或 Bitmap。如何使用该 Image?非常感谢!!
    • 另外,我在创建 FileCapture 实例时遇到此异常:无法加载 DLL 文件“opencv_highgui248”。我该怎么办?
    【解决方案2】:

    据我所知,您的问题是您无法以这种方式将图像与图像进行比较。我想你会发现这样做的方法是建立一个直方图表,然后比较图像直方图。

    需要研究的一些相关事情是:

    how to compare two images

    image comparer class form VS 2015 unit testing

    第二个来自单元测试库,所以不确定性能(我自己还没试过)

    【讨论】:

      猜你喜欢
      • 2021-05-24
      • 2015-11-06
      • 2012-02-19
      • 2019-08-12
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多