我正在尝试从WPF / C#中的一个应用程序中捕获网络摄像头的图像
1)我尝试了WIA,但我发现错误0x80210015,我已经读过,当没有可用的WIA设备时会发生此错误。我在windows vista / 7中看到WPD使用的是WIA,但是当我尝试一个简单的例子时
PortableDeviceManager deviceManager = new PortableDeviceManager();
deviceManager.RefreshDeviceList();
uint numberOfDevices = 1;
deviceManager.GetDevices(null, ref numberOfDevices);
if (numberOfDevices == 0)
{
Console.WriteLine("No device");
}
else
{
string[] deviceIds = new string[numberOfDevices];
deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices);
Console.WriteLine(deviceIds);
}
Console.Read();
我无法检测设备。
2)我使用http://easywebcam.codeplex.com/作品,但随机出现错误“捕获视频图像时发生错误。视频捕获......”我需要始终选择设备,我需要执行网络摄像头.start()几次(2或3)为该相机工作。
我有两个网络摄像头
答案 0 :(得分:-1)
这里是一个简单的拍照类节目
Image<Bgr, Byte> img;
private Capture capture;
private bool captureInProgress;
private void gumb_kamera_Click(object sender, EventArgs e)
{
}
private void processFunction(object sender, EventArgs e)
{
img = capture.QueryFrame();
// imageBox1.Image = img;
}
private void Form1_Load(object sender, EventArgs e)
{
if (capture == null)
{
try
{
capture = new Capture(0);
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
if (capture != null)
{
if (captureInProgress)
{
Application.Idle -= processFunction;
}
else
{
Application.Idle += processFunction;
}
captureInProgress = !captureInProgress;
}
}
private void button1_Click(object sender, EventArgs e)
{
imageBox1.Image = img;
}