Introduction: Cost-effective Thermal Camera
- I have developed a device that can be attached to a drone and can live-stream a blended frame made of the thermographic image showing thermal radiation and regular photography with visible light.
- The platform consists of a small single-boarded computer, a thermal camera sensor, and a regular camera module.
- This project aims to examine the possibilities of a low-cost thermal imaging platform for detecting damages in solar panel which is characterized by heat signatures.
- Raspberry Pi 3B+
- Panasonic AMG8833 grid-eye
- Pi Camera V2
- Laptop with VNC viewer
Step 1: PCB Development
- The PCB board for Panasonic grid-eye sensor can be designed with help of Auto-desk EAGLE.
- The .brd file is developed similar to the Adafruit AMG8833 module with slight modifications
- Then the PCB can be printed with PCB manufacturers and I used pcbway.com, where my first order was completely free of charge.
- I found that PCB soldering was completely different from the soldering I knew as it involved surface mounted devices, so I went to another PCB manufacturer and got my PCB soldered with the sensor.
Step 2: Software Devopment
- The code is written in Thonny, a python Integrated Development Environment.
- The procedure behind the project was to connect the pi camera and install associated software.
- The next step was to connect the thermal sensor to correct GPIO pins and install the Adafruit Library for utilizing the sensor.
- Adafruit library contained script for reading the sensor and mapping the temperatures to colors however, moving images it created couldn't be implemented
- Therefore code was rewritten to a format supporting image processing, mainly for fusing two frames together.
Step 3: Reading the Sensors
- To gather data from thermal camera ADAFRUIT library was utilised, which allows fo reasy reasing the sensors with command readpixels(), generating an array containing temepratures in degree Celsius measured from sensors seperate elements.
- For the Pi camera, the function command picamera.capture() generates an image with specified output file format
- In order to suit rapid processing a lower resolution was set to 500 x 500 pixels
Step 4: Thermal Sensor Setup
- Firstly, we have to install the Adafruit Library and python packages
- Open the command prompt and run: sudo apt-get update which will update you Pi
- Then issue the command: sudo apt-get install -y build-essential python-pip python-dev python-smbus git
- Then run: git clone https://github.com/adafruit/Adafruit_Python_GPIO....which will download the Adafruit package to your Raspberry Pi
- Move inside the directory: cd Adafruit_Python_GPIO
- And install setup by running the command: sudo python setup.py install
- Now install scipy and pygame : sudo apt-get install -y python-scipy python-pygame
- Finally, install the color library by issuing the command: sudo pip install colour Adafruit_AMG88xx
Step 5: Enabling I2C Interface
- Issue the command: sudo raspi-config
- Click on the Advanced options and select I2C and then enable it and select Finish
- Reboot the Pi to succesfully enable I2C
- Make sure that you have enabled Camera and VNC interfaces too
Step 6: Wiring the Sensor and Camera
- You should connect only 4 pins of AMG8833 to Pi and leave the IR pin.
- 5V supply and ground can be connected to GPIO pins 1 and 6
- SDA and SCL are wired to pin 4 and 5 of the Pi.
- Login to raspberry with ssh
- run: sudo i2cdetect -y 1
- You should see "69" on the 9th column if not there is some issue in wiring the sensor with Pi.
- Finally connect the pi camera v2 to the camera slot in the raspberry pi
Step 7: Heat Mapping
- Issue the command: git clone https://github.com/adafruit/Adafruit_AMG88xx_pyth...
- Move into the directory Adafruit_AMG88xx_python/examples
- issue the command : sudo python thermal_cam.py
- I have attached the code for heat mapping AMG8833 below.
Step 8: Image Processing
- Temperature Mapping
- To visualize the thermal data, the temperature values are mapped into a color gradient, ranging from blue to red with all other colours in between
- When the sensor is initiated, the lowest temperature is mapped to 0(Blue) and the highest temperature to 1023(Red)
- All other temperatures in between are assigned correlated values within the interval
- The sensor output is 1 x 64 array which is resized to a matrix.
- The resolution of the Thermal sensor is fairly low, 8 x 8 pixels, so cubic interpolation is used to increase the resolution to 32 x 32 which results in matrix 16 times larger
- Interpolation works by constructing new data points between a set of known points however accuracy decreases.
- Numbers to images
- Numbers ranging from 0 to 1023 in 32 x 32 matrix are converted into decimal code in the RGB colour model.
- From the decimal code, it is easy to generate the image with a function from SciPy library
- Resizing with anti-aliasing
- To resize 32 x 32 image to 500 x 500 in order to match the resolution of Pi camera, PIL (Python Image Library) is used.
- It has anti-aliasing filter which will smooth out the edges between the pixels when enlarged up
- Transparent Image overlay
- The digital image and heat image are then blended to one final image adding them with 50% transparency each.
- When images from two sensors with a parallel distance between them are fused, they won't completely overlap
- Finally, Minimum and Maximum Temperature measures by AMG8833 is displayed with overlaying text on display
Step 9: Code and PCB Files
- I have attached the testing and final code for the project below.
Step 10: Conclusion
- Thus a thermal Camera has been built with Raspberry Pi and AMG8833.
- The final video has been embedded in this post
- It can be observed that the temperature changes instantaneously as I get the lighter near the setup and the flame of the lighter has been accurately detected by the sensor.
- Hence this project can be further developed for fever detection in people entering a room which will be very helpful in this COVID19 crisis.
Participated in the