0

I'm trying to generate all frames of my selected video in a listview or imagelist one by one, is it possible without saving first the frames as images?

Here is my sample code.

string name = @"E:\Videos\Anime\eyeshield\Eyeshield 21 Episode 1.flv";
VideoCapture _capture;
_capture = new VideoCapture(name);

List<Image<Bgr, Byte>> image_array = new List<Image<Bgr, Byte>>();

double totalFrames =_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
double fps = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
double frameNumber = 0.0;
bool Reading = true;

 while (Reading)
        {
            _capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, frameNumber);
            Image<Bgr, Byte> frame = _capture.QueryFrame().ToImage<Bgr, Byte>();
            if (frame != null)
            {
                //Display the image_array frame in listView1 or imageList1 one by one
            }
            else
            {
                Reading = false;
            }

            frameNumber++;
        }

Here is some case that maybe similar to my target output but the syntax QueryFrame().Copy is not working.

Breakpoint
  • 28
  • 6

1 Answers1

0

Since still no one answer this issue, I already solved this and I will post the code for the future reference. The frame will be store to an image list as bitmap and show to listview.

double TotalFrame;
int FrameNo = 1;
bool IsReadingFrame;
VideoCapture capture;

System.Windows.Forms.ImageList myImageList = new ImageList();

public Form1()
{
  InitializeComponent();
  listViewFile.LargeImageList = myImageListLarge;

  if (capture==null)
  {
    return;
  }
  IsReadingFrame = true;
  ReadAllFrames();
}

private async void ReadAllFrames()
{
  Mat m = new Mat();
  while (IsReadingFrame == true && FrameNo <= TotalFrame)
  {
    listViewFile.Items.Add(new ListViewItem { ImageIndex = FrameNo, Text = 
    FrameNo.ToString() });
    capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, FrameNo);
    capture.Read(m);
    pictureBox1.Image = m.Bitmap;

    myImageList.ImageSize = new Size(80, 80);
    myImageList.Images.Add(m.Bitmap);

    listViewFile.LargeImageList = myImageList;
  }
}
Breakpoint
  • 28
  • 6