如何初始化 AForge 网络摄像头

How initialize AForge webcam(如何初始化 AForge 网络摄像头)
本文介绍了如何初始化 AForge 网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我尝试使用 Aforge 编写一小段代码来捕获帧我参考了 Aforge.dll 和 AForge.Video.DirectShow.dll代码如下,但我做错了什么.警告我得到名称 videoDevices 在当前上下文中不存在.我认为这与我尝试创建该变量的位置有关,但我不确定在哪里放置按钮的代码以使其初始化.错误在 Visual Studio 中也显示为对象videoDevices"下的红线

I try to write a small peace of code to capture a frame using Aforge I made a reference to Aforge.dll and AForge.Video.DirectShow.dll The code is below, but i am doing something wrong. The Warning i get "the name videoDevices does not exist in the current context. I think it has to do about where i try to create that variable but i'm not exactly sure as where to place that code of the button to get it initialized. The error is displayed in visual studio also as a redline under the object "videoDevices"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge;
using AForge.Video.DirectShow;

namespace AforgeCam
 {
   public partial class Form1 : Form
 {
    public Form1()
    {
        InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {

        videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

        if (videoDevices.Count == 0)
            throw new ApplicationException();

        foreach (FilterInfo device in videoDevices)
        {
    VideoCaptureDevice videoSource = new    VideoCaptureDevice(device.MonikerString);
            videoSource.DesiredFrameSize = new Size(320, 240);
            videoSource.DesiredFrameRate = 15;
            videoSourcePlayer1.VideoSource = videoSource;
            videoSourcePlayer1.Start();
        }

    }
    }
}

推荐答案

根据要求,解决方案如下,代码有效,我将针对我对此提出的另一个问题提出一个新问题.该代码需要一个下拉框、2个按钮和一个图片框

As requested the solution is below , the code works, i will raise a new question for another question i have about it. the code requires a dropdown box, 2 buttons and a picturebox

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AforgeCam;
using AForge.Video;
using AForge.Video.DirectShow;

namespace AforgeCam
{
public partial class Form1 : Form
{
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;

public Form1() // init
{
    InitializeComponent();
    {
        VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
        {
            comboBox1.Items.Add(VideoCaptureDevice.Name);
        }
        comboBox1.SelectedIndex = 0;
    }
}

private void button1_Click(object sender, EventArgs e)
{
    FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
    FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
    FinalVideo.Start();
}

void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    Bitmap video = (Bitmap)eventArgs.Frame.Clone();
    pictureBox1.Image = video;

}

private void button2_Click(object sender, EventArgs e)
{
    FinalVideo.Stop();
}
}

这篇关于如何初始化 AForge 网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to MOQ an Indexed property(如何最小起订量索引属性)
Mocking generic methods in Moq without specifying T(在 Moq 中模拟泛型方法而不指定 T)
How Moles Isolation framework is implemented?(Moles Isolation 框架是如何实现的?)
Difference between Dependency Injection and Mocking Framework (Ninject vs RhinoMocks or Moq)(依赖注入和模拟框架之间的区别(Ninject vs RhinoMocks 或 Moq))
How to mock Controller.User using moq(如何使用 moq 模拟 Controller.User)
How do I mock a class without an interface?(如何模拟没有接口的类?)