question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cameras enumeration

See original GitHub issue

Summary 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:closed
  • Created 3 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ravazquezcommented, Jan 6, 2021

@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

1reaction
lifuhua123commented, Nov 13, 2020

        [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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Camera lenses and capabilities
Many modern Android devices have two or more cameras on the front, back, or both sides of the device. Each lens can have...
Read more >
Camera Enumeration on Android
This blog post is the latest one in the current series about camera on Android; we have previously covered camera enumeration and camera…...
Read more >
IMAQdx Enumerate Cameras VI
Returns a list of all cameras on the host computer. IMAQdx Enumerate Cameras. cbool.gif. Connected Only? (Yes) If the Connected Only?
Read more >
CVL User's Guide - Persistent Camera Enumeration
When your CVL application launches, CVL automatically generates a list of all connected GigE Vision cameras. The list orders cameras by their IP...
Read more >
Use Persistent Camera Enumeration - Documentation
Persistent Camera Enumeration is an advanced capability that is turned off by default, which means that Designer and VisionPro will manage the assignments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found