繁体   English   中英

如何在图片框上显示网络摄像头图像

[英]How can I display webcam image on picturebox

我正在编写可以将罗技 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 网络摄像头亮起,因此网络摄像头实际上正在工作,但无法在图片框屏幕上显示图像。

对此很抱歉......现在它按我的预期工作。 这是由于USB集线器问题。 我可以确认此代码运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM