To support custom roms like das trainer which do not permit reading color1 and color2 from fixed location. We introduced a Colors class which contained a hardcoded default reference color table.
Because the color matching algorithm is resilient (it chooses the closest color), it worked well, but it is clear that the default colors can be quite far from whatever colors a capture card or an emulator might give.
To let users taylor colors to their system, this PR introduces a custom color palette system which can be set in config
Approach
Store palette as both a json file (list of 10 entries of 2 colors each) and a png reference file
Extract the hardcoded reference table from class Colors into nestris_ocr/palettes/DEFAULT.json, which is now loaded at bootstrap time
Add config entry calibration.palette. This entry should contain the name of the palette to load from the folder nestris_ocr/palettes/
Load the palette from config in base_strategy since all child classes would benefit
Add a script to compute palettes
The scripts works by having reference field by level as local files. As an example the PR introduces a color palette for easiercap which was computed by running the following:
the name of the palette (this could be a capture card identifier)
the field path template (fields for level 0 to 9 will be retrieved by interpolating the %d for the level)
Bonus:
the custom script test_bad_frames.py is updated a little for minor fixes.
The class Colors now stores a color list as [black, white, color1, color2] that can be used
The class Colors now includes a method getClosestColorIndex() which can be used by custom scripts (rather than copy/paste).
The palette is also stored as a png file in the nestris_ocr/palettes/ folder for visual reference. For example, below are the 2 palettes that this PR adds:
Context
To support custom roms like das trainer which do not permit reading
color1
andcolor2
from fixed location. We introduced aColors
class which contained a hardcoded default reference color table.Because the color matching algorithm is resilient (it chooses the closest color), it worked well, but it is clear that the default colors can be quite far from whatever colors a capture card or an emulator might give.
To let users taylor colors to their system, this PR introduces a custom color palette system which can be set in config
Approach
nestris_ocr/palettes/DEFAULT.json
, which is now loaded at bootstrap timecalibration.palette
. This entry should contain the name of the palette to load from the foldernestris_ocr/palettes/
base_strategy
since all child classes would benefitThe scripts works by having reference field by level as local files. As an example the PR introduces a color palette for
easiercap
which was computed by running the following:The script takes 2 arguments:
%d
for the level)Bonus:
test_bad_frames.py
is updated a little for minor fixes.Colors
now stores a color list as[black, white, color1, color2]
that can be usedColors
now includes a methodgetClosestColorIndex()
which can be used by custom scripts (rather than copy/paste).The palette is also stored as a png file in the
nestris_ocr/palettes/
folder for visual reference. For example, below are the 2 palettes that this PR adds: