I'm trying to initialize my camera with VideoCapture by passing the camera index and the videoCaptureApi. The issue is that depending on the VideoCaptureApi, the camera index points to one camera or another. Why does this happen and how could it be resolved?
Environment
Operating System: Windows 11 Pro
Development Environment: Visual Studio 2022
Dependencies:
DirectShowLib (1.0.0)
OpenCvSharp4.Windows (4.9.0.20240103)
Cameras:
Microsoft LifeCam Cinema
ELP-USBFHD06H-BL36
Example code:
DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
if (devices.Length == 0)
{
Console.WriteLine("No se encontraron dispositivos de captura de video.");
return;
}
DsDevice webcam = devices[0];
Console.WriteLine($"Usando la webcam: {webcam.Name}");
using VideoCapture capture = new VideoCapture(0);
if (!capture.IsOpened())
{
Console.WriteLine("No se pudo abrir la webcam.");
return;
}
using (Window window = new Window("Webcam"))
{
while (true)
{
Mat frame = new Mat();
capture.Read(frame);
window.ShowImage(frame);
int key = Cv2.WaitKey(30);
if (key == 27)
break;
}
}
Using
using VideoCapture capture = new VideoCapture(0, VideoCaptureAPIs.ANY);
Output
Opened Camera: ELP-USBFHD06H-BL36
Using
using VideoCapture capture = new VideoCapture(0, VideoCaptureAPIs.DSHOW);
Issue
I'm trying to initialize my camera with VideoCapture by passing the camera index and the videoCaptureApi. The issue is that depending on the VideoCaptureApi, the camera index points to one camera or another. Why does this happen and how could it be resolved?
Environment
Example code:
Using
using VideoCapture capture = new VideoCapture(0, VideoCaptureAPIs.ANY);
Output
Opened Camera: ELP-USBFHD06H-BL36
Using
using VideoCapture capture = new VideoCapture(0, VideoCaptureAPIs.DSHOW);
Output
Opened Camera: Microsoft LifeCam Cinema