FRLG Summary stat reading initial implementation#1130
FRLG Summary stat reading initial implementation#1130miniumknight wants to merge 12 commits intoPokemonAutomation:mainfrom
Conversation
SerialPrograms/Source/PokemonFRLG/Programs/TestPrograms/PokemonFRLG_ReadStats.cpp
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.cpp
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.cpp
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.cpp
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.cpp
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h
Outdated
Show resolved
Hide resolved
SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_StatsReader.cpp
Outdated
Show resolved
Hide resolved
| // | ||
| // Returns the parsed integer, or -1 on failure. | ||
| int read_digits_waterfill_template( | ||
| Logger& logger, |
|
|
||
| // Read a string of decimal digits from `stat_region` by splitting the region into | ||
| // a fixed number of equal-width segments, instead of using waterfill. | ||
| // Useful when digits are tightly packed or overlapping and waterfill merges them. |
There was a problem hiding this comment.
When are the digit overlapping?
| std::string prefix = "DebugDumps/ocr_" + label + "_" + std::to_string(id); | ||
|
|
||
| // Save raw input | ||
| image.save(prefix + "_0_raw.png"); |
There was a problem hiding this comment.
Put this behind some sort of debug flag.
| cv::Mat src = image.to_opencv_Mat(); | ||
|
|
||
| // Step 1: Gaussian blur at NATIVE resolution with 5×5 kernel. | ||
| // The 5×5 kernel reaches 2 pixels away (vs 1px for 3×3), bridging |
There was a problem hiding this comment.
Let's try to avoid non-ascii characters in source code.
| // Step 3: BW threshold on the smooth upscaled image. | ||
| ImageRGB32 bw = | ||
| to_blackwhite_rgb32_range(resized_img, in_range_black, bw_min, bw_max); | ||
| bw.save(prefix + "_3_bw.png"); |
There was a problem hiding this comment.
Same as earlier, put all the temporary/debug images behind a debug flag.
| // | ||
| // The native blur connects gaps. Post-BW padding provides margins. | ||
| static ImageRGB32 preprocess_for_ocr(const ImageViewRGB32 &image, | ||
| const std::string &label, |
There was a problem hiding this comment.
Nit: If a function headers needs to be broken up, we move all of it on the following lines such that they start with one indent rather than mid-way through the page.
ReturnType function_name(
Type param0, Type param1,
Type param2, Type param3,
Type param2, Type param3
){
}
| // Read Name (white text with shadow) | ||
| auto name_result = Pokemon::PokemonNameReader::instance().read_substring( | ||
| logger, language, extract_box_reference(game_screen, m_box_name), | ||
| {{combine_rgb(235, 235, 235), combine_rgb(255, 255, 255)}}); |
There was a problem hiding this comment.
This filter range 235 - 255 is probably too small. I've seen whites be as low as 0xc0 (192).
How low can this go before it starts pulling in other stuff we don't want?
If the margin is too small, we typically resort to "multi-filtering" where we run it across a range of narrower bands and pick the best result from all of them.
| if (px.red() > 200 && px.green() > 200 && px.blue() > 200) { | ||
| preprocessed.pixel(c, r) = 0xff000000u; // white text → black | ||
| } else { | ||
| preprocessed.pixel(c, r) = level_box.pixel(c, r); // keep as-is |
There was a problem hiding this comment.
Can this entire double-loop be done using this call?
ImageRGB32 preprocessed = filter_rgb32_range(level_box, 0xffc8c8c8, 0xffffffff, 0xff000000, true);
|
This looks pretty good! Thank you for doing this! |
Basic implementation of FRLG stat reading using either PaddleOCR if enabled or Template matching to set images (From Packages)