Skip to content

Commit 63c1e60

Browse files
committed
Improve AutoDA name-read disambiguation tolerance.
1 parent b52b096 commit 63c1e60

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
#include "PokemonLA/Inference/Map/PokemonLA_OutbreakReader.h"
126126
#include "PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.h"
127127
#include "PokemonLA/Inference/Objects/PokemonLA_MMOQuestionMarkDetector.h"
128-
128+
//#include "PokemonSwSh/Inference/Battles/PokemonSwSh_BattleMenuDetector.h"
129+
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h"
129130

130131

131132
#include <QPixmap>
@@ -278,8 +279,12 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
278279
VideoOverlaySet overlays(overlay);
279280

280281

282+
PokemonSwSh::MaxLairInternal::BattleMenuReader reader(console, Language::Korean);
283+
284+
ImageRGB32 image("20241220-161934162025.png");
285+
286+
reader.read_opponent_in_summary(logger, image);
281287

282-
// ImageRGB32 image("Screenshot.png");
283288
// PokemonSwSh::find_selection_arrows(image, 10);
284289

285290

@@ -331,7 +336,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
331336
);
332337
#endif
333338

334-
#if 1
339+
#if 0
335340
VideoSnapshot image = feed.snapshot();
336341
// ImageRGB32 image("screenshot-20241124-135028529403.png");
337342

SerialPrograms/Source/Pokemon/Inference/Pokemon_NameReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ OCR::StringMatchResult PokemonNameReader::read_substring(
2929
Language language,
3030
const ImageViewRGB32& image,
3131
const std::vector<OCR::TextColorRange>& text_color_ranges,
32-
double min_text_ratio, double max_text_ratio
32+
double min_text_ratio, double max_text_ratio,
33+
double max_log10p
3334
) const{
3435
return match_substring_from_image_multifiltered(
3536
&logger, language, image, text_color_ranges,
36-
MAX_LOG10P, MAX_LOG10P_SPREAD, min_text_ratio, max_text_ratio
37+
max_log10p, MAX_LOG10P_SPREAD, min_text_ratio, max_text_ratio
3738
);
3839
}
3940

SerialPrograms/Source/Pokemon/Inference/Pokemon_NameReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class PokemonNameReader : public OCR::LargeDictionaryMatcher{
3131
Language language,
3232
const ImageViewRGB32& image,
3333
const std::vector<OCR::TextColorRange>& text_color_ranges,
34-
double min_text_ratio = 0.01, double max_text_ratio = 0.50
34+
double min_text_ratio = 0.01, double max_text_ratio = 0.50,
35+
double max_log10p = MAX_LOG10P
3536
) const;
3637

3738
};

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,30 +254,36 @@ std::set<std::string> BattleMenuReader::read_opponent(
254254
}
255255
std::set<std::string> BattleMenuReader::read_opponent_in_summary(Logger& logger, const ImageViewRGB32& screen) const{
256256
ImageViewRGB32 name = extract_box_reference(screen, m_summary_opponent_name);
257-
std::set<std::string> slugs = read_pokemon_name(logger, m_language, name);
257+
258+
// We can use a weaker threshold here since we are cross-checking with the type.
259+
std::set<std::string> slugs = read_pokemon_name(logger, m_language, name, -1.0);
258260

259261
ImageViewRGB32 types = extract_box_reference(screen, m_summary_opponent_types);
260262
std::multimap<double, std::pair<PokemonType, ImagePixelBox>> candidates = find_symbols(types, 0.2);
261-
// for (const auto& item : candidates){
262-
// cout << get_type_slug(item.second.first) << ": " << item.first << endl;
263-
// }
263+
264+
std::string type_str = "Type Read Result:\n";
265+
for (const auto& item : candidates){
266+
type_str += " " + get_type_slug(item.second.first) + " : " + tostr_default(item.first ) + "\n";
267+
}
268+
logger.log(type_str);
264269

265270
PokemonType type0 = PokemonType::NONE;
266271
PokemonType type1 = PokemonType::NONE;
267272
{
268273
auto iter = candidates.begin();
269274
if (iter != candidates.end()){
270275
type0 = iter->second.first;
271-
iter++;
276+
++iter;
272277
}
273278
if (iter != candidates.end()){
274279
type1 = iter->second.first;
275-
iter++;
280+
++iter;
276281
}
277282
}
278283

279284
for (auto iter = slugs.begin(); iter != slugs.end();){
280285
const MaxLairMon& mon = get_maxlair_mon(*iter);
286+
// cout << mon.species << endl;
281287
if ((type0 == mon.type[0] && type1 == mon.type[1]) || (type0 == mon.type[1] && type1 == mon.type[0])){
282288
++iter;
283289
}else{

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonReader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@ std::string read_boss_sprite(ConsoleHandle& console){
108108

109109
std::set<std::string> read_pokemon_name(
110110
Logger& logger, Language language,
111-
const ImageViewRGB32& image
111+
const ImageViewRGB32& image,
112+
double max_log10p
112113
){
113114
const SpeciesReadDatabase& database = SpeciesReadDatabase::instance();
114115

115116
// OCR::MatchResult result = PokemonNameReader::instance().read_substring(language, image);
116117
// image.save("test.png");
117118
OCR::StringMatchResult result = database.name_reader->read_substring(
118119
logger, language, image,
119-
OCR::BLACK_OR_WHITE_TEXT_FILTERS()
120+
OCR::BLACK_OR_WHITE_TEXT_FILTERS(),
121+
0.01, 0.50,
122+
max_log10p
120123
);
121124
// result.log(logger);
122125
if (result.results.empty()){

SerialPrograms/Source/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ std::string read_boss_sprite(ConsoleHandle& console);
2424
// OCR the Pokemon name and return all possible candidates.
2525
std::set<std::string> read_pokemon_name(
2626
Logger& logger, Language language,
27-
const ImageViewRGB32& image
27+
const ImageViewRGB32& image,
28+
double max_log10p = -1.4
2829
);
2930

3031

0 commit comments

Comments
 (0)