alex-ong / NESTrisOCR

OCR for statistics in NESTris
24 stars 7 forks source link

Capture areas from nes logical pixels, and update easiercap palette accordingly #48

Closed timotheeg closed 4 years ago

timotheeg commented 4 years ago

Context

Palette script was averaging pixels from a static 3x3 pixel area from the input.

What we really want however is a fixed safe location of expected pure color derived from the NES logical pixels. Like this:

image

From logical NES pixel, the green zones above are 2x2 pixels in size, at position (3,3) ( where position (0,0) is the top-left corner)

Approach

Results

For the sample fields of easiercap in this repo (size of field is 199x321, which is an "okay-ish" calibration), the capture area increased from 3x3 to 4x4. The captured location still looks safe.

The actual palette changed a little bit, by 1 or 2 units for some color channel values. The differences in the palette image are not perceptible by humans however (see the rich diff in the file changes).

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

image

timotheeg commented 4 years ago

I've edited the palette script once more to sample nes logical pixels.

Like this

nes_pixels_to_sample = (
    (2, 4.5),
    (4.5, 2),
    (4.5, 4.5),
)

Which represent these areas on a 16x16 blocks to show where the .5 sit: image

The safe zone I had previously was safer to grab with lower risk of edge bleeding into the capture area. Still, from my easiercap inputs, it gives is ok results.

Sample image below of capture areas, which capture between 12 and 16 pixels per block. image

alex-ong commented 4 years ago

@timotheeg crap, forgot to merge this back in the day. I'm guessing it's still safe to merge?

alex-ong commented 4 years ago

Just realised this entire PR is a tool; so by definition can't really break master.