Cameras enumeration
See original GitHub issueSummary of your issue
Environment
Windows 10 1909
NuGet packages:
<package id="OpenCvSharp4" version="4.3.0.20200524" targetFramework="net48" />
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200524" targetFramework="net48" />
<package id="OpenCvSharp4.Windows" version="4.3.0.20200524" targetFramework="net48" />
What did you do when you faced the problem?
Camera enumeration. My concern is to define a valid association between VideoCapture
index
to open a camera and an enumeration of all the cameras connected to the computer.
To enumerate the cameras I use WMI
:
public static List<CameraDevice> GetAllConnectedCameras()
{
var cameras = new List<CameraDevice>();
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
{
int openCvIndex = 0;
foreach (var device in searcher.Get())
{
cameras.Add(new CameraDevice()
{
Name = device["Caption"].ToString(),
Status = device["Status"].ToString(),
DeviceId = device["DeviceId"].ToString(),
OpenCvId = i
});
++i;
}
}
return cameras;
}
public class CameraDevice
{
public int OpenCvId { get; set;}
public string Name { get; set; }
public string DeviceId { get; set; }
public string Status { get; set; }
}
Which gives me an enumeration that is always in the same order.
After a lot of test I understood that OpenCv
Open
method uses an enumeration based on when the camera get connected.
For example if the camera A
is connected before camera B
, the association is: camera A index 0
, camera B index 1
. If the camera A
is connected before camera B
, the association is: camera A index 1
, camera B index 0
.
I don’t find a way to have a solid association - that could for example be that open method gets a camera name as input, instead of an index.
Do you have any idea how to solve this?
Below the code of how I connect to the camera.
Example code:
var videoCapture = new VideoCapture();
if (!videoCapture.Open(CameraDeviceId))
{
throw new ApplicationException("Cannot connect to camera");
}
Output:
[
{
"OpenCvId": 0,
"Name": "HP HD Camera",
"DeviceId": "USB\\VID_0408&PID_5373&MI_00\\6&48E0E83&0&0000",
"Status": "OK"
}
]
What did you intend to be?
I’d like a way to get a solid association between OpenCv
camera index
and camera name.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
@FrancescoBonizzi This is how I handled this + getting supported formats using Media Foundation.
https://github.com/vvvv/VL.OpenCV/blob/master/src/VideoInInfo.cs
Hope it helps
[DllImport(“CameraIndex.dll”)] public extern static int GetCameraIndex(string cameraName);
The return value is the camera index, if not found, it will return -1
------------------ 原始邮件 ------------------ 发件人: “shimat/opencvsharp” <notifications@github.com>; 发送时间: 2020年11月13日(星期五) 下午4:10 收件人: “shimat/opencvsharp”<opencvsharp@noreply.github.com>; 抄送: “Frank”<625851617@qq.com>;“Manual”<manual@noreply.github.com>; 主题: Re: [shimat/opencvsharp] Cameras enumeration (#969)
Yes, please! fbonizzi.90 at gmail.com
Thanks a lot!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.