nerf-turret 1
Infrared targeting nerf turret
|
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. | |
Class which wraps an MLX90640 thermal infrared camera driver to make it easier to grab and use an image.
def mlx_cam.MLX_Cam.__init__ | ( | self, | |
i2c, | |||
address = 0x33 , |
|||
pattern = ChessPattern , |
|||
width = NUM_COLS , |
|||
height = NUM_ROWS |
|||
) |
Set up an MLX90640 camera.
i2c | An I2C bus which has been set up to talk to the camera; this must be a bus object which has already been set up |
address | The address of the camera on the I2C bus (default 0x33) |
pattern | The way frames are interleaved, as we read only half the pixels at a time (default ChessPattern) |
width | The width of the image in pixels; leave it at default |
height | The height of the image in pixels; leave it at default |
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.
array | The array to be shown, probably image.v_ir |
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.
array | An array of (self._width * self._height) pixel values |
pixel | Text which is shown for each pixel, default being a pair of extended-ASCII blocks (code 219) |
textcolor | The 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 |
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.
array | The array of data to be presented |
limits | A 2-iterable containing the maximum and minimum values to which the data should be scaled, or None for no scaling |
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.