nerf-turret 1
Infrared targeting nerf turret
Loading...
Searching...
No Matches
mlx_cam.MLX_Cam Class Reference

Class which wraps an MLX90640 thermal infrared camera driver to make it easier to grab and use an image. More...

Public Member Functions

def __init__ (self, i2c, address=0x33, pattern=ChessPattern, width=NUM_COLS, height=NUM_ROWS)
 Set up an MLX90640 camera.
 
def ascii_image (self, array, pixel="██", textcolor="0;180;0")
 Show low-resolution camera data as shaded pixels on a text screen.
 
def ascii_art (self, array)
 Show a data array from the IR image as ASCII art.
 
def get_csv (self, array, limits=None)
 Generate a string containing image data in CSV format.
 
def get_image (self)
 Get one image from a MLX90640 camera.
 

Static Public Attributes

str asc = " -.:=+*#%@"
 A "standard" set of characters of different densities to make ASCII art.
 

Protected Attributes

 _i2c
 The I2C bus to which the camera is attached.
 
 _addr
 The address of the camera on the I2C bus.
 
 _pattern
 The pattern for reading the camera, usually ChessPattern.
 
 _width
 The width of the image in pixels, which should be 32.
 
 _height
 The height of the image in pixels, which should be 24.
 
 _camera
 
 _image
 A local reference to the image object within the camera driver.
 

Detailed Description

Class which wraps an MLX90640 thermal infrared camera driver to make it easier to grab and use an image.

Constructor & Destructor Documentation

◆ __init__()

def mlx_cam.MLX_Cam.__init__ (   self,
  i2c,
  address = 0x33,
  pattern = ChessPattern,
  width = NUM_COLS,
  height = NUM_ROWS 
)

Set up an MLX90640 camera.

Parameters
i2cAn I2C bus which has been set up to talk to the camera; this must be a bus object which has already been set up
addressThe address of the camera on the I2C bus (default 0x33)
patternThe way frames are interleaved, as we read only half the pixels at a time (default ChessPattern)
widthThe width of the image in pixels; leave it at default
heightThe height of the image in pixels; leave it at default

Member Function Documentation

◆ ascii_art()

def mlx_cam.MLX_Cam.ascii_art (   self,
  array 
)

Show a data array from the IR image as ASCII art.

Each character is repeated twice so the image isn't squished laterally. A code of "><" indicates an error, probably caused by a bad pixel in the camera.

Parameters
arrayThe array to be shown, probably image.v_ir

◆ ascii_image()

def mlx_cam.MLX_Cam.ascii_image (   self,
  array,
  pixel = "██",
  textcolor = "0;180;0" 
)

Show low-resolution camera data as shaded pixels on a text screen.

The data is printed as a set of characters in columns for the number of rows in the camera's image size. This function is intended for testing an MLX90640 thermal infrared sensor.

A pair of extended ACSII filled rectangles is used by default to show each pixel so that the aspect ratio of the display on screens isn't too smushed. Each pixel is colored using ANSI terminal escape codes which work in only some programs such as PuTTY. If shown in simpler terminal programs such as the one used in Thonny, the display just shows a bunch of pixel symbols with no difference in shading (boring).

A simple auto-brightness scaling is done, setting the lowest brightness of a filled block to 0 and the highest to 255. If there are bad pixels, this can reduce contrast in the rest of the image.

After the printing is done, character color is reset to a default of medium-brightness green, or something else if chosen.

Parameters
arrayAn array of (self._width * self._height) pixel values
pixelText which is shown for each pixel, default being a pair of extended-ASCII blocks (code 219)
textcolorThe color to which printed text is reset when the image has been finished, as a string "<r>;<g>;<b>" with each letter representing the intensity of red, green, and blue from 0 to 255

◆ get_csv()

def mlx_cam.MLX_Cam.get_csv (   self,
  array,
  limits = None 
)

Generate a string containing image data in CSV format.

This function generates a set of lines, each having one row of image data in Comma Separated Variable format. The lines can be printed or saved to a file using a for loop.

Parameters
arrayThe array of data to be presented
limitsA 2-iterable containing the maximum and minimum values to which the data should be scaled, or None for no scaling

◆ get_image()

def mlx_cam.MLX_Cam.get_image (   self)

Get one image from a MLX90640 camera.

Grab one image from the given camera and return it. Both subframes (the odd checkerboard portions of the image) are grabbed and combined (maybe; this is the raw version, so the combination is sketchy and not fully tested). It is assumed that the camera is in the ChessPattern (default) mode as it probably should be.

Returns
A reference to the image object we've just filled with data

The documentation for this class was generated from the following file: