This project integrates a thermal camera with an Arduino to capture real-time temperature and humidity data. It overlays sensor readings on thermal images, detects the darkest contours in the image, and saves annotated screenshots along with metadata (e.g., temperature, humidity, and contour area) in a CSV file.
- Displays thermal images with a color gradient.
- Detects and highlights the darkest regions in the thermal image.
- Displays minimum and maximum temperature values as a color bar.
- Captures temperature and humidity data from an Arduino via a serial connection.
- Displays real-time sensor readings on the thermal image.
- Saves the following data to a CSV file (
sensor_data.csv):- Timestamp
- Temperature
- Humidity
- Saved image filename
- Area of the darkest contours in pixels.
- Saves annotated thermal images in the
screenshotsdirectory.
- Pure Thermal 2 Interface Board
- FLIR Lepton Camera Module
- Computer running Linux (tested on Ubuntu)
- DHT11 Sensor (for temperature and humidity)
- Visual Studio Code (or any text editor)
- Python 3.x
- Required libraries:
libuvcopencv-pythonnumpypyserialcmake
- Required libraries:
- Arduino IDE
- Required library:
DHT-sensor-library(by Adafruit)
- Required library:
- Connect the DHT11 sensor to the Arduino as follows:
- GND (sensor) -> GND (Arduino)
- VCC (sensor) -> 5V (Arduino)
- Signal (sensor) -> Pin 2 (Arduino)
# Clone this repository and navigate to the files directory
git clone <your-repo-url>
cd thermal-camera/files- Navigate to the
dht11_sensor.inofile. - Open it in the Arduino IDE.
- Install the
DHT-sensor-libraryby Adafruit via the Arduino Library Manager. - Ensure the digital pin in the code matches the pin connected to the sensor.
- Upload the code to the Arduino.
- Verify the Arduino is outputting correct data via the Serial Monitor.
If the Arduino outputs incorrect data:
- Double-check the wiring (ensure the signal and power cables are correctly placed).
- Restart the Arduino IDE.
# Navigate to the project directory and create a virtual environment
cd thermal-camera/files
python3 -m venv thermcam
source thermcam/bin/activate# Install required Python libraries and system dependencies
sudo apt update
sudo apt install -y build-essential cmake libusb-1.0-0-dev libjpeg-dev python3-pip libgtk2.0-dev libgtk-3-dev
pip install numpy opencv-python pyserial# Clone the libuvc repository and build it
git clone https://github.com/groupgets/libuvc.git
cd libuvc
mkdir build && cd build
cmake ..
make
sudo make install
sudo ldconfigActivate the virtual environment and run the script:
source thermcam/bin/activate
sudo python3 camera_area.py- The thermal camera feed will:
- Highlight the hottest (red) and coldest (blue) points.
- Show a color bar indicating the temperature range.
- Overlay:
- Temperature (from Arduino).
- Humidity (from Arduino).
- Area of the darkest (coldest) region.
- A sample entry:
| Timestamp | Temperature (C) | Humidity (%) | Photo Filename | Contour Area (px) |
|---|---|---|---|---|
| 2025-01-26 15:29:19 | 22.6 | 45.0 | screenshots/thermal_0.png | 25434.0 |
- Annotated thermal images are saved in the
screenshots/directory.
-
Ensure the camera is properly connected via USB.
-
Verify detection using:
ls /dev/video*If no device appears, check your USB connection and try reconnecting the camera.
-
Confirm the Arduino is connected and note the port using:
ls /dev/ttyUSB* -
Update the
serial_portvariable incamera_area.pyto match the detected port (e.g.,/dev/ttyUSB0).
If you encounter errors such as:
The function is not implementedorCannot query video position
Ensure OpenCV is installed via:
sudo apt update
sudo apt install python3-opencv- Ensure Python dependencies are installed in the virtual environment.
- Run the script with root privileges (
sudo) to access the thermal camera. - Check the Arduino serial output via the Serial Monitor in the Arduino IDE if no sensor data is being received.
thermal-camera/
├── README.md # Documentation
├── LICENSE # License information
├── files/ # Main directory for scripts
│ ├── thermcam/ # Virtual environment for the project
│ ├── camera_area.py # Main Python script
│ ├── sensor_data.csv # CSV log file (auto-generated)
│ ├── screenshots/ # Directory for saved screenshots
│ └── dht11_sensor/ # Arduino sketch for the DHT11 sensor
- libuvc
- OpenCV
- Adafruit DHT Sensor Library
- Creation of GitHub template: Marita Georganta - Robotic Sensing Expert
- Creation of MRAC-IAAC GitHub Structure: Huanyu Li - Robotic Researcher