gpt4 book ai didi

c# - 如何使用 AForge 库提取特定帧

转载 作者:行者123 更新时间:2023-11-30 22:10:20 27 4
gpt4 key购买 nike

我正在尝试从视频文件中提取特定帧。当我使用 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是我要匹配的固定框。当我播放视频文件并提取新帧时,这段代码工作正常,但我无法将新帧与特定帧进行比较。请指导我如何实现这一目标。

最佳答案

你可以看看: 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

关于c# - 如何使用 AForge 库提取特定帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20917099/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com