1

I'm using an MLX90640 Thermal Camera and I got it to work after some time through a Raspberry Pi.

What I am trying to do however is take in a picture every minute (or every few minutes) from what it sees. It doesn't necessarily have to show the video in tandem, but I want to save the images in a folder to be able to code with them.

My ultimate goal is to show a fire from the thermal image reduce in size until its ultimately out though Python. Is there any advice?

Here is the code I'm referencing and what is showing a live thermal signature:

import time,board,busio
import numpy as np
import adafruit_mlx90640
import matplotlib.pyplot as plt

print("Initializing MLX90640")
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000) # setup I2C
mlx = adafruit_mlx90640.MLX90640(i2c) # begin MLX90640 with I2C comm
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ # set refresh rate
mlx_shape = (24,32)
print("Initialized")

# setup the figure for plotting
plt.ion() # enables interactive plotting
fig,ax = plt.subplots(figsize=(12,7))
therm1 = ax.imshow(np.zeros(mlx_shape),vmin=0,vmax=60) #start plot with zeros
cbar = fig.colorbar(therm1) # setup colorbar for temps
cbar.set_label('Temperature [$^{\circ}$C]',fontsize=14) # colorbar label

frame = np.zeros((24*32,)) # setup array for storing all 768 temperatures
t_array = []
print("Starting loop")
while True:
    t1 = time.monotonic()
    try:
        mlx.getFrame(frame) # read MLX temperatures into frame var
        data_array = (np.reshape(frame,mlx_shape)) # reshape to 24x32
        therm1.set_data(np.fliplr(data_array)) # flip left to right
        therm1.set_clim(vmin=np.min(data_array),vmax=np.max(data_array)) # set bounds
        cbar.update_normal(therm1) # update colorbar range
        plt.title(f"Max Temp: {np.max(data_array):.1f}C")
        plt.pause(0.001) # required
        t_array.append(time.monotonic()-t1)
        print('Sample Rate: {0:2.1f}fps'.format(len(t_array)/np.sum(t_array)))
    except ValueError:
        continue # if error, just read again
4
  • 1
    what exactly is the problem?
    – jsotola
    Commented Oct 10, 2022 at 2:22
  • With the code, I am able to showcase a live video showcasing the heat from the camera. I'm trying to figure out how to simply take in a picture every minute or so instead and store it into a file to be able to process each picture in Python. Sorta like snapshots. I didn't know if there was any code I could reference for this camera specifically on a Raspberry Pi.
    – ceilowens
    Commented Oct 10, 2022 at 2:47
  • Usually in Python when I was using OpenCV, I could simply choose to use a webcam or an external camera, but I'm not sure about the process with my thermal one.
    – ceilowens
    Commented Oct 10, 2022 at 2:50
  • And also, I want to be able to take in the matrix of thermal values along with the image.
    – ceilowens
    Commented Oct 10, 2022 at 3:02

1 Answer 1

1

You have all you need in your code to store the images now and then. The image data is stored in data_array and updated every loop cycle. It seem to be a 2D numpy array, there are number of ways to store them. The easiest is saving into numpy binary like np.save('file_path/file_name.npy', data_array).

Something to keep in mind, thermal images unlike regular RGB images contain one value per pixel (not 3 like in RGB), meaning that they are "monochrome". Generally you can use matplotlib, as you are already using it, to display the images in pseudo-colors and to save figures like fig.savefig('figure_name.png', dpi=150).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.