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!
How to get list of webcams?
How to get list of webcams?
Kindness, like a boomerang, always returns.
Re: How to get list of webcams?
But how to get names of webcams installed?
Kindness, like a boomerang, always returns.
Re: How to get list of webcams?
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.
Put a ComboBox on your project form. Than rename that "ComboBoxCameraList"
i hope, this approach can help you.
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.
Re: How to get list of webcams?
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?
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.
Re: How to get list of webcams?
You can do that with ComboBox's "SelectedIndexChanged' method like below.
If you don't want to do with ComboBox's "SelectedIndexChanged" method.
You can use a button's "_Click" method.
After that, you can use "_CameraIndex" var with new capture object.
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);
Re: How to get list of webcams?
You're welcome 

Re: How to get list of webcams?
I am trying to get a higher resolution from my webcams. I can only get a default of 640X480.
Here is my code:
Thanks in advance
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
Re: How to get list of webcams?
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.
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.
Who is online
Users browsing this forum: No registered users and 4 guests