Python Forum
Get list of Video Device in python on Windows machine - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Get list of Video Device in python on Windows machine (/thread-25574.html)



Get list of Video Device in python on Windows machine - Michal - Apr-03-2020

I am working on a software, where an USB video device is used. I use [python]cv2.VideoCapture()[python] function from the openCV library in the software. The function need to get index of the video device, but my USB cam has sometimes index 0, sometimes index 1 or index 7. Because the software must be user friendly, so I would like to get list of all available USB video devices and let the user choose what device he wants. The best would be get name and address of the devices. I tried search in older questions but without satisfactory answer. The solution should be easy and elegant Thank you very much for your help and I hope that the question is understandable.


RE: Get list of Video Device in python on Windows machine - Mateusz - Apr-03-2020

Try use
pywin32
if Windows:
import win32com.client

wmi = win32com.client.GetObject ("winmgmts:")
for usb in wmi.InstancesOf ("Win32_USBHub"):
    print usb.DeviceID
More details here: https://stackoverflow.com/questions/8110310/simple-way-to-query-connected-usb-devices-info-in-python