Coder Social home page Coder Social logo

mlx90640_python's Introduction

Based on code from: https://github.com/pimoroni/mlx90640-library

An ugly but working hack for the raspberry pi 3 so we can spit thermal data out to a file to be read by other programs.

A thermal cam can easily be implemented in python and openCV by reading this file.

Screenshot

Above: Screenshot of myself having got up from the sofa. Note the thermal signature left behind.

mlx90640_driver.cpp

When compiled, the executable can be called with: sudo ./mlx90640_driver 8 Where 8 is the required FPS (4,8 and 16 work) 8 FPS is optimal

This program continually overwrites frame data to /tmp/heatmap.csv, where it can be read by other programs.

Note: Modify /etc/fstab to mount /tmp in to RAM, else this program will hammer your SD card!

thermalcam.py

An example program that reads data from /tmp/heatmap.csv and generates an image from it.

There are a number of Features and hacks implemented this program:

When I physically mounted the cameras, I mounted them side by side. This means the video and thermal images do not overlap correctly. Originally I considered mounting one camera on a kinematic mount, however the simplest solution was to simply re-align them in software. The original video camera frame dimensions are set to 288 368 (slightly larger than 240 * 320 that we end up with) The video data is then cropped in opencv like this: frame = [5:325,10:250] where 5 and 10 are the offsets to crop from respectively.

Ocassionally data is being written whilst we are trying to read and a read error occurs, in that case the last good frame is displayed, rather than just dropping it which is visually annoying.

For an as of yet undetermined reason i2C randomly hangs on the raspberry pi 3, which means the program can no longer retrieve i2c data! Fortunately it turns out that if we merely probe the i2c bus, suddenly everything wakes back up again.The python script checks to see if the current frame of thermal data is different from the last one. If it is not, it just probes the i2c bus at 0x33 (rather than the whole bus which is slow!).

Thermal data is cubic interpolated to give an impression of a higher resolution. The sensor is only 32 by 24 and is scaled to 320 by 240.

The visible and thermal images are combined to provide a meamingful image. Before this occurs edges in the visible image are enhanced to aid viewing.

The temperature displayed is that of the area under the crosshairs.

Keys:

a & z: Alter nmin (normalization limits) changes color mapping. Lower nmin reduces background thermal noise displayed.

s & x: Alters nmax (normalization limits) changes upper limit color mapping.

d & c: Alters the alpha ratio between the Thermal and the video image.

mlx90640_python's People

Contributors

leswright1977 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

Watchers

 avatar  avatar  avatar  avatar  avatar

mlx90640_python's Issues

Program crashes with PiCameraRuntimeError "Timed out waiting for capture to end"

Hi,
I've tinkered a little bit with your code in order to make it run fullscreen and I placed an instruction in /etc/xdg/lxsession/LXDE-pi/autostart to make it autostart when the LXDE starts. The rest of the code is pretty much the same original one.

However sometimes when I boot up the raspberry the code crashes and by redirecting stderr on a log file I found out this traceback:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1704, in capture_continuous
    'Timed out waiting for capture to end')
picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/mlx90640-library/thermal.py", line 45, in <module>
    for frame in camera.capture_continuous(rawCapture, format="rgb", use_video_port=True):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1710, in capture_continuous
    encoder.close()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 431, in close
    self.stop()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 419, in stop
    self._close_output()
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 349, in _close_output
    mo.close_stream(output, opened)
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 371, in close_stream
    stream.flush()
  File "/usr/lib/python3/dist-packages/picamera/array.py", line 238, in flush
    self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution)
  File "/usr/lib/python3/dist-packages/picamera/array.py", line 127, in bytes_to_rgb
    'Incorrect buffer length for resolution %dx%d' % (width, height))
picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 288x368

I'm not expert on the picamera and the odd thing is that other times it works perfectly. If there was an error for the buffer length for resolution, shouldn't the code always fail instantly?
Is there a way to fix this issue?

How to create the mlx90640_driver execute file

How did you compile the Mlx90649_driver.cpp - do I need the bcm8235 lib installed ? - I have tried Geany on the Pi and I get errors.
If I test the circuit with i2cdetect -y 1, I get back the i2c address 33 - but all the compiler in Geany say is that the address is unknown
Can anyone offer any help ?

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.