Skip to content

FRLG Summary stat reading initial implementation#1130

Open
miniumknight wants to merge 12 commits intoPokemonAutomation:mainfrom
miniumknight:main
Open

FRLG Summary stat reading initial implementation#1130
miniumknight wants to merge 12 commits intoPokemonAutomation:mainfrom
miniumknight:main

Conversation

@miniumknight
Copy link

Basic implementation of FRLG stat reading using either PaddleOCR if enabled or Template matching to set images (From Packages)

//
// Returns the parsed integer, or -1 on failure.
int read_digits_waterfill_template(
Logger& logger,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent is 4.


// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When are the digit overlapping?

std::string prefix = "DebugDumps/ocr_" + label + "_" + std::to_string(id);

// Save raw input
image.save(prefix + "_0_raw.png");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

@Mysticial Mysticial Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this entire double-loop be done using this call?

ImageRGB32 preprocessed = filter_rgb32_range(level_box, 0xffc8c8c8, 0xffffffff, 0xff000000, true);

@Mysticial
Copy link
Collaborator

This looks pretty good! Thank you for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants