LJMUAstroecology / flirpy

Python library to interact with FLIR camera cores
Other
191 stars 54 forks source link

lepton.find_video_device() does not find Lepton when picamera connected #9

Closed zoltanszalontay closed 4 years ago

zoltanszalontay commented 4 years ago

https://github.com/LJMUAstroecology/flirpy/blob/9a35fb1a4ceca557acea165543acf5cd9d900f1e/flirpy/camera/lepton.py#L66

Automatic video capture device enumeration using lepton.find_video_device() on a Raspberry + Lepton 3.5 + PureThermal setup does not work for me when picamera is also connected.

I guess the problem is at the 66. 'i' is the number of order the video device has been found, which depends on the folder structure. However, cv2.videocapture(id) expects an id that is equivalent to the last figures of the filename of the device driver (as in /sys/class/video4linux/).

Background info: Video devices: ['/sys/class/video4linux/video12', '/sys/class/video4linux/video1', '/sys/class/video4linux/video10', '/sys/class/video4linux/video2', '/sys/class/video4linux/video11', '/sys/class/video4linux/video0']

print d => "[1, 5]" based on filtering capabilities.

The correct id would be '0' (../video0) and cam = camera.setup_video(0) is working.

jveitchmichaelis commented 4 years ago

Nice catch, yes the order of devices and their ids can't be guaranteed... On my machine the índices are in order so this didn't come up. We can probably replace it with something like:

dev.append(int(device.split('video')[-1]))

zoltanszalontay commented 4 years ago

I was thinking about the same, except it is not guaranteed that the number of devices is less than 10 (one decimal figure).

jveitchmichaelis commented 4 years ago

That should be OK, e.g.

>>> '/sys/class/video4linux/video12'.split('video')
['/sys/class/', '4linux/', '12']

Split returns the string, not the character.

zoltanszalontay commented 4 years ago

I can confirm, that the patch above is working on my config.

Thanks a lot! Zoltan

jveitchmichaelis commented 4 years ago

Thanks, glad it works - I'll patch this shortly!

jveitchmichaelis commented 4 years ago

https://github.com/LJMUAstroecology/flirpy/commit/836800908b6a6e9e05682abf0b679f2c782a5eac