首页 > 解决方案 > 网络摄像头捕获 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 是图片框。

标签: c#webcam-capturelogitech

解决方案


我有一个非常相似的问题。虽然我不知道为什么会发生这种情况,但我已经测试了以下解决方案:

  1. 使用Media Capture API - 似乎适用于所有网络摄像头,但我遇到了很多稳定性问题。
  2. 使用这个Versatile WebCam C# library - 似乎工作正常。

我没有测试过Emgu /OpenCV,但这是另一种选择。


推荐阅读