c# - 网络摄像头捕获 c# Logitech
问题描述
我制作了这个程序来从我的 Logitech HD Pro WebCam c920 拍摄图像。
该程序实际上适用于集成摄像头,但是当我想使用我的罗技网络摄像头时,我什么都没有……(没有图像,没有错误)。
我想知道是否有人有同样的问题或帮助我解决它...
我的程序仅用于使用 aForge 在 c# 上从我的 WebCam 罗技拍摄照片。
我有这个代码:
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;
using Accord;
using AForge.Video;
using AForge.Video.DirectShow;
namespace WindowsFormsApp1
{
public partial class Webcam : Form
{
public Webcam()
{
InitializeComponent();
}
FilterInfoCollection filterInfoCollection;
VideoCaptureDevice videoCaptureDevice;
private void btnStart_Click(object sender, EventArgs e)
{
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[cboCamera.SelectedIndex].MonikerString);
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame;
videoCaptureDevice.Start();
}
private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pic.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void Webcam_Load(object sender, EventArgs e)
{
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach(FilterInfo filterinfo in filterInfoCollection)
{
cboCamera.Items.Add(filterinfo.Name);
cboCamera.SelectedIndex = 0;
videoCaptureDevice = new VideoCaptureDevice();
}
}
private void Webcam_FormClosing(object sender, FormClosingEventArgs e)
{
if (videoCaptureDevice.IsRunning == true)
videoCaptureDevice.SignalToStop();
}
btnstart 是按钮,cboCamera 是 Combobox,而 pic 是图片框。
解决方案
我有一个非常相似的问题。虽然我不知道为什么会发生这种情况,但我已经测试了以下解决方案:
- 使用Media Capture API - 似乎适用于所有网络摄像头,但我遇到了很多稳定性问题。
- 使用这个Versatile WebCam C# library - 似乎工作正常。
我没有测试过Emgu /OpenCV,但这是另一种选择。
推荐阅读
- sql - 将多个 CSV 文件插入到一个 oracle 数据库中
- java - 为什么我的 android 程序在 4.4.3 版本上运行良好但在 10.0 上运行不正常
- json - Helm3 - 将 json 文件读入 configmap 会产生一个字符串?
- python - KeyError:'未找到蜘蛛:蜘蛛'
- windows-installer - 安装程序升级将错误的文件日期应用于需要重新启动的保留文件
- java - 从 Scala 代码调用 java 泛型 Java 方法时类型不匹配
- git - `git branch --contains` 不显示发起提交的分支
- reactjs - 打印带有数组值的卡片
- python - 保存 sklearn 管道的中间结果
- swift - SwiftUI - 导航链接 - 第二次不起作用