The Hitchhiker’s Guide to Python!
Structuring Your Project
Code Style
// Scales Fonts + Checkboxes UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JOSM HiDPI Support
Java swing application too small in ~HiDpi~ computers, UIManager.put('*.font'), JXLayer
JMeterUtils JavaDoc
Scale a JCheckBox box
HiDPI support in Java Swing for multiple look and feels
Make JCheckbox bigger..?
Lepton Maker Community – Maker community for Lepton thermal imaging camera
Boson
Lepton 2.0
Lepton 2.5
Lepton 3.0
Lepton 3.5
FLIR Lepton Breakout Board v1.4
PureThermal 2
Raspberry Pi 3 FLIR Lepton Dev Kit
DIY-Thermocam
FLIR BOSON VPC Accessory with USB Cable
FLIR BOSON VPC Accessory with USB-ANALOG CABLE
GroupGets PureThermal 2
Digikey SparkFun Electronics DEV-14670
Mouser SparkFun DEV-14670
Mouser SparkFun DEV-14670-Board
SparkFun PureThermal 2 – FLIR Lepton Smart I/O Board
SparkFun FLIR Radiometric Lepton Dev Kit
PureThermal 2
Flir Boson 640
FLIR Boson & Accessories
github.com/groupgets/purethermal1-firmware, Reference firmware for PureThermal 1 FLIR Lepton Dev Kit
github.com/groupgets/purethermal1-uvc-capture, USB Video Class capture examples for PureThermal 1 / PureThermal 2 FLIR Lepton Dev Kit
github.com/groupgets/libuvc, a cross-platform library for USB video devices (FORK!)
github.com/groupgets/LeptonModule, Code for getting started with the FLIR Lepton breakout board
github.com/groupgets/pylepton, Quick and dirty pure python library for interfacing with FLIR lepton
github.com/groupgets/GetThermal, Cross-platform USB thermal camera viewer
github.com/groupgets/GetThermal/wiki/Building-for-Raspberry-Pi, Building for Raspberry Pi
RaspberryPi2EGLFS
“EGLFS is a platform plugin for running Qt5 applications on top of EGL and OpenGL ES 2.0 without an actual windowing system (like X11 or Wayland).”
Qt for Embedded Linux
github.com/maxritter/DIY-Thermocam
github.com/maxritter/diythermocam_firmware
$ git clone git@github.com:groupgets/purethermal1-uvc-capture.git
$ cd purethermal1-uvc-capture/python/
$ ./uvc-radiometry.py
Error: could not find libuvc!
$ sudo apt-get install libuvc-dev
$ dpkg-query -L libuvc-dev
[...]
/usr/lib/x86_64-linux-gnu/libuvc.so
[...]
$ ./uvc-radiometry.py
Traceback (most recent call last):
File "./uvc-radiometry.py", line 6, in <module>
import cv2
ImportError: No module named cv2
$ sudo apt-get install python-opencv
$ ./uvc-radiometry.py
uvc_open error
$ dmesg | tail -n 30
[ 733.814416] usb 1-1: new full-speed USB device number 7 using xhci_hcd
[ 733.966127] usb 1-1: New USB device found, idVendor=1e4e, idProduct=0100
[ 733.966142] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 733.966153] usb 1-1: Product: PureThermal 1
[ 733.966162] usb 1-1: Manufacturer: GroupGets
[ 733.966171] usb 1-1: SerialNumber: v1.1.0
[ 733.968005] uvcvideo: Found UVC 1.00 device PureThermal 1 (1e4e:0100)
[ 733.969256] uvcvideo 1-1:1.0: Entity type for entity Extension 3 was not initialized!
[ 733.969273] uvcvideo 1-1:1.0: Entity type for entity Processing 2 was not initialized!
[ 733.969284] uvcvideo 1-1:1.0: Entity type for entity Extension 4 was not initialized!
[ 733.969294] uvcvideo 1-1:1.0: Entity type for entity Extension 5 was not initialized!
[ 733.969305] uvcvideo 1-1:1.0: Entity type for entity Extension 6 was not initialized!
[ 733.969315] uvcvideo 1-1:1.0: Entity type for entity Extension 7 was not initialized!
[ 733.969326] uvcvideo 1-1:1.0: Entity type for entity Extension 21 was not initialized!
[ 733.969337] uvcvideo 1-1:1.0: Entity type for entity Extension 254 was not initialized!
[ 733.969348] uvcvideo 1-1:1.0: Entity type for entity Camera 1 was not initialized!
[ 733.971018] input: PureThermal 1: PureThermal 1 as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/input/input13
$ ./uvc-radiometry.py
uvc_open error
$ sudo ./uvc-radiometry.py
unsupported descriptor subtype VS_COLORFORMAT
unsupported descriptor subtype VS_COLORFORMAT
unsupported descriptor subtype VS_COLORFORMAT
unsupported descriptor subtype VS_COLORFORMAT
unsupported descriptor subtype VS_COLORFORMAT
device opened!
Version gpp: 3.3.26 dsp: 3.3.26
FLIR part #: 500-0771-01
FLIR serial #: '{"(\x00\x00\x00\x00\x00'
format: UYVY
frame 160x120 @ 9fps
format: Y16
frame 160x120 @ 9fps
frame 160x122 @ 9fps
format: Y8
frame 160x120 @ 9fps
format: RGBP
frame 160x120 @ 9fps
format: }�6�
frame 160x120 @ 9fps
uvc_start_streaming failed: -2
$ sudo apt-get remove libuvc-dev
UVC Y16 reading raw values – Pure Thermal 1
$ cd ..
$ git clone https://github.com/groupgets/GetThermal.git
$ cd GetThermal
$ git submodule update --init
Submodule 'libuvc' (https://github.com/groupgets/libuvc) registered for path 'libuvc'
Cloning into '/home/andreas/src/GetThermal/libuvc'...
Submodule path 'libuvc': checked out '5e866910de3f172bd5adab72baec40a066bbbe3a'
$ cmake ..
Command 'cmake' not found, but can be installed with:
sudo apt install cmake
$ sudo apt install cmake
$ cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default to Release
-- No target type selected, default to shared library
CMake Warning at CMakeLists.txt:58 (message):
JPEG not found. libuvc will not support JPEG decoding.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBUSB_INCLUDE_DIR
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
used as include directory in directory /home/andreas/src/GetThermal/libuvc
LIBUSB_LIBRARY_NAMES
linked by target "uvc" in directory /home/andreas/src/GetThermal/libuvc
-- Configuring incomplete, errors occurred!
See also "/home/andreas/src/GetThermal/libuvc/build/CMakeFiles/CMakeOutput.log".
$ sudo apt-get install libusb-1.0-0-dev
$ cmake ..
CMake Warning at CMakeLists.txt:58 (message):
JPEG not found. libuvc will not support JPEG decoding.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andreas/src/GetThermal/libuvc/build
$ sudo apt-get install libjpeg-dev
The following NEW packages will be installed:
libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev
$ xed $HOME/src/GetThermal/libuvc/CMakeLists.txt
# Try to find JPEG using a module or pkg-config. If that doesn't work, search for the header.
find_package(jpeg QUIET)
if(NOT JPEG_FOUND)
find_path(JPEG_INCLUDE_DIR jpeglib.h)
if(JPEG_INCLUDE_DIR)
set(JPEG_FOUND ON)
set(JPEG_LIBRARIES -ljpeg)
endif()
endif()
$ cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default to Release
-- No target type selected, default to shared library
-- Building libuvc with JPEG support.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andreas/src/GetThermal/libuvc/build
$ make
[ 50%] Linking C shared library libuvc.so
[100%] Linking C static library libuvcstatic.a
$ xed $HOME/src/purethermal1-uvc-capture/python/uvctypes.py
libuvc = cdll.LoadLibrary("/home/andreas/src/GetThermal/libuvc/build/libuvc.so")
$ sudo ./uvc-radiometry.py
device opened!
Version gpp: 3.3.26 dsp: 3.3.26
FLIR part #: 500-0771-01
FLIR serial #: '{"(\x00\x00\x00\x00\x00'
format: UYVY
frame 160x120 @ 9fps
format: Y16
frame 160x120 @ 9fps
frame 160x122 @ 9fps
format: Y8
frame 160x120 @ 9fps
format: RGBP
frame 160x120 @ 9fps
format: }�6�
frame 160x120 @ 9fps
Estimated / selected altsetting bandwith : 18 / 962.
Lepton Camera feed not available
$ sudo sh -c "echo 'SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"1e4e\", ATTRS{idProduct}==\"0100\", SYMLINK+=\"pt1\", GROUP=\"usb\", MODE=\"666\"' > /etc/udev/rules.d/99-pt1.rules"
$ ls -la /dev
0 lrwxrwxrwx 1 root root 15 Nov 16 17:46 pt1 -> bus/usb/001/013
$ vlc
$ ls -la /dev
0 drwxr-xr-x 4 root root 80 Nov 16 17:46 v4l
0 crw-rw-rw-+ 1 root root 81, 0 Nov 16 17:46 video0
VideoCapure: uncompressed 16 bit video stream (Y16)
$ python
>>> import cv2
>>> cam = cv2.VideoCapture("/dev/video0")
>>> cam.get(cv2.CAP_PROP_FORMAT)
16.0
>>> cam.set(cv2.CAP_PROP_FORMAT,cv2.CV_16U)
VIDEOIO ERROR: V4L2: setting property #8 is not supported
True
>>> print(cv2.CV_16U)
2
>>> print(cv2.CV_8UC3)
16
>>> cam.set(cv2.CAP_PROP_FORMAT, 2.0)
VIDEOIO ERROR: V4L2: setting property #8 is not supported
True
Captured frame RGB to YUV and Reverse
Creating a video with OpenCV
$ sudo apt install v4l-utils $ v4l2-ctl -d /dev/video0 --list-formats-ext ioctl: VIDIOC_ENUM_FMT Index : 0 Type : Video Capture Pixel Format: 'UYVY' Name : UYVY 4:2:2 Size: Discrete 160x120 Interval: Discrete 0.111s (9.000 fps) Index : 1 Type : Video Capture Pixel Format: 'Y16 ' Name : 16-bit Greyscale Size: Discrete 160x120 Interval: Discrete 0.111s (9.000 fps) Size: Discrete 160x122 Interval: Discrete 0.111s (9.000 fps) Index : 2 Type : Video Capture Pixel Format: 'GREY' Name : 8-bit Greyscale Size: Discrete 160x120 Interval: Discrete 0.111s (9.000 fps) Index : 3 Type : Video Capture Pixel Format: 'RGBP' Name : 16-bit RGB 5-6-5 Size: Discrete 160x120 Interval: Discrete 0.111s (9.000 fps) Index : 4 Type : Video Capture Pixel Format: 'BGR3' Name : 24-bit BGR 8-8-8 Size: Discrete 160x120 Interval: Discrete 0.111s (9.000 fps)
$ uname -a
Linux udoo-x86 4.15.0-32-generic #35-Ubuntu SMP Fri Aug 10 17:58:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ dmesg
[...]
[ 168.770386] usb 1-3: new high-speed USB device number 6 using xhci_hcd
[ 168.921648] usb 1-3: New USB device found, idVendor=09cb, idProduct=4007
[ 168.921663] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 168.921673] usb 1-3: Product: Boson
[ 168.921682] usb 1-3: Manufacturer: FLIR
[ 168.921690] usb 1-3: SerialNumber: 6088
[ 168.930320] cdc_acm 1-3:1.2: ttyACM1: USB ACM device
[ 169.013588] media: Linux media interface: v0.10
[ 169.032892] Linux video capture interface: v2.00
[ 169.062065] uvcvideo: Unknown video format 3132564e-0000-0010-8000-00aa00389b71
[ 169.062075] uvcvideo: Found UVC 1.00 device Boson (09cb:4007)
[ 169.064103] uvcvideo 1-3:1.0: Entity type for entity Processing 3 was not initialized!
[ 169.064108] uvcvideo 1-3:1.0: Entity type for entity Camera 1 was not initialized!
[ 169.064461] usbcore: registered new interface driver uvcvideo
[ 169.064463] USB Video Class driver (1.1.1)
$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YU12'
Name : Planar YUV 4:2:0
Size: Discrete 640x512
Interval: Discrete 0.111s (9.000 fps)
Interval: Discrete 0.133s (7.500 fps)
Index : 1
Type : Video Capture
Pixel Format: 'Y16 '
Name : 16-bit Greyscale
Size: Discrete 320x256
Interval: Discrete 0.111s (9.000 fps)
Interval: Discrete 0.133s (7.500 fps)
Index : 2
Type : Video Capture
Pixel Format: 'NV12'
Name : Y/CbCr 4:2:0
Size: Discrete 640x512
Interval: Discrete 0.111s (9.000 fps)
Interval: Discrete 0.133s (7.500 fps)
Index : 3
Type : Video Capture
Pixel Format: ''
Name : 3132564e-0000-0010-8000-00aa003
Size: Discrete 640x512
Interval: Discrete 0.111s (9.000 fps)
Interval: Discrete 0.133s (7.500 fps)
$ ./GetThermal-v0.1.3-x86_64-Linux.AppImage
UVC initialized
Device found
uvc_open: Access denied (-3)
$ sudo ./GetThermal-v0.1.3-x86_64-Linux.AppImage
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
UVC initialized
Device found
Device opened
DEVICE CONFIGURATION (09cb:4007/6088) ---
Status: idle
VideoControl:
bcdUVC: 0x0100
VideoStreaming(1):
bEndpointAddress: 129
Formats:
UncompressedFormat(1)
bits per pixel: 12
GUID: 4934323000001000800000aa00389b71 (I420)
default frame: 1
aspect ratio: 0x0
interlace flags: 00
copy protect: 00
FrameDescriptor(1)
capabilities: 02
size: 640x512
bit rate: 10592000-235929600
max frame size: 491520
default interval: 1/9
interval[0]: 1/9
interval[1]: 1/7
UncompressedFormat(2)
bits per pixel: 16
GUID: 5931362000001000800000aa00389b71 (Y16 )
default frame: 1
aspect ratio: 0x0
interlace flags: 00
copy protect: 00
FrameDescriptor(1)
capabilities: 02
size: 320x256
bit rate: 10592000-78643200
max frame size: 163840
default interval: 1/9
interval[0]: 1/9
interval[1]: 1/7
UncompressedFormat(3)
bits per pixel: 12
GUID: 4e56313200001000800000aa00389b71 (NV12)
default frame: 1
aspect ratio: 0x0
interlace flags: 00
copy protect: 00
FrameDescriptor(1)
capabilities: 02
size: 640x512
bit rate: 10592000-235929600
max frame size: 491520
default interval: 1/9
interval[0]: 1/9
interval[1]: 1/7
UncompressedFormat(4)
bits per pixel: 12
GUID: 4e56323100001000800000aa00389b71 (NV21)
default frame: 1
aspect ratio: 0x0
interlace flags: 00
copy protect: 00
FrameDescriptor(1)
capabilities: 02
size: 640x512
bit rate: 10592000-235929600
max frame size: 491520
default interval: 1/9
interval[0]: 1/9
interval[1]: 1/7
END DEVICE CONFIGURATION
Initializing Boson with UVC backend...
Using FLIR Boson with firmware 6088
Initialize: 0x00000000
bmHint: 0001
bFormatIndex: 1
bFrameIndex: 1
dwFrameInterval: 1111111
wKeyFrameRate: 1
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 14240
dwMaxVideoFrameSize: 491520
dwMaxPayloadTransferSize: 491532
bInterfaceNumber: 1
Streaming...
QQmlExpression: Expression qrc:/ViewerForm.ui.qml:69:22 depends on non-NOTIFYable properties:
BosonVariation::supportsRadiometry
QQmlExpression: Expression qrc:/ViewerForm.ui.qml:53:30 depends on non-NOTIFYable properties:
BosonVariation::supportsRadiometry
Surface set. Supported formats: 18 19 22 23 20 21 3 1 10 8 5
Surface supports format 18 width 640 height 512QQmlExpression: Expression qrc:/boson/InfoControls.qml:44:23 depends on non-NOTIFYable properties:
BosonVariation::softwareRev
QQmlExpression: Expression qrc:/boson/InfoControls.qml:40:23 depends on non-NOTIFYable properties:
BosonVariation::cameraSerialNumber
QQmlExpression: Expression qrc:/boson/InfoControls.qml:36:23 depends on non-NOTIFYable properties:
BosonVariation::cameraPartNumber
QQmlExpression: Expression qrc:/boson/InfoControls.qml:32:23 depends on non-NOTIFYable properties:
BosonVariation::sensorSerialNumber
QQmlExpression: Expression qrc:/boson/InfoControls.qml:28:23 depends on non-NOTIFYable properties:
BosonVariation::sensorPartNumber
QQmlExpression: Expression qrc:/boson/VidControls.qml:47:22 depends on non-NOTIFYable properties:
BosonVariation::supportsHwPseudoColor
QQmlExpression: Expression qrc:/boson/VidControls.qml:25:22 depends on non-NOTIFYable properties:
BosonVariation::supportsHwPseudoColor
qrc:/controls/VideoRoi.qml:18: TypeError: Cannot read property 'height' of undefined
qrc:/controls/VideoRoi.qml:17: TypeError: Cannot read property 'width' of undefined
qrc:/controls/VideoRoi.qml:16: TypeError: Cannot read property 'y' of undefined
qrc:/controls/VideoRoi.qml:15: TypeError: Cannot read property 'x' of undefined
Closing...
Done streaming.
Device closed
UVC exited
Reading entire file in Python
The Python Tutorial – Input and Output
If you don’t use “with”, when does Python close files? The answer is: It depends.
Is closing a file after having opened it with `open()` required in Python?
Is explicitly closing files important?
PEP 343 — The “with” Statement
When would one use “as” in Python?
As Keyword In Python
Python equivalent of Java StringBuffer? (Python 3, 2013)
Efficient String Concatenation in Python (Python 2, 2004)
Iterating over a string
“Simply implement an iterator that defines a next() method, and implement an __iter__ method on a class to make it iterable.”
s = 'abcde'
for c in s:
print(c)
Reverse string in Python (5 different ways)
s = s[::-1]