简体   繁体   中英

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>>(); .

To import it I have created a timer which ticks every 33 milliseconds, in oder to get every frame. The event which is triggering should import the frame to the list. Therefore I have tried the following lines:

Either just a simple .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 . 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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