Skip to content

Commit 3512ccc

Browse files
committed
Indentation fix for digitreader, removed non ASCII characters
1 parent a7305e1 commit 3512ccc

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_DigitReader.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ struct DigitTemplates {
9090
// ---------------------------------------------------------------------------
9191
// Main function
9292
// ---------------------------------------------------------------------------
93-
int read_digits_waterfill_template(Logger& logger,
94-
const ImageViewRGB32& stat_region,
95-
double rmsd_threshold,
96-
DigitTemplateType template_type,
97-
const std::string& dump_prefix,
98-
uint8_t binarize_high) {
93+
int read_digits_waterfill_template(
94+
Logger& logger,
95+
const ImageViewRGB32& stat_region,
96+
double rmsd_threshold,
97+
DigitTemplateType template_type,
98+
const std::string& dump_prefix,
99+
uint8_t binarize_high
100+
) {
99101
using namespace Kernels::Waterfill;
100102

101103
if (!stat_region) {
@@ -123,7 +125,7 @@ int read_digits_waterfill_template(Logger& logger,
123125
// Pixels where ALL channels <= binarize_high become 1 (foreground).
124126
// Default 0xBE (190) works for yellow stat boxes.
125127
// Use 0x7F (127) for the lilac level box to prevent the blurred
126-
// lilac background (B208, drops to ~156 near shadows) from being
128+
// lilac background (B~208, drops to ~156 near shadows) from being
127129
// captured and merging digit blobs.
128130
// ------------------------------------------------------------------
129131
uint32_t bh = binarize_high;
@@ -195,7 +197,7 @@ int read_digits_waterfill_template(Logger& logger,
195197
ImageViewRGB32 crop = extract_box_reference(stat_region, bbox);
196198

197199
if (dump_prefix == "levelDigit") {
198-
crop.save("DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) + "_split_raw.png");
200+
crop.save("DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) + "_split_raw.png");
199201
}
200202

201203
// Compute RMSD against each digit template; pick the minimum.
@@ -218,16 +220,20 @@ int read_digits_waterfill_template(Logger& logger,
218220
// Always save the raw crop for user inspection / template extraction.
219221
crop.save("DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) +
220222
"_raw.png");
221-
logger.log("DigitReader: blob at x=" + std::to_string(min_x) +
222-
" skipped (best RMSD=" + std::to_string(best_rmsd) +
223-
", threshold=" + std::to_string(rmsd_threshold) + ").",
224-
COLOR_ORANGE);
223+
logger.log(
224+
"DigitReader: blob at x=" + std::to_string(min_x) +
225+
" skipped (best RMSD=" + std::to_string(best_rmsd) +
226+
", threshold=" + std::to_string(rmsd_threshold) + ").",
227+
COLOR_ORANGE
228+
);
225229
continue;
226230
}
227231

228-
logger.log("DigitReader: blob at x=" + std::to_string(min_x) +
229-
" -> digit " + std::to_string(best_digit) +
230-
" (RMSD=" + std::to_string(best_rmsd) + ")");
232+
logger.log(
233+
"DigitReader: blob at x=" + std::to_string(min_x) +
234+
" -> digit " + std::to_string(best_digit) +
235+
" (RMSD=" + std::to_string(best_rmsd) + ")"
236+
);
231237
// Save crop with prefix so level and stat crops are distinguishable.
232238
crop.save("DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) +
233239
"_match" + std::to_string(best_digit) + ".png");
@@ -240,8 +246,10 @@ int read_digits_waterfill_template(Logger& logger,
240246
}
241247

242248
int number = std::atoi(result_str.c_str());
243-
logger.log("DigitReader: \"" + result_str + "\" -> " +
244-
std::to_string(number));
249+
logger.log(
250+
"DigitReader: \"" + result_str + "\" -> " +
251+
std::to_string(number)
252+
);
245253
return number;
246254
}
247255

SerialPrograms/Source/PokemonFRLG/Inference/PokemonFRLG_StatsReader.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int debug_counter = 0;
3131
// Full OCR preprocessing pipeline for GBA pixel fonts.
3232
//
3333
// GBA fonts are seven-segment-like with 1-pixel gaps between segments.
34-
// Pipeline: blur at native smooth upscale BW smooth BW re-BW pad
34+
// Pipeline: blur at native -> smooth upscale -> BW -> smooth BW -> re-BW -> pad
3535
//
3636
// The native blur connects gaps. Post-BW padding provides margins.
3737
static ImageRGB32 preprocess_for_ocr(
@@ -52,8 +52,8 @@ static ImageRGB32 preprocess_for_ocr(
5252

5353
cv::Mat src = image.to_opencv_Mat();
5454

55-
// Step 1: Gaussian blur at NATIVE resolution with 5×5 kernel.
56-
// The 5×5 kernel reaches 2 pixels away (vs 1px for 3×3), bridging
55+
// Step 1: Gaussian blur at NATIVE resolution with 5x5 kernel.
56+
// The 5x5 kernel reaches 2 pixels away (vs 1px for 3x3), bridging
5757
// wider gaps in the seven-segment font. Two passes for heavy smoothing.
5858
cv::Mat blurred_native;
5959
src.copyTo(blurred_native);
@@ -73,7 +73,7 @@ static ImageRGB32 preprocess_for_ocr(
7373
blurred_native_img.save(prefix + "_1_blurred_native.png");
7474
}
7575

76-
// Step 2: Smooth upscale with bilinear interpolation.
76+
// Step 2: Smooth upscale 4x with bilinear interpolation.
7777
int scale_factor = 4;
7878
int new_w = static_cast<int>(image.width()) * scale_factor;
7979
int new_h = static_cast<int>(image.height()) * scale_factor;
@@ -97,7 +97,7 @@ static ImageRGB32 preprocess_for_ocr(
9797
bw.save(prefix + "_3_bw.png");
9898
}
9999

100-
// Step 4: Post-BW smoothing re-threshold.
100+
// Step 4: Post-BW smoothing -> re-threshold.
101101
// The BW image has angular seven-segment shapes. GaussianBlur on the
102102
// binary image creates gray anti-aliased edges. Re-thresholding at 128
103103
// rounds the corners into natural smooth digit shapes that Tesseract
@@ -109,7 +109,7 @@ static ImageRGB32 preprocess_for_ocr(
109109
// Re-threshold: convert smoothed back to ImageRGB32 and BW threshold.
110110
// After blur on BW: text areas are dark gray (~0-64), bg areas are
111111
// light gray (~192-255), edge zones are mid-gray (~64-192).
112-
// Threshold at [0..128] captures text + expanded edges BLACK.
112+
// Threshold at [0..128] captures text + expanded edges -> BLACK.
113113
ImageRGB32 smoothed_img(smoothed.cols, smoothed.rows);
114114
smoothed.copyTo(smoothed_img.to_opencv_Mat());
115115
ImageRGB32 smooth_bw = to_blackwhite_rgb32_range(
@@ -211,8 +211,8 @@ void StatsReader::read_page1(
211211

212212
if (!GlobalSettings::instance().USE_PADDLE_OCR) {
213213
// The level uses white text with dark shadow on a lilac background.
214-
// The digit reader's binarizer captures dark pixels (190 on all channels)
215-
// but NOT the white text (all channels 255 excluded). This leaves the
214+
// The digit reader's binarizer captures dark pixels (<=190 on all channels)
215+
// but NOT the white text (all channels 255 -> excluded). This leaves the
216216
// shadow outline fragmented into many small disconnected blobs.
217217
// Preprocess: convert bright-white text pixels to black so the binarizer
218218
// merges text + shadow into one solid connected blob per digit.
@@ -222,7 +222,7 @@ void StatsReader::read_page1(
222222
if (save_debug_images) {
223223
preprocessed.save("DebugDumps/ocr_level_preprocessed.png");
224224
}
225-
// Trim left 7% to exclude the "L" glyph blob (always at x0).
225+
// Trim left 7% to exclude the "L" glyph blob (always at x~0).
226226
// The actual level digits start at ~13%+ of the box width.
227227
size_t lv_skip = preprocessed.width() * 7 / 100;
228228
ImagePixelBox digits_bbox(
@@ -245,27 +245,27 @@ void StatsReader::read_page1(
245245
}
246246

247247
// Read Nature (black text on white/beige).
248-
// Pipeline: BW invert morph close invert upscale smooth pad.
248+
// Pipeline: BW -> invert -> morph close -> invert -> upscale -> smooth -> pad.
249249
// Morph close on the inverted image (text=white) bridges gaps in text
250-
// regions by growing whiteeroding back. Works per-channel on CV_8UC4.
250+
// regions by growing white->eroding back. Works per-channel on CV_8UC4.
251251
const static Pokemon::NatureReader reader("Pokemon/NatureCheckerOCR.json");
252252
ImageViewRGB32 nature_raw = extract_box_reference(game_screen, m_box_nature);
253253
if (save_debug_images) {
254254
nature_raw.save("DebugDumps/ocr_nature_0_raw.png");
255255
}
256256

257-
// Step 1: BW at native resolution. Dark text [0..150] black.
257+
// Step 1: BW at native resolution. Dark text [0..150] -> black.
258258
ImageRGB32 nature_bw = to_blackwhite_rgb32_range(
259259
nature_raw, true,
260260
combine_rgb(0, 0, 0), combine_rgb(150, 150, 150));
261261
if (save_debug_images) {
262262
nature_bw.save("DebugDumps/ocr_nature_1_bw.png");
263263
}
264264

265-
// Step 2: Invert MORPH_CLOSE Invert to bridge gaps.
265+
// Step 2: Invert -> MORPH_CLOSE -> Invert to bridge gaps.
266266
// On the inverted image, text is bright (255) and bg is dark (0).
267267
// MORPH_CLOSE (dilate then erode) fills small dark holes within
268-
// the bright text regions exactly the 1px gaps we need to bridge.
268+
// the bright text regions - exactly the 1px gaps we need to bridge.
269269
// A 3x3 kernel bridges 1px gaps. Two iterations bridges 2px gaps.
270270
{
271271
cv::Mat bw_mat = nature_bw.to_opencv_Mat();
@@ -396,15 +396,15 @@ void StatsReader::read_page2(
396396
}
397397

398398
// PaddleOCR path (original): preprocess then per-digit waterfill OCR.
399-
// Dark text [0..190] black. Threshold at 190 captures the
399+
// Dark text [0..190] -> black. Threshold at 190 captures the
400400
// blurred gap pixels between segments, making bridges thicker.
401401
// Not higher than 190 to avoid capturing yellow bg edge noise.
402402
ImageRGB32 ocr_ready = preprocess_for_ocr(
403403
stat_region, name, 7, 2, true,
404404
combine_rgb(0, 0, 0), combine_rgb(190, 190, 190)
405405
);
406406

407-
// Waterfill isolates each digit per-char SINGLE_CHAR OCR.
407+
// Waterfill isolates each digit -> per-char SINGLE_CHAR OCR.
408408
return OCR::read_number_waterfill(
409409
logger, ocr_ready, 0xff000000,
410410
0xff808080

0 commit comments

Comments
 (0)