Skip to content

Commit 5ccce65

Browse files
author
Gin
committed
Finish overworld party selection detector
1 parent a1547a9 commit 5ccce65

File tree

8 files changed

+93
-14
lines changed

8 files changed

+93
-14
lines changed

SerialPrograms/Scripts/check_detector_regions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@
3636
# LZA overworld party selection buttons
3737
for i in range(6):
3838
# loctions for the dpad up buttons to send party pokemon from ball to outside
39-
add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.954, 0.017, 0.030, image)
39+
# add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.954, 0.017, 0.030, image)
4040
# locations for the dpad down buttons to retrieve outside pokemon back to ball while
4141
# current party selection is on another in-ball pokemon
42-
add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.926, 0.017, 0.030, image)
42+
# add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.926, 0.017, 0.030, image)
4343
# locations for the dpad down buttons to retrieve outside pokemon back to ball while
4444
# current party selection is this outside pokemon. In this case, dpad up button is not
4545
# present.
46-
add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.939, 0.017, 0.030, image)
46+
# add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.939, 0.017, 0.030, image)
47+
48+
add_infer_box_to_image(raw_image, 0.048 + 0.0398*i, 0.926, 0.017, 0.058, image)
4749

4850

4951
# ==================================================================

SerialPrograms/Source/CommonTools/Images/WaterfillUtilities.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ bool match_template_by_waterfill(
8383
std::function<bool(Kernels::Waterfill::WaterfillObject& object)> check_matched_object)
8484
{
8585
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
86+
std::cout << "============ match_template_by_waterfill ============" << std::endl;
8687
dump_debug_image(
8788
global_logger_command_line(),
8889
"CommonFramework/WaterfillTemplateMatcher",
8990
"match_template_by_waterfill_input_image",
9091
image
9192
);
92-
std::cout << "Match template by waterfill, " << filters.size() << " filter(s), size range ("
93+
std::cout << "Use " << filters.size() << " filter(s), size range ("
9394
<< area_thresholds.first << ", ";
9495
if (area_thresholds.second == SIZE_MAX){
9596
std::cout << "SIZE_MAX";
@@ -131,7 +132,7 @@ bool match_template_by_waterfill(
131132

132133
// cout << "object.area = " << object.area << endl;
133134
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
134-
std::cout << "------------" << std::endl;
135+
std::cout << "------------ Matching One WaterfillObject ------------" << std::endl;
135136
std::cout << "Object area: " << object.area << std::endl;
136137
}
137138

@@ -140,7 +141,8 @@ bool match_template_by_waterfill(
140141
}
141142
double rmsd = matcher.rmsd_original(input_resolution, image, object);
142143
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
143-
std::cout << "Object rmsd: " << rmsd << std::endl;
144+
std::cout << "Final rmsd: " << rmsd << " vs " << rmsd_threshold << std::endl;
145+
std::cout << "------------ End of Matching one WaterfillObject ------------" << std::endl;
144146
}
145147

146148
// std::cout << "Object rmsd: " << rmsd << std::endl;
@@ -166,7 +168,7 @@ bool match_template_by_waterfill(
166168
}
167169
}
168170
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
169-
std::cout << "End match template by waterfill" << std::endl;
171+
std::cout << "============ End of match_template_by_waterfill ============" << std::endl;
170172
}
171173
return detected;
172174
}

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool BoxDetector::detect(const ImageViewRGB32& screen){
188188
if (arrow_found && m_debug_mode){
189189
cout << "Multiple box selection arrows detected! First detection (" << int(m_found_row) << ", " << int(m_found_col) << ")"
190190
<< " second detection (" << int(row) << ", " << int(col) << ")" << endl;
191-
throw FatalProgramException(ErrorReport::SEND_ERROR_REPORT,
191+
throw FatalProgramException(ErrorReport::NO_ERROR_REPORT,
192192
"Multiple box selection arrows detected!", nullptr, screen.copy());
193193
}
194194
arrow_found = true;

SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_ButtonDetector.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
1111
#include "PokemonLZA_ButtonDetector.h"
1212

13-
//#include <iostream>
14-
//using std::cout;
15-
//using std::endl;
13+
// #include <iostream>
14+
// using std::cout;
15+
// using std::endl;
1616

1717
namespace PokemonAutomation{
1818
namespace NintendoSwitch{
@@ -67,17 +67,19 @@ class ButtonMatcher : public ImageMatch::WaterfillTemplateMatcher{
6767
return matcher;
6868
}
6969
static const ButtonMatcher& DpadUp(){
70-
static ButtonMatcher matcher(ButtonType::ButtonDpadUp, 50, 50, 70);
70+
static ButtonMatcher matcher(ButtonType::ButtonDpadUp, 30, 30, 80);
7171
return matcher;
7272
}
7373
static const ButtonMatcher& DpadDown(){
74-
static ButtonMatcher matcher(ButtonType::ButtonDpadDown, 50, 50, 70);
74+
static ButtonMatcher matcher(ButtonType::ButtonDpadDown, 30, 30, 80);
7575
return matcher;
7676
}
7777

7878
virtual bool check_image(Resolution input_resolution, const ImageViewRGB32& image) const override{
7979
size_t min_width = m_min_width * input_resolution.width / 3840;
8080
size_t min_height = m_min_height * input_resolution.height / 2160;
81+
// cout << "???? check_image() ???? min size " << min_width << " x " << min_height
82+
// << " got " << image.width() << " x " << image.height() << endl;
8183
return image.width() >= min_width && image.height() >= min_height;
8284
};
8385

SerialPrograms/Source/Tests/PokemonLZA_Tests.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h"
1616
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h"
1717
#include "PokemonLZA/Inference/PokemonLZA_MapIconDetector.h"
18+
#include "PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h"
1819
#include "CommonFramework/ImageTools/ImageBoxes.h"
1920
#include <iostream>
2021
#include <fstream>
@@ -393,5 +394,72 @@ int test_pokemonLZA_MapIconDetector(const std::string& filepath){
393394
return 0;
394395
}
395396

397+
int test_pokemonLZA_OverworldPartySelectionDetector(const ImageViewRGB32& image, const std::vector<std::string>& words){
398+
// Expected filename format: <...>_<dpad_up_idx>_<dpad_down_idx>.png
399+
// Where indices are 0-5 for party positions, or 6 for INVALID_PARTY_IDX
400+
// Examples:
401+
// test_0_1.png -> dpad_up_idx = 0, dpad_down_idx = 1
402+
// test_6_2.png -> dpad_up_idx = 6 (INVALID), dpad_down_idx = 2
403+
// test_1_6.png -> dpad_up_idx = 1, dpad_down_idx = 6 (INVALID)
404+
405+
if (words.size() < 2){
406+
cerr << "Error: filename must have at least 2 words (dpad_up_idx, dpad_down_idx)." << endl;
407+
return 1;
408+
}
409+
410+
// Parse dpad_up_idx from second-to-last word
411+
int expected_up_idx;
412+
if (parse_int(words[words.size() - 2], expected_up_idx) == false){
413+
cerr << "Error: second-to-last word in filename should be dpad_up_idx (0-6)." << endl;
414+
return 1;
415+
}
416+
if (expected_up_idx < 0 || expected_up_idx > 6){
417+
cerr << "Error: dpad_up_idx must be between 0 and 6, got " << expected_up_idx << "." << endl;
418+
return 1;
419+
}
420+
421+
// Parse dpad_down_idx from last word
422+
int expected_down_idx;
423+
if (parse_int(words[words.size() - 1], expected_down_idx) == false){
424+
cerr << "Error: last word in filename should be dpad_down_idx (0-6)." << endl;
425+
return 1;
426+
}
427+
if (expected_down_idx < 0 || expected_down_idx > 6){
428+
cerr << "Error: dpad_down_idx must be between 0 and 6, got " << expected_down_idx << "." << endl;
429+
return 1;
430+
}
431+
432+
// Run detector
433+
auto overlay = DummyVideoOverlay();
434+
OverworldPartySelectionDetector detector(COLOR_RED, &overlay);
435+
detector.set_debug_mode(true);
436+
bool detected = detector.detect(image);
437+
438+
// Check if detection matches expectations
439+
uint8_t detected_up_idx = detector.dpad_up_idx();
440+
uint8_t detected_down_idx = detector.dpad_down_idx();
441+
442+
// If both expected indices are INVALID_PARTY_IDX (6), detection should fail
443+
if (expected_up_idx == 6 && expected_down_idx == 6){
444+
if (detected){
445+
cerr << "Error: detector should not detect anything when both indices are INVALID." << endl;
446+
return 1;
447+
}
448+
TEST_RESULT_EQUAL(detected, false);
449+
return 0;
450+
}
451+
452+
// Otherwise, detection should succeed
453+
if (!detected){
454+
cerr << "Error: detector failed to detect party selection screen." << endl;
455+
return 1;
456+
}
457+
458+
TEST_RESULT_COMPONENT_EQUAL((int)detected_up_idx, expected_up_idx, "dpad_up_idx");
459+
TEST_RESULT_COMPONENT_EQUAL((int)detected_down_idx, expected_down_idx, "dpad_down_idx");
460+
461+
return 0;
462+
}
463+
396464

397465
}

SerialPrograms/Source/Tests/PokemonLZA_Tests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
int test_pokemonLZA_MapIconDetector(const std::string& filepath);
4141

42+
int test_pokemonLZA_OverworldPartySelectionDetector(const ImageViewRGB32& image, const std::vector<std::string>& words);
43+
4244
}
4345

4446
#endif

SerialPrograms/Source/Tests/TestMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ const std::map<std::string, TestFunction> TEST_MAP = {
298298
{"PokemonLZA_BoxCellInfoDetector", std::bind(image_words_detector_helper, test_pokemonLZA_BoxCellInfoDetector, _1)},
299299
{"PokemonLZA_SelectionArrowDetector", std::bind(image_words_detector_helper, test_pokemonLZA_SelectionArrowDetector, _1)},
300300
{"PokemonLZA_MapIconDetector", test_pokemonLZA_MapIconDetector},
301+
{"PokemonLZA_OverworldPartySelectionDetector", std::bind(image_words_detector_helper, test_pokemonLZA_OverworldPartySelectionDetector, _1)},
301302
};
302303

303304
TestFunction find_test_function(const std::string& test_space, const std::string& test_name){

SerialPrograms/SourceFiles.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ file(GLOB LIBRARY_SOURCES
10391039
Source/NintendoSwitch/Options/TurboMacroTable.h
10401040
Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp
10411041
Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h
1042+
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch2_DateSkippers.cpp
10421043
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.cpp
10431044
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h
10441045
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManipBase.h
@@ -1050,7 +1051,6 @@ file(GLOB LIBRARY_SOURCES
10501051
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip_US.h
10511052
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateSkippers.cpp
10521053
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateSkippers.h
1053-
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch2_DateSkippers.cpp
10541054
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch1_HomeToDateTime.cpp
10551055
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch2_HomeToDateTime.cpp
10561056
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.cpp
@@ -1570,6 +1570,8 @@ file(GLOB LIBRARY_SOURCES
15701570
Source/PokemonLZA/Inference/PokemonLZA_MapIconDetector.h
15711571
Source/PokemonLZA/Inference/PokemonLZA_MoveEffectivenessSymbol.cpp
15721572
Source/PokemonLZA/Inference/PokemonLZA_MoveEffectivenessSymbol.h
1573+
Source/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.cpp
1574+
Source/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h
15731575
Source/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.cpp
15741576
Source/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h
15751577
Source/PokemonLZA/Options/PokemonLZA_ShinyDetectedAction.cpp

0 commit comments

Comments
 (0)