Code Monkey home page Code Monkey logo

thermalcamera's Introduction

ThermalCamera

MLX90640 Thermal Camera with Edge Detect Video Overlay, for Raspberry Pi

The Thermal Camera resolution is 32x24, scaled to match the Video Camera resolution. Running the Video Camera at high resolutions lowers the framerate due to the Laplacian Edge Detect processing:

Table

Hardware

Cameras

The cameras need to be mounted flat and as close together as possible:

The USB camera pictured is "Bare USB Webcam" from Public Lab which unfortunately is no longer available.

These will probably work, but with a different FOV:

By default the camera device is /dev/video0. To change it, edit videoDev in config.ini:

videoDev = /dev/video0

Setup

Installation

The installation script installs:

  • pygame
  • colour
  • MLX90640
  • wiringPi
git clone https://github.com/obstruse/ThermalCamera.git
sudo ThermalCamera/install/installThermalCamera.sh

I2C Baudrate

Increase the I2C baudrate to 1 MHz by editing /boot/config.txt. Modify the dtparam=i2c_arm=on line to read:

dtparam=i2c_arm=on,i2c_arm_baudrate=1000000

...and reboot.

Configuration

Program settings can be changed by modifying config.ini located in the same directory as heat.py

  Configuration Settings  
Key Description Default
width display width 320
height display height 240
videoDev video device /dev/video0
camFOV camera FOV 35
heatFOV heat FOV 40
theme color mapping theme 1 (0-3 available)
offsetX image offset X 0
offsetY image offset Y 0

Execution

Run the program from the command line:

ThermalCamera/python/heat.py

You can run the program remotely from an SSH connection, with the heat displayed in an X-window. Framerate will drop (see timings above)

Click on the window to bring up the menu overlay:

Menu

Commands  
MAX/+/- changes the maximum threshold for red pixels.
MIN/+/- changes the minimum threshold for blue pixels.
Capture copy the current camra image to /home/pi/Pictures
Mode cycle through the display modes
Back return to display
Exit exit program

Display Modes:

  • heat + camera overlay
  • heat + edge detect overlay
  • heat only (no scaling)
  • camera only (no scaling)

The Capture only saves a single image. To capture series of images over a period of time, use the gpio command to set GPIO5. For example, to capture 3 seconds of images, this command:

pi@rpi4:~ $ gpio -g write 5 1; sleep 3; gpio -g write 5 0

The captured images in /home/pi/Pictures can be combined into an MP4 or GIF using ffmpeg and convert, for example:

#!
PATTERN=${1}
convert -delay 8 -coalesce -duplicate 1,-2-1 -layers Optimize -loop 0 ${PATTERN}\*.jpg ${PATTERN}.gif

Alignment

Field Of View (FOV)

The script needs the FOV of both cameras in order to scale the images properly. The camera data sheet might have a value for FOV, but it's often missing or incorrect.

To measure the FOV, use the heat only and camera only modes of heat.py. Separate two objects horizontally until they are at the edges of the image. Measure the distance between the objects and the distance to the camera to calculate the FOV:

FOV = degrees(atan(width/distance/2)*2)

FOV

Enter the values for camFOV and heatFOV in config.ini:

camFOV = 35
heatfov = 40

Offset

If you carefully mounted the two cameras, the two images should line up fairly well... but then there's the parallax caused by the distance between them.

To correct for mounting errors and parallax, use the keyboard arrow keys to offset the images until they line up. Press 'w' to save the offsets in the config.ini file



Camera

Thermal Camera with LCD Touchscreen

Hot Watermelon PiZero

EICO 460

EICO 460 Oscilloscope chassis hot spots

thermalcamera's People

Contributors

obstruse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

thermalcamera's Issues

I have some problems with read pixel

Thank you for your kindness.
I used your code with MLX90640 so I changed the import value to "SMBus" and then they said I have some problem with line 222 in heat.py

AttributeError: type object 'SMBus' has no attribute 'readPixels'

What should I do? Could you help me please

getting face temperature

@obstruse
thanks for the work.

Is there any way to findout temperature on face area.?

i can do face detection but I dont know about finding face part in AMG8833 sensor array.

please advise.

cam calibration

Hello
Can you please elaborate the calibration process to put heat data over rgb image?

Also not need to consider displacement of one sensor to another? i mean not in the same physical position, just trying to understand how this works

Thank you!!

runtimeError: Too many retries

Hello! I've been trying to make your project work for some time now, and I'm really close to having it work.
However, when I try to run : ThermalCamera/Python/heat.py
I get this error :
pygame 2.1.3 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
MLX addr detected on I2C, Serial # ['0xb2b', '0xcb26', '0x189']
Traceback (most recent call last):
File "/home/captcharleyhalo/ThermalCamera/python/heat.py", line 325, in
mlx.getFrame(temps)
File "/usr/local/lib/python3.9/dist-packages/adafruit_mlx90640.py", line 132, in getFrame
status = self._GetFrameData(mlx90640Frame)
File "/usr/local/lib/python3.9/dist-packages/adafruit_mlx90640.py", line 161, in _GetFrameData
raise RuntimeError("Too many retries")
RuntimeError: Too many retries

Would you know how to fix this? It's not the mlx90640 because its worked with other codes on itself, however the camera i ordered it plugged by usb... do i need to change its video input or something?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.