Skip to content

Instantly share code, notes, and snippets.

@uzl
Created July 2, 2019 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzl/ef56b1c97f6a05f1639b67490b30e680 to your computer and use it in GitHub Desktop.
Save uzl/ef56b1c97f6a05f1639b67490b30e680 to your computer and use it in GitHub Desktop.
get usb camera id automatically for opencv
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
@uzl
Copy link
Author

uzl commented Jul 2, 2019

DFK 33UX265 is camera name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment