Skip to content

Commit f90f9e7

Browse files
committed
Add a proper ambiguous silhouette path.
1 parent 0c66895 commit f90f9e7

File tree

8 files changed

+71
-30
lines changed

8 files changed

+71
-30
lines changed

SerialPrograms/Source/CommonTools/ImageMatch/ImageCropper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ ImagePixelBox enclosing_rectangle_with_pixel_filter(const ImageViewRGB32& image,
5353
size_t cs = 0;
5454
size_t ce = image.width();
5555

56+
// cout << "Before: rs = " << rs << ", re = " << re << ", cs = " << cs << ", ce = " << ce << endl;
57+
5658
// If we cannot find a foreground (aka, alpha != 0) pixel on one row or column, we trim it, until hitting a foreground pixel.
5759
while (rs < re && is_background_row(image, rs , is_foreground)) rs++;
5860
while (re > rs && is_background_row(image, re - 1, is_foreground)) re--;
5961
while (cs < ce && is_background_col(image, cs , is_foreground)) cs++;
6062
while (ce > cs && is_background_col(image, ce - 1, is_foreground)) ce--;
63+
64+
// cout << "After: rs = " << rs << ", re = " << re << ", cs = " << cs << ", ce = " << ce << endl;
65+
6166
return ImagePixelBox(cs, rs, ce, re);
6267
}
6368

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,16 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
375375

376376

377377

378-
// ImageRGB32 image("20250115-110356822901.png");
378+
ImageRGB32 image("20250218-003554940153.png");
379379
// ImageRGB32 image("raidecho1.jpg");
380380
// auto image = feed.snapshot();
381381

382382
// MaxLairInternal::BattleMenuReader reader(overlay, Language::English);
383383
// reader.read_opponent_in_summary(logger, image);
384384

385-
// TeraCardReader reader;
385+
TeraCardReader reader;
386+
cout << reader.detect(image) << endl;
387+
reader.pokemon_slug(logger, env.program_info(), image);
386388
// cout << (int)reader.stars(logger, env.program_info(), image) << endl;
387389

388390

SerialPrograms/Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,28 @@ std::string TeraCardReader::tera_type(
218218

219219
return best_type;
220220
}
221-
std::string TeraCardReader::pokemon_slug(
221+
std::set<std::string> TeraCardReader::pokemon_slug(
222222
Logger& logger, const ProgramInfo& info, const ImageViewRGB32& screen
223223
) const{
224224
ImageMatch::ImageMatchResult silhouette = m_silhouette.read(screen);
225-
silhouette.log(logger, 100);
226-
std::string best_silhouette;
227-
if (!silhouette.results.empty()){
228-
best_silhouette = silhouette.results.begin()->second;
229-
}
225+
silhouette.log(logger, 110);
226+
// std::string best_silhouette;
227+
// if (!silhouette.results.empty()){
228+
// best_silhouette = silhouette.results.begin()->second;
229+
// }
230230
if (silhouette.results.empty()){
231231
dump_image(logger, info, "ReadSilhouetteFailed", screen);
232-
}else if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
233-
dump_debug_image(logger, "PokemonSV/TeraRoller/" + best_silhouette, "", screen);
232+
}
233+
// else if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
234+
// dump_debug_image(logger, "PokemonSV/TeraRoller/" + best_silhouette, "", screen);
235+
// }
236+
237+
std::set<std::string> results;
238+
for (const auto& item : silhouette.results){
239+
results.insert(std::move(item.second));
234240
}
235241

236-
return best_silhouette;
242+
return results;
237243
}
238244

239245

SerialPrograms/Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TeraCardReader : public StaticScreenDetector{
4040
std::string tera_type(
4141
Logger& logger, const ProgramInfo& info, const ImageViewRGB32& screen
4242
) const;
43-
std::string pokemon_slug(
43+
std::set<std::string> pokemon_slug(
4444
Logger& logger, const ProgramInfo& info, const ImageViewRGB32& screen
4545
) const;
4646

SerialPrograms/Source/PokemonSV/Inference/Tera/PokemonSV_TeraSilhouetteReader.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ ImageMatch::ImageMatchResult TeraSilhouetteReader::read(const ImageViewRGB32& sc
6060
225,
6161
};
6262

63+
// static int c = 0;
64+
ImageMatch::ImageMatchResult slugs;
6365
for (uint32_t threshold : BRIGHTNESS_THRESHOLDS){
6466
// cout << "check0" << endl;
6567
// Get a loose crop of the silhouette icon
6668
ImageViewRGB32 cropped_image = extract_box_reference(screen, m_box);
67-
// cropped_image.save("tera_cropped_image.png");
69+
// cropped_image.save("tera_cropped_image-" + std::to_string(c++) + ".png");
6870

6971
// cout << "check1" << endl;
7072
ImageRGB32 preprocessed_image(cropped_image.width(), cropped_image.height());
@@ -88,14 +90,14 @@ ImageMatch::ImageMatchResult TeraSilhouetteReader::read(const ImageViewRGB32& sc
8890

8991
// cout << "check3" << endl;
9092
ImageRGB32 processed_image = extract_box_reference(preprocessed_image, tight_box).copy();
91-
// processed_image.save("tera_processed_image.png");
93+
// processed_image.save("tera_processed_image-" + std::to_string(c++) + ".png");
9294

9395
// cout << "check4" << endl;
9496
ImageRGB32 filtered_image = to_blackwhite_rgb32_range(processed_image, 0xff000000, 0xff5f5f5f, true);
9597
// filtered_image.save("tera_filtered_image.png");
9698

9799
// cout << "check5" << endl;
98-
ImageMatch::ImageMatchResult slugs = TERA_RAID_SILHOUETTE_MATCHER().match(filtered_image, ALPHA_SPREAD);
100+
slugs = TERA_RAID_SILHOUETTE_MATCHER().match(filtered_image, ALPHA_SPREAD);
99101
slugs.clear_beyond_alpha(MAX_ALPHA);
100102

101103
// slugs.log(global_logger_tagged(), MAX_ALPHA);
@@ -105,7 +107,7 @@ ImageMatch::ImageMatchResult TeraSilhouetteReader::read(const ImageViewRGB32& sc
105107
}
106108
}
107109

108-
return ImageMatch::ImageMatchResult();
110+
return slugs;
109111
}
110112

111113

SerialPrograms/Source/PokemonSV/Options/PokemonSV_TeraRollFilter.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
*
55
*/
66

7-
//#include "Common/Cpp/Exceptions.h"
7+
#include <algorithm>
8+
#include "Common/Cpp/PrettyPrint.h"
89
#include "CommonFramework/VideoPipeline/VideoFeed.h"
9-
//#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10-
//#include "CommonFramework/Tools/DebugDumper.h"
1110
#include "CommonFramework/Tools/ErrorDumper.h"
1211
#include "Pokemon/Pokemon_Strings.h"
1312
#include "PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.h"
@@ -172,9 +171,15 @@ void TeraRollFilter::read_card(
172171
std::string tera_type = data.tera_type.empty()
173172
? "? tera"
174173
: data.tera_type;
175-
std::string pokemon = data.species.empty()
176-
? "? " + Pokemon::STRING_POKEMON
177-
: data.species;
174+
175+
std::string pokemon;
176+
if (data.species.empty()){
177+
pokemon = "unknown " + Pokemon::STRING_POKEMON;
178+
}else if (data.species.size() == 1){
179+
pokemon = *data.species.begin();
180+
}else{
181+
pokemon = set_to_str(data.species);
182+
}
178183

179184
stream.overlay().add_log(
180185
stars + "* " + tera_type + " " + pokemon,
@@ -183,7 +188,7 @@ void TeraRollFilter::read_card(
183188
std::string log = "Detected a " + stars + "* " + tera_type + " " + pokemon;
184189
stream.log(log);
185190
}
186-
bool TeraRollFilter::check_herba(const std::string& pokemon_slug) const{
191+
bool TeraRollFilter::check_herba(const std::set<std::string>& pokemon_slugs) const{
187192
if (!SKIP_NON_HERBA){
188193
return true;
189194
}
@@ -197,10 +202,23 @@ bool TeraRollFilter::check_herba(const std::string& pokemon_slug) const{
197202
"poliwrath", "snorlax", "basculegion"
198203
};
199204

200-
if (fivestar.find(pokemon_slug) != fivestar.end()){
205+
std::set<std::string> fivestar_compatible;
206+
std::set_intersection(
207+
fivestar_compatible.begin(), fivestar_compatible.end(),
208+
pokemon_slugs.begin(), pokemon_slugs.end(),
209+
std::inserter(fivestar_compatible, fivestar_compatible.begin())
210+
);
211+
if (!fivestar_compatible.empty()){
201212
return true;
202213
}
203-
if (sixstar.find(pokemon_slug) != sixstar.end()){
214+
215+
std::set<std::string> sixstar_compatible;
216+
std::set_intersection(
217+
sixstar_compatible.begin(), sixstar_compatible.end(),
218+
pokemon_slugs.begin(), pokemon_slugs.end(),
219+
std::inserter(sixstar_compatible, sixstar_compatible.begin())
220+
);
221+
if (!sixstar_compatible.empty()){
204222
return true;
205223
}
206224

SerialPrograms/Source/PokemonSV/Options/PokemonSV_TeraRollFilter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PokemonAutomation_PokemonSV_TeraRollFilter_H
88
#define PokemonAutomation_PokemonSV_TeraRollFilter_H
99

10+
#include <set>
1011
#include "Common/Cpp/Options/GroupOption.h"
1112
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1213
#include "Common/Cpp/Options/SimpleIntegerOption.h"
@@ -37,7 +38,7 @@ struct TeraRaidData{
3738

3839
uint8_t stars = 0;
3940
std::string tera_type;
40-
std::string species;
41+
std::set<std::string> species;
4142
};
4243

4344

@@ -65,7 +66,7 @@ class TeraRollFilter : public GroupOption{
6566
const ProgramInfo& info, VideoStream& stream, const ImageViewRGB32& screen,
6667
TeraCardReader& reader, TeraRaidData& data
6768
) const;
68-
bool check_herba(const std::string& pokemon_slug) const;
69+
bool check_herba(const std::set<std::string>& pokemon_slugs) const;
6970

7071
public:
7172
enum class EventCheckMode{

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraSelfFarmer.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <sstream>
88
#include "Common/Cpp/Exceptions.h"
9+
#include "Common/Cpp/PrettyPrint.h"
910
#include "CommonFramework/Notifications/ProgramNotifications.h"
1011
#include "CommonFramework/ProgramStats/StatsTracking.h"
1112
#include "CommonFramework/VideoPipeline/VideoFeed.h"
@@ -308,9 +309,15 @@ void TeraSelfFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerC
308309
std::string tera_type = raid_data.tera_type.empty()
309310
? "unknown tera type"
310311
: raid_data.tera_type;
311-
std::string pokemon = raid_data.species.empty()
312-
? "unknown " + Pokemon::STRING_POKEMON
313-
: raid_data.species;
312+
313+
std::string pokemon;
314+
if (raid_data.species.empty()){
315+
pokemon = "unknown " + Pokemon::STRING_POKEMON;
316+
}else if (raid_data.species.size() == 1){
317+
pokemon = *raid_data.species.begin();
318+
}else{
319+
pokemon = set_to_str(raid_data.species);
320+
}
314321

315322
ss << " a " << stars << "* " << tera_type << " " << pokemon << " raid";
316323
env.log(ss.str());

0 commit comments

Comments
 (0)