简体   繁体   English

在EmguCV中将视频转换为List的最佳方法是什么?

[英]What is the best way to convert a video to a List in EmguCV

I want to store every frame from my video in a generic List, to process it later on. 我想将我的视频中的每一帧存储在一个通用列表中,以便稍后处理。 I have the list declared as followed: List<Image<Bgr, Byte>> Stream_to_Images = new List<Image<Bgr, Byte>>(); 我将列表声明如下: List<Image<Bgr, Byte>> Stream_to_Images = new List<Image<Bgr, Byte>>(); .

To import it I have created a timer which ticks every 33 milliseconds, in oder to get every frame. 为了导入它,我已经创建了一个计时器,每隔33毫秒计时,以获得每一帧。 The event which is triggering should import the frame to the list. 触发的事件应将帧导入列表。 Therefore I have tried the following lines: 因此我尝试了以下几行:

Either just a simple .Add() 要么只是一个简单的.Add()

Stream_to_Images.Add(_capture.QueryFrame());

Or a counter for every frame, and adressing every Position itself. 或每个框架的计数器,并对每个位置本身进行贴标。

Stream_to_Images[StreamPosition] = _capture.QueryFrame();
StreamPosition++;

Using the first, my whole list contains only one frame, not the last one but one from the very end of the video, the second option results in an ArgumentOutOfRangeException . 使用第一个,我的整个列表只包含一个帧,而不是最后一个,但是从视频的最后一个,第二个选项导致ArgumentOutOfRangeException I am running out of ideas, are there any other ways to store every frame from my video in a list? 我的想法已经不多了,有没有其他方法可以将我的视频中的每一帧存储在列表中?

** UPDATE ** ** 更新 **

I have tried to change from a List to an Array, by using this 我试图通过使用它从列表更改为数组

imageBox1.Image = _capture.QueryFrame();
image_array.Add(_capture.QueryFrame());

But still, if I try to interate the array and display the video, I only get a picture of the last frame. 但是,如果我尝试对数组进行交互并显示视频,我只会得到最后一帧的图片。

I think the issue may be with how you are adding the image to the list. 我认为问题可能在于您如何将图像添加到列表中。 Currently, it looks like it may be adding by reference, which means all the items in the list point to the same image. 目前,它看起来可能是通过引用添加,这意味着列表中的所有项目都指向同一图像。 If you force Emgu to create a copy of the frame, it should work: 如果你强制Emgu创建框架的副本,它应该工作:

imageBox1.Image = _capture.QueryFrame();
image_array.Add(new Image<Rgb, byte>(_capture.QueryFrame().Bitmap));

I'm looking more into it now, but I think this should work. 我现在正在研究它,但我认为这应该有效。 It will create a local copy, rather than relying on references. 它将创建本地副本,而不是依赖于引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM