2017-07-12 7 views
0

私は特定の秒でビデオから画像を抽出しようとしています。たとえば、3秒を使用すると、ビデオファイルから3秒ごとに画像が抽出されます。emgu-cvを使用していますしかし、問題は、そのビデオからすべてのフレームを取得している。私は秒を設定する方法を理解していない。 これは私のコードです:ビデオ内の特定の秒で画像を検索

private List<Image<Bgr, Byte>> GetVideoFrames(String Filename) 
     { 
      try 
      { 
       List<Image<Bgr, Byte>> image_array = new List<Image<Bgr, Byte>>(); 
       _capture = new Capture(Filename); 


       bool Reading = true; 
       int frameNumber = 10; 
       int count = 0; 
       while (Reading) 
       { 
        Image<Bgr, Byte> frame = _capture.QueryFrame(); 
        if (frame != null) 
        { 
         image_array.Add(frame.Copy()); 
         //if(count>=frameNumber && count%frameNumber==0) 
         //{ 
          image_array[count].Save(@"D:\SVN\Video Labeling\Images\"+count+".png"); 
         //} 
         count++; 
        } 
        else 
        { 
         Reading = false; 
        } 

       } 

       return image_array; 
      } 
      catch (Exception ex) 
      { 

       throw; 
      } 
     } 

答えて

0

FFMPEGは、ビデオの操作や変換のための非常に良いです。 emgucvを使う必要はありませんが、ffmpegを使って簡単に行うことができます。 emgucvと

バージョンも

の下に提供され、あなたが次にEMGUCVで答えをしたい場合、必要なパラメータがhere

サンプルコード

string pathToVideo = @"<enter the video path here>"; 
int xSeconds = 10; 
string imageName = @"D:\SVN\Video Labeling\Images\"+count+".png"; 

Process process = new Process(); 
process.StartInfo.RedirectStandardOutput = true; 
process.StartInfo.RedirectStandardError = true; 
process.StartInfo.FileName = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) + 
        @"\bin\ffmpeg.exe"; 

process.StartInfo.Arguments = String.Format("-i {0} -vf fps=1/{1} {2}%04d.bmp",pathToVideo,xSeconds,imageName); 


process.StartInfo.UseShellExecute = false; 
process.StartInfo.CreateNoWindow = true; 
process.Start(); 
1

が設けられています。ここには

private List<Image<Bgr, Byte>> GetVideoFrames(String Filename,int secondsToSkip) 
    { 
     try 
     { 
      List<Image<Bgr, Byte>> image_array = new List<Image<Bgr, Byte>>(); 
      _capture = new Capture(Filename); 

      double fps = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS); 

      Image<Bgr, Byte> frame = null; 
      bool reading = true; 
      double framesToSkip = secondsToSkip * fps; 

      for (int count=1; reading; count++) 
      { 
       if(count%framesToSkip != 0) 
        _capture.QuerySmallFrame(); 
       else 
       { 
        frame = _capture.QueryFrame(); 
        reading = (frame != null); 
        if (reading) 
        { 
         image_array.Add(frame.Copy()); 
         image_array[count].Save(@"D:\SVN\Video Labeling\Images\" + count + ".png"); 
        } 
       } 

      } 

      return image_array; 
     } 
     catch (Exception ex) 
     { 
      throw; 
     } 
    } 
関連する問題