Skip to content

DreamtaleCore/cv_device

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

List Capture Devices for Python OpenCV on Windows

OpenCV does not have an API for listing capture devices. The sample shows how to create a Python extension to invoke DirectShow C++ APIs for enumerating capture devices.

I modified a version from here add serial number for each device.

Environment

NOTE: other versions may also be ok, but I didn't test them.

How to Run

  1. Configure Visual Studio environment:

    • Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
    • Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
    • Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
    • Visual Studio 2015 (VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%

    If you are using Visual Studio 2015, use the following command:

    SET VS90COMNTOOLS=%VS140COMNTOOLS%
    
  2. Add your Windows SDK lib path to setup.py:

    from distutils.core import setup, Extension
    
    module_device = Extension('cv_device',
                            sources = ['cv_device.cpp'], 
                            library_dirs=['G:\Program Files\Microsoft SDKs\Windows\v6.1\Lib']   # <== Here, if u don't add it to path, change here.
                        )
    
    setup (name = 'WindowsDevices',
            version = '1.0',
            description = 'Get device list with DirectShow',
            ext_modules = [module_device])
  3. Build the Python extension

    Python

    python setup.py build install
    
  4. Run the app and select a capture device:

    Python

    python test.py

    camera list in Python

Blog

Listing Multiple Cameras for OpenCV-Python on Windows

About

Query devices' serial number for opencv-python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published