Can I change my MLX90640 thermal output to a polar orientation?

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

Can I change my MLX90640 thermal output to a polar orientation?

Post by ceilowens »

Hello,

I've been playing with some code with my thermal camera. I have an output that showcases a live video of thermal reactions from people and things.

What I'm only trying to do is change the orientation of the output.

I have the code below:

Code: Select all

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
        #fig.savefig('mlx90640_test_fliplr.png',dpi=300,facecolor='#FCFCFC', bbox_inches='tight') # comment out to speed up
        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
I want to simply add a few lines of code to change the orientation of the output from cartesian to polar.

I'm attaching my current output and if needed, a circle which is the orientation that I'm seeking. If possible, I want to retain the cartesian coordianates of each bit (x,y) and transform it into polar coordinates (r, theta).

Is there anyone that can help?
Attachments
circle.png
circle.png (33.28 KiB) Viewed 122 times
thermal img ex.png
thermal img ex.png (614.14 KiB) Viewed 122 times

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: Can I change my MLX90640 thermal output to a polar orientation?

Post by sj_remington »

to change the orientation of the output from cartesian to polar
Could you take a few lines to explain what you mean by this? The question doesn't make sense, as worded. For example: define the meanings of r and theta, in the polar plot.

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”