【问题标题】:Changing Framerate & System.Threading Aforge.video C# ASP.NET更改帧率和 System.Threading Aforge.video C# ASP.NET
【发布时间】:2012-10-26 09:02:11
【问题描述】:

我有一个小项目,我从网络摄像头捕获图像并解码 qr。

以下代码捕获图像并将其存储到本地文件中,仅当它不在 while 循环中时。 system.threading 似乎使捕获的图像变黑。如果我不使用它(循环),它每秒会捕获太多图像。

那么有没有办法改变 aforge.video 的帧率,这样我就可以每 x 秒捕获一张图像而无需 while 循环?

   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;     
    }

    public void Start_OnClick(object sender, EventArgs e)
    {
        FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[inputDevices.SelectedIndex].MonikerString);
        FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
        FinalVideo.Start();
    }
    void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        int i = 0;
        while (i < 10)
        {
            Bitmap video = (Bitmap)eventArgs.Frame.Clone();
            video.Save("C:\\Users\\Wayneio\\Desktop\\image\\test" + i + ".jpg");
            i++;
            System.Threading.Thread.Sleep(5000);
        }

    }
    public void Stop_OnClick(object sender, EventArgs e)
    {
        this.FinalVideo.Stop();
    }
}

此外,我在尝试通过 asp 按钮停止捕获时收到此错误:

 Object reference not set to an instance of an object on this.FinalVideo.Stop();

试过了没有用: ((VideoCaptureDevice)FinalVideo).DesiredFrameRate = 10;

【问题讨论】:

    标签: c# asp.net frame-rate aforge


    【解决方案1】:

    在你编码开始视频之前,像这样设置帧率

     FinalVideo.DesiredFrameRate = 10;
     FinalVideo.Start();
    

    跳过您保存的帧的另一个选项是使用并非总是正确的函数 如果你有一个全局计数器值 myCounter

    进行如下模计算 ix mycounter 除以 10 等于 1

     myCounter++
     if (m(ycounter %% 10))==1) { //code to save your bitmap   }
    

    【讨论】:

    • FinalVideo.DesiredFrameRateobsolete "...Setting this property does not have any effect."
    • 您的权利,除非您使用的是旧版本。由于我的应用程序是围绕旧版本构建的,对我来说重写整个应用程序没有任何好处,只是为了支持新的 aforge 版本,因为这些版本之间发生了很多变化。
    • 这很公平 - 我们都有这样的代码 - 我只是指出,对于新的开发,它可能不是 OP 正在寻找的东西
    • 我认为他的语法也在使用其他旧方法。也许他的工作基于 sme 较旧的代码示例
    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 2020-11-06
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多