alex-ong / NESTrisOCR

OCR for statistics in NESTris
24 stars 7 forks source link

Prelim support for custom color palettes #46

Closed timotheeg closed 4 years ago

timotheeg commented 4 years ago

Context

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

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:

python3 -m scripts.compute_color_palette easiercap nestris_ocr/assets/sample_inputs/easiercap/lvl%d/field.png`

The script takes 2 arguments:

  1. the name of the palette (this could be a capture card identifier)
  2. the field path template (fields for level 0 to 9 will be retrieved by interpolating the %d for the level)

Bonus:

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:

DEFAULT easiercap
DEFAULT easiercap
alex-ong commented 4 years ago

Can I press merge?

timotheeg commented 4 years ago

Yep, PR is ready :)