-1

I'm writing C# code which can display logitech usb c525 webcam to picturebox. I tried many sample codes from web with AFORGE/OpenCvSharp/avicap32.dll and no success, keep displays no image on picturebox. Webcam, C525, is working with other application like a camera app in Win10 so webcam is working, not broken.

Could you look at my code what I'm missing?

If I using default webcam on laptop, it's working well with my code

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();
        }
    }
}

Build is ok and when I run program, I can see memory increasing from diagnostics window and also I can see C525 webcam led on so actually webcam is working but couldn't display image on picturebox screen.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Louiey
  • 19
  • 1
  • 7

1 Answers1

0

Sorry for this... Now it's work here as I expected. It was due to USB hub problem. I can confirm that this code works well.

Louiey
  • 19
  • 1
  • 7