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!
....
//-> import DirectShowLib-2005.dll to your project referance
using DirectShowLib;
....
....
//-> define var
private int _CameraIndex;
.... //-> 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";
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;
} 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;
}
_Capture = new Capture(_CameraIndex);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();
}
}
}Users browsing this forum: Google [Bot] and 2 guests