Flirpy with PT2/Lepton 3.5 support (comments welcome)

145 views
Skip to first unread message

Josh Veitch-Michaelis

unread,
Feb 13, 2020, 12:55:08 PM2/13/20
to Flir Lepton
Hi everyone,

I've been working on a Python library to easily grab images from FLIR cameras. I've recently added some preliminary support for the Lepton 3.5 using the PT2 and it would be great if people could try it out. I hope to add support for low level interfaces too, when I have time. The library also has pretty good (and tested) support for the FLIR Boson and the Tau in serial mode; it can also split out.SEQ files from the Duo Pro cameras. The capture backend is OpenCV and it should work fine on Windows and Linux, but I haven't tried to integrate the uvc driver for Mac yet (and Mac has rubbish 16-bit video support).

Currently the code assumes you have telemetry enabled as an image footer (I'll add a flag for this in later versions), and it will automatically decode the values and store them as attributes.

You can install using:

pip install flirpy

and a simple grab example can be found here: https://github.com/LJMUAstroecology/flirpy#grab-images. Flirpy should automatically detect which video device the PT2 is. Images are returned as radiometric by default, I believe the default scale factor out of the camera is 100 or something (I forget!). Cameras support the with interface in Python, and I suggest using this so they will automatically close themselves when done e.g.

with flirpy.camera.Lepton() as cam:
    image
= cam.grab()


I hope this helps, and please do send over suggestions or requests either here or on the issue tracker on Github. I'm actively working on documenting everything at the moment, but you can poke around the code - should be fairly straightforward.

Best,
Josh

Al Bencomo

unread,
Feb 13, 2020, 9:02:28 PM2/13/20
to Flir Lepton
Hello Josh,

Thank you for sharing your work and well documenting it. I gave it a quick try and I have a just a couple of comments.  In the lepton.py file, I had to add the import os and convert the vid value to uppercase since in my Ubuntu 18.04, it was listed as lowercase ('1e4e'); which causes a raise ValueError("Lepton not connected.").  Everything else works well.  Thanks! ~~Al  

flirpy.png


Josh Veitch-Michaelis

unread,
Feb 14, 2020, 9:44:52 AM2/14/20
to Flir Lepton
Hi Al,

Thanks for trying it out, fixed! (I've not updated on PyPI yet though)

Best,
Josh

Al Bencomo

unread,
Feb 14, 2020, 11:01:26 AM2/14/20
to Flir Lepton
Josh,

I failed to mention that when I tried to capture multiple images I get this message in the console:

[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

Maybe I'm doing something wrong, do you have an example showing how to capture a sequence of images?

Josh Veitch-Michaelis

unread,
Feb 14, 2020, 1:55:48 PM2/14/20
to Flir Lepton
I'll check this out on Linux this evening, but on Windows this works fine for me:

from flirpy.camera.lepton import Lepton
import matplotlib.pyplot as plt

with Lepton() as cam:
   
for _ in range(10):
        image
= cam.grab()
        plt
.figure()
        plt
.imshow(image)

You can also try forcing the camera ID if it's still not detecting properly:

with Lepton() as cam:
    cam
.setup_video(1)
   
for _ in range(10):
        image
= cam.grab()
        plt
.figure()
        plt
.imshow(image)

(On a laptop here so dev 0 is the integrated webcam)

Al Bencomo

unread,
Feb 14, 2020, 2:23:58 PM2/14/20
to Flir Lepton
The first code snippet works, although it still throws the warnings. The 2nd fails when it attempts to call `cam.setup_video(1)` the second time.  

[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video1): can't open camera by index
Traceback (most recent call last):
  File "/home/safe50/PycharmProjects/flirpy/test.py", line 5, in <module>
    cam.setup_video(1)
  File "/home/safe50/PycharmProjects/flirpy/venv/lib/python3.6/site-packages/flirpy/camera/lepton.py", line 104, in setup_video
    raise IOError("Failed to open capture device {}".format(device_id))
OSError: Failed to open capture device 1

Josh Veitch-Michaelis

unread,
Feb 14, 2020, 5:08:37 PM2/14/20
to Flir Lepton
The second one probably fails if the Lepton isn't actually `/dev/video1`.

I just tried this out on an Ubuntu 19.04 machine and I get the same warning. I believe it was caused by the code which attempts to determine which video device is which, if there are multiple devices which match the VID/PID. The code opens the matching devices and sees which one actually captures images. When the right camera was found, the code called a break before releasing the camera. Then when the device is opened again, it throws that warning. I've pushed a fix to PyPI (v0.0.10), let me know if that does it! Also affected the Boson code I suspect, so I changed that as well.
Reply all
Reply to author
Forward
0 new messages