Created
July 2, 2019 00:15
-
-
Save uzl/ef56b1c97f6a05f1639b67490b30e680 to your computer and use it in GitHub Desktop.
get usb camera id automatically for opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_usb_camera_id(): | |
from subprocess import check_output | |
out = check_output(["ls /dev/video*"], shell=True) | |
out = out.decode('utf-8').strip().split('\n') | |
if len(out) == 0: | |
raise Exception('No camera Module Found') | |
cam_id = None | |
for dev in out: | |
cmd = 'cat /sys/class/video4linux/' + dev[5:] + '/name' | |
cam_name = check_output([cmd], shell=True) | |
cam_name = cam_name.decode('utf-8').strip() | |
if cam_name == 'DFK 33UX265': | |
cam_id = dev | |
print('Camera detected: {} in {}'.format(cam_name, dev)) | |
break | |
return cam_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DFK 33UX265
is camera name