2012-10-27 63 views
0

我有以下代码,它捕获视频并更新jpg速度非常快。捕获帧不是视频AForge C#ASP.NET

我需要做的是改变这捕捉每x秒一帧,这样我可以做其他的东西给它,就像解码条码:

using AForge.Video; 
using AForge.Video.DirectShow; 

namespace BAMSystem 
{ 
public partial class WebForm1 : System.Web.UI.Page 
{ 
    public int FrameRate { get; set; } 

    private FilterInfoCollection VideoCaptureDevices; 
    private VideoCaptureDevice FinalVideo; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     inputDevices.Items.Clear(); 

     VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); 
     foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices) 
     { 
      inputDevices.Items.Add(VideoCaptureDevice.Name); 
     } 
     inputDevices.SelectedIndex = 0; 

     FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[inputDevices.SelectedIndex].MonikerString); 
     FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); 

    } 

    public void Start_OnClick(object sender, EventArgs e) 
    { 
       FinalVideo.Start(); 
    } 

    void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) 
    { 
       Bitmap video = (Bitmap)eventArgs.Frame.Clone(); 
       video.Save("C:\\Users\\Wayneio\\Desktop\\image\\live.jpg"); 
    } 
    public void Stop_OnClick(object sender, EventArgs e) 
    { 
     if (FinalVideo.IsRunning) 
     { 
      FinalVideo.SignalToStop(); 
      FinalVideo.Stop(); 
     } 
    } 

回答

0

首先设置videoCaptureDevice.desiredFrameRate这应该使NewFrameEventHandler每秒运行一次。 然后让NewFrameEventHandler在num之后做一些事情。秒(跳过或帧)你想要的。

0

如果您的相机不支持设置帧速率 您可能会使用全局变量,并且只有在该值= true时才会执行 ,您可以通过Visual Studio中的简单定时器事件来执行此操作。

void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) 
    { if(mytimedevent) { 
        Bitmap video = (Bitmap)eventArgs.Frame.Clone(); 
        video.Save("C:\\Users\\Wayneio\\Desktop\\image\\live.jpg"); 
        } 
    mytimedevent!=mytimedevent // or set it simply to false. 
    } 

您也可以更改mytimedevent的valeu根据您的其他计算如果那是完成了它能够为true,并且运行时,它设置为false