Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ ImageRGB32 preprocess_for_ocr(
const std::string &label,
int blur_kernel_size, int blur_passes,
bool in_range_black, uint32_t bw_min,
uint32_t bw_max
uint32_t bw_max,
bool save_debug_images
){
const bool save_debug_images = GlobalSettings::instance().SAVE_DEBUG_IMAGES;
int id = debug_counter++;
std::string prefix = "DebugDumps/ocr_" + label + "_" + std::to_string(id);

Expand Down Expand Up @@ -203,7 +203,8 @@ int read_digits_waterfill_template(
double rmsd_threshold,
DigitTemplateType template_type,
const std::string& dump_prefix,
uint8_t binarize_high
uint8_t binarize_high,
bool save_debug_images
){
using namespace Kernels::Waterfill;

Expand Down Expand Up @@ -305,7 +306,7 @@ int read_digits_waterfill_template(
ImagePixelBox bbox(min_x, obj.min_y, max_x, obj.max_y);
ImageViewRGB32 crop = extract_box_reference(stat_region, bbox);

if (dump_prefix == "levelDigit"){
if (save_debug_images && dump_prefix == "levelDigit"){
crop.save("DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) + "_split_raw.png");
}

Expand All @@ -327,9 +328,11 @@ int read_digits_waterfill_template(

if (best_rmsd > rmsd_threshold){
// Always save the raw crop for user inspection / template extraction.
crop.save(
"DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) + "_raw.png"
);
if (save_debug_images){
crop.save(
"DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) + "_raw.png"
);
}
logger.log(
"DigitReader: blob at x=" + std::to_string(min_x) +
" skipped (best RMSD=" + std::to_string(best_rmsd) +
Expand All @@ -345,10 +348,12 @@ int read_digits_waterfill_template(
" (RMSD=" + std::to_string(best_rmsd) + ")"
);
// Save crop with prefix so level and stat crops are distinguishable.
crop.save(
"DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) +
"_match" + std::to_string(best_digit) + ".png"
);
if (save_debug_images){
crop.save(
"DebugDumps/" + dump_prefix + "_x" + std::to_string(min_x) +
"_match" + std::to_string(best_digit) + ".png"
);
}
result_str += static_cast<char>('0' + best_digit);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ ImageRGB32 preprocess_for_ocr(
const std::string &label,
int blur_kernel_size, int blur_passes,
bool in_range_black, uint32_t bw_min,
uint32_t bw_max
uint32_t bw_max,
bool save_debug_images = false
);

// Read a string of decimal digits from `stat_region`.
Expand All @@ -53,27 +54,11 @@ int read_digits_waterfill_template(
double rmsd_threshold = 175.0,
DigitTemplateType template_type = DigitTemplateType::StatBox,
const std::string& dump_prefix = "digit",
uint8_t binarize_high = 0xBE // 0xBE=190 for yellow stat boxes;
uint8_t binarize_high = 0xBE, // 0xBE=190 for yellow stat boxes;
bool save_debug_images = false
// use 0x7F=127 for lilac level box
);

// 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.
//
// num_splits The number of equal-width segments to split the region into.
// template_type Which template set to use (StatBox or LevelBox).
// dump_prefix Prefix used when saving debug crop PNGs to DebugDumps/.
//
// Returns the parsed integer, or -1 on failure.
int read_digits_fixed_width_template(
Logger& logger,
const ImageViewRGB32& stat_region,
int num_splits = 2,
double rmsd_threshold = 175.0,
DigitTemplateType template_type = DigitTemplateType::LevelBox,
const std::string& dump_prefix = "digit_split"
);

} // namespace PokemonFRLG
} // namespace NintendoSwitch
Expand Down
Loading
Loading