Identifying USB devices

Are the cameras in a fixed position? Are the scenes more or less constant? If so, you could use image recognition to identify the cameras by what they are seeing instead.

There are some decent python tools to do this, this answer has some good info on the topic: https://stackoverflow.com/questions/1927660/compare-two-images-the-python-linux-way


As you discovered, the problem can't be solved, if you can't get a unique identification from the device itself. The closest thing to a solution is to depend upon the physical connection of the unit. (This won't change on reboot. Only if you physically change the position of the connector)

Programmatically you can use sysfs to get the information the kernel has, about the device. Sysfs is a file-system-like representation of devices as the kernel sees them. (Its not real files on the disk)

With it, you can: - identify the device type with product and vendor ID - read the serial number of the device, if it has one. - read the physical connection number on the USB hub

You could start by finding your type of devices in /sys/class. In this example I use an USB→LPT port. But the principle is the same.

$ ls -l /sys/class/usbmisc
lp1 -> ../../devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5/4-1.5:1.0/usbmisc/lp1
lp2 -> ../../devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.6/4-1.6:1.0/usbmisc/lp2

Grap the device name from the uevent file:

cat /sys/class/usbmisc/lp1/uevent
MAJOR=180
MINOR=1
DEVNAME=__usb/lp1__

add /dev so you get the device name to open: /dev/usb/lp1

Use the real path: $ cd -P /sys/class/usbmisc/lp1

Step back 3 branches:

$ cd ../../../
/sys/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5

This directory contains a lot of the information on the device:

idProduct and idVendor can be used to uniquely identify the device type.

If there is a serial file and it contains a unique serial number, you are done.

Otherwise your option is to use the physical connection as identification, which is this directory name “4-1.5” It is unique for the physical connection, and will as you already mentioned change if you plug the device into another port.


Simply unplug the camera's, plug 1 in and do a lsusb. Identify the camera and note down which USB port is used. Maybe put a little label on the cam. Then repeat for the other camera's and you'll get there. Nothing is mission impossible ;)