Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.