捕获帧不是视频AForge C#ASP.NET

时间:2012-10-27 15:56:36

标签: c# asp.net aforge

我有以下代码,可以非常快速地捕获视频并更新jpg。

我需要的是将其更改为每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();
        }
    }

2 个答案:

答案 0 :(得分:0)

首先将videoCaptureDevice.desiredFrameRate设置为1.这应该使NewFrameEventHandler每秒运行一次。 然后让NewFrameEventHandler在num之后执行某些操作。你想要的秒数(跳过或帧数)。

答案 1 :(得分: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