我正在编写可以将 logitech usb c525 网络摄像头显示到图片框的 C# 代码。我使用 AFORGE/OpenCvSharp/avicap32.dll 尝试了许多来自网络的示例代码,但没有成功,保持在图片框上不显示图像。网络摄像头 C525 正在与其他应用程序(如 Win10 中的相机应用程序)一起使用,因此网络摄像头可以正常工作,而不是损坏。
你能看看我的代码我缺少什么吗?
如果我在笔记本电脑上使用默认网络摄像头,它与我的代码配合得很好
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
namespace LogitechWebCam
{
public partial class Form1 : Form
{
//Create webcam object
VideoCaptureDevice videoSource;
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
public void AForgeLoadDevice()
{
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
}
comboBox1.SelectedIndex = 0;
}
public void AForgeOpen()
{
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
public void AForgeClose()
{
FinalVideo.Stop();
}
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = video;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LogitechWebCam
{
public partial class Form1 : Form
{
LogiWebCam webCam;
WebCamera wc;
public Form1()
{
InitializeComponent();
}
// start cam
private void Button1_Click(object sender, EventArgs e)
{
AForgeOpen();
}
// stop cam
private void Button2_Click(object sender, EventArgs e)
{
AForgeClose();
}
// load cam
private void Button3_Click(object sender, EventArgs e)
{
AForgeLoadDevice();
}
}
}
构建没问题,当我运行程序时,我可以从诊断窗口看到内存增加,而且我可以看到 C525 网络摄像头亮着,所以实际上网络摄像头正在工作,但无法在图片框屏幕上显示图像。