LocationColorMap class¶
Translate the finger location into a code, according to a BMP image. The image is not displayed, but the class can tell you the color of a certain image pixel had it been displayed on screen.
This is a very flexible method for defining several different regions on the screen.
Using this class¶
Create an image file. The file format should be a bitmap (image.bmp) in 24-bit format (which means that each pixel is specified as an RGB combination).
The file doesn’t have to be of the same size as the screen.
Create the LocationColorMap object
Get the colors of pixels using
get_color_at()
In this simplest configuration,
get_color_at()
will tell you the RGB color of the pixel indicated.You can also define
colormap
to map each RGB color to any value (e.g., to makeget_color_at()
will return meaningful values).When using a color map, make sure to set
use_mapping
to True.
Methods and properties:¶
-
class
trajtracker.misc.
LocationColorMap
(image, position=None, use_mapping=False, colormap=None)¶ -
__init__
(image, position=None, use_mapping=False, colormap=None)¶ Constructor - invoked when you create a new object by writing LocationColorMap()
Parameters: - image – Name of a BMP file, or the actual image (rectangular matrix of colors)
- position – See
position
- use_mapping – See
use_mapping
- colormap – See
colormap
-
available_colors
¶ Return a set with all colors that exist in the image
-
colormap
¶ Mapping of each color in the image to another value. This mapping will be used when calling get_color_at(use_mapping=True)
Valid values:
- None (default): no mapping; calling get_color_at(use_mapping=True)
- “RGB”: Each color is assigned the RGB code - a number between 0 and 65535 (0xFFFFFF)
- “DEFAULT”: Each color is assigned a unique code (0, 1, 2, etc.). Codes are assigned by order of RGB codes.
- or a dictionary that maps each color in the image (RGB tuple) to a value
-
get_color_at
(x_coord, y_coord, use_mapping=None)¶ Return the color at a given coordinate
Parameters: - x_coord –
- y_coord –
- use_mapping –
Returns: The color in the given place, or None if the coordinate is out of the image range
-
log_level
¶ Logging level of this object: trajtracker.log_none, log_error (default), log_warn, log_info, log_debug, log_trace
-
position
¶ The coordinate of the image provided in the constructor (middle of the image) - an (x,y) tuple/list If position=(a,b), then
get_color_at()
with arguments (a,b) will return the color of the middle of the image.
-
use_mapping
¶ The default value of the ‘use_mapping’ argument in get_color_at()
Type: bool
-