alex-ong / NESTrisOCR

OCR for statistics in NESTris
24 stars 7 forks source link

Don't use scale NEAREST for field scanning #44

Closed timotheeg closed 4 years ago

timotheeg commented 4 years ago

Context

Field scanning is currently done with scale NEAREST, which can misbehave on dirty input. A user may see missing blocks at various time during game play.

Approach

Bonus:

For discussion:

Results

Performance

The new method is faster. Result below for 10,000 iterations:

Timing with old method:

$ python3 -m nestris_ocr.ocr_algo.board
1.7801620960235596 0.00017801620960235595

Timing with new method

python3 -m nestris_ocr.ocr_algo.board
1.3790240287780762 0.0001379024028778076

Capture Improvements

The images below show:

Side Note: The regenerated field (last column) shows that the hardcoded reference colors are quite far from the colors reported by the capture device in these example. As discussed previously, this highlights that the system should allow a user to supply a custom color palettes to match their setup.

The sample scripts can be run as:

python3 -m nestris_ocr.assets.sample_inputs.easiercap.test_bad_frames $IMG_PATH
IMG_PATH=nestris_ocr/assets/sample_inputs/easiercap/bad_frames/cropped_10.png

foo

IMG_PATH=nestris_ocr/assets/sample_inputs/easiercap/bad_frames/cropped_63.png

foo

IMG_PATH=nestris_ocr/assets/sample_inputs/easiercap/bad_frames/cropped_82.png

foo