How to get list of webcams?

Ask question on using Emgu CV with C#

How to get list of webcams?

Postby Andy » Sun Apr 08, 2012 2:49 am

I have two webcams installed on my system, but how to get the names of webcams installed on my system using emgucv?

At first when my app is started I will display the list of webcams, and then user will select which webcam he want to use!
Kindness, like a boomerang, always returns.
Andy
 
Posts: 54
Joined: Sun Sep 18, 2011 2:35 pm

Re: How to get list of webcams?

Postby masangga » Sun Apr 08, 2012 12:37 pm

masangga
 
Posts: 21
Joined: Mon Mar 26, 2012 2:42 am

Re: How to get list of webcams?

Postby Andy » Sun Apr 08, 2012 1:42 pm

But how to get names of webcams installed?
Kindness, like a boomerang, always returns.
Andy
 
Posts: 54
Joined: Sun Sep 18, 2011 2:35 pm

Re: How to get list of webcams?

Postby kerbooo » Mon Apr 09, 2012 3:57 am

Hi, you can use "DirectShowLib" dll http://sourceforge.net/projects/directshownet/files/DirectShowNET/v2.1/DirectShowLibV2-1.zip/download for listing system cams.

Usage example is below which i used in my project.

Code: Select all
....
//-> import DirectShowLib-2005.dll to your project referance
using DirectShowLib;
....


Code: Select all
....
//-> define var
private int _CameraIndex;
....


Put a ComboBox on your project form. Than rename that "ComboBoxCameraList"

Code: Select all
  //-> Create a List to store for ComboCameras
            List<KeyValuePair<int, string>> ListCamerasData = new List<KeyValuePair<int, string>>();

            //-> Find systems cameras with DirectShow.Net dll
            DsDevice[] _SystemCamereas = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            int _DeviceIndex = 0;
            foreach (DirectShowLib.DsDevice _Camera in _SystemCamereas)
            {
                ListCamerasData.Add(new KeyValuePair<int, string>(_DeviceIndex, _Camera.Name));
                _DeviceIndex++;
            }

            //-> clear the combobox
            ComboBoxCameraList.DataSource = null;
            ComboBoxCameraList.Items.Clear();

            //-> bind the combobox
            ComboBoxCameraList.DataSource = new BindingSource(ListCamerasData, null);
            ComboBoxCameraList.DisplayMember = "Value";
            ComboBoxCameraList.ValueMember = "Key";


i hope, this approach can help you.
kerbooo
 
Posts: 8
Joined: Sat Mar 31, 2012 11:46 am

Re: How to get list of webcams?

Postby Andy » Mon Apr 09, 2012 5:27 am

Ok Now I have added the code in form load().
It shows list of camera installed.
But I want webcam to be selected on click of my ok button. How to do that?
Kindness, like a boomerang, always returns.
Andy
 
Posts: 54
Joined: Sun Sep 18, 2011 2:35 pm

Re: How to get list of webcams?

Postby kerbooo » Mon Apr 09, 2012 5:50 am

You can do that with ComboBox's "SelectedIndexChanged' method like below.

Code: Select all
  private void ComboCameras_SelectedIndexChanged(object sender, EventArgs e)
        {
            //-> Get the selected item in the combobox
            KeyValuePair<int, string> SelectedItem = (KeyValuePair<int, string>)ComboBoxCameraList.SelectedItem;

            //-> Assign selected cam index to defined var
           _CameraIndex = SelectedItem.Key;
        }




If you don't want to do with ComboBox's "SelectedIndexChanged" method.
You can use a button's "_Click" method.

Code: Select all
 private void YourButton_Click(object sender, EventArgs e)
{
    //-> Get the selected item in the combobox
            KeyValuePair<int, string> SelectedItem = (KeyValuePair<int, string>)ComboBoxCameraList.SelectedItem;
  //-> Assign selected cam index to defined var
            _CameraIndex = SelectedItem.Key;
 }
       


After that, you can use "_CameraIndex" var with new capture object.
Code: Select all
_Capture = new Capture(_CameraIndex);
kerbooo
 
Posts: 8
Joined: Sat Mar 31, 2012 11:46 am

Re: How to get list of webcams?

Postby Andy » Mon Apr 09, 2012 7:20 am

Thankyou Kerbooo :D :mrgreen:
Kindness, like a boomerang, always returns.
Andy
 
Posts: 54
Joined: Sun Sep 18, 2011 2:35 pm

Re: How to get list of webcams?

Postby kerbooo » Mon Apr 09, 2012 8:07 am

You're welcome :)
kerbooo
 
Posts: 8
Joined: Sat Mar 31, 2012 11:46 am

Re: How to get list of webcams?

Postby olugbone » Mon Apr 09, 2012 3:33 pm

I am trying to get a higher resolution from my webcams. I can only get a default of 640X480.

Here is my code:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
namespace Camera_Capture
{
 public partial class Form1 : Form
 {
 //declaring global variables
 private Capture capture1,capture2; //takes images from camera as image frames
 private bool captureInProgress; // checks if capture is executing

 public Form1()
 {
 InitializeComponent();
 }
 private void Form1_Load(object sender, EventArgs e)
 {
 capture1 = new Capture(0);
 capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1280);
 capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 720);

 capture2 = new Capture(1);
 this.capture2.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1024);



 }

 private void button1_Click(object sender, EventArgs e)
 {
 #region if capture is not created, create it now
 if (capture1 == null)
 {
 try
 {
 capture1 = new Capture(0);
 capture2 = new Capture(1);
 }
 catch (NullReferenceException excpt)
 {
 MessageBox.Show(excpt.Message);
 }
 }
 #endregion

 if (capture1 != null)
 {
 if (captureInProgress)
 { //if camera is getting frames then stop the capture and set button Text
 // "Start" for resuming capture
 button1.Text = "Start!"; //
 Application.Idle -= ProcessFrame;
 }
 else
 {
 //if camera is NOT getting frames then start the capture and set button
 // Text to "Stop" for pausing capture
 button1.Text = "Stop";
 Application.Idle += ProcessFrame;
 }

 captureInProgress = !captureInProgress;
 }
 }
 private void ProcessFrame(object sender, EventArgs arg)
 {
 Image<Bgr, Byte> ImageFrame = capture1.QueryFrame();
 camimageBox.Image = ImageFrame; //line 2
 Image<Bgr, Byte> ImageFrame2 = capture2.QueryFrame();
 imageBox1.Image = ImageFrame2;
 }

 private void ReleaseData()
 {
 if (capture1 != null)
 capture1.Dispose();
 }
 }
}

Thanks in advance
olugbone
 
Posts: 3
Joined: Mon Apr 09, 2012 3:24 pm

Re: How to get list of webcams?

Postby Andy » Tue Apr 10, 2012 8:15 am

How to change the webcam in runtime?

Means currently my application is running on webcam A, now I will select Webcam B. Immediately my application should switch to Webcam B.
Kindness, like a boomerang, always returns.
Andy
 
Posts: 54
Joined: Sun Sep 18, 2011 2:35 pm

Next

Return to C# Help

Who is online

Users browsing this forum: Google [Bot] and 6 guests