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