0

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

我需要将其更改为每 x seconds 捕获一帧,以便我可以对其执行其他操作,例如解码条形码:

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();
        }
    }
4

2 回答 2

0

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

于 2012-11-05T10:21:27.433 回答
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 的值:如果已完成,请将其启用为 true,并在运行时将其设置为 false。

于 2012-11-28T23:19:57.243 回答