【问题标题】:Capture Frame Not Video AForge C# ASP.NET捕获帧不是视频 AForge C# ASP.NET
【发布时间】:2012-10-27 15:56:35
【问题描述】:

我有以下代码,它可以非常快速地捕获视频并更新 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();
        }
    }

【问题讨论】:

    标签: c# asp.net aforge


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果您的相机不支持设置帧速率。您可以使用全局变量,并且仅在该值 = 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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-30
        • 2011-12-29
        • 1970-01-01
        • 2014-09-29
        相关资源
        最近更新 更多