簡體   English   中英

捕獲幀而不是視頻 AForge C# ASP.NET

[英]Capture Frame Not Video AForge C# ASP.NET

我有以下代碼,它可以非常快速地捕獲視頻並更新 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();
        }
    }

首先將 videoCaptureDevice.desiredFrameRate 設置為 1。這應該使 NewFrameEventHandler 每秒運行一次。 然后讓 NewFrameEventHandler 在 num 之后做一些事情。 您想要的秒數(跳過或幀)。

如果您的相機不支持設置幀速率。 您可以使用全局變量,並且僅在該值 = 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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM