Skip to content

Commit bbf07a5

Browse files
committed
Switch2: Fix false positive Home menu detection on user select screen.
1 parent 2f087d1 commit bbf07a5

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 54;
29-
const int PROGRAM_VERSION_PATCH = 5;
29+
const int PROGRAM_VERSION_PATCH = 6;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,16 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
287287

288288

289289

290+
290291
#if 1
291-
// HomeMenuDetector detector0(console);
292-
// StartGameUserSelectDetector detector1(console);
292+
HomeMenuDetector detector0(console);
293+
StartGameUserSelectDetector detector1(console);
293294
UpdatePopupDetector detector2(console);
294-
// detector0.make_overlays(overlays);
295-
// detector1.make_overlays(overlays);
295+
detector0.make_overlays(overlays);
296+
detector1.make_overlays(overlays);
296297
detector2.make_overlays(overlays);
298+
cout << detector0.detect(feed.snapshot()) << endl;
299+
cout << detector1.detect(feed.snapshot()) << endl;
297300
cout << detector2.detect(feed.snapshot()) << endl;
298301
#endif
299302

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include "CommonTools/Images/SolidColorTest.h"
99
#include "NintendoSwitch_HomeMenuDetector.h"
1010

11+
//#include <iostream>
12+
//using std::cout;
13+
//using std::endl;
14+
1115
namespace PokemonAutomation{
1216
namespace NintendoSwitch{
1317

@@ -17,6 +21,7 @@ namespace NintendoSwitch{
1721
HomeMenuDetector::HomeMenuDetector(ConsoleHandle& console, Color color)
1822
: m_color(color)
1923
, m_console_type(console, color)
24+
, m_top(0.510223, 0.019835, 0.441450, 0.034711)
2025
, m_bottom_row(0.10, 0.92, 0.10, 0.05)
2126
, m_bottom_icons(0.70, 0.92, 0.28, 0.05)
2227
, m_bottom_left(0.02, 0.70, 0.15, 0.15)
@@ -26,6 +31,7 @@ HomeMenuDetector::HomeMenuDetector(ConsoleHandle& console, Color color)
2631
{}
2732
void HomeMenuDetector::make_overlays(VideoOverlaySet& items) const{
2833
m_console_type.make_overlays(items);
34+
items.add(m_color, m_top);
2935
items.add(m_color, m_bottom_row);
3036
items.add(m_color, m_bottom_icons);
3137
items.add(m_color, m_bottom_left);
@@ -60,6 +66,12 @@ bool HomeMenuDetector::detect_only(const ImageViewRGB32& screen){
6066

6167
// cout << "white: " << white << endl;
6268

69+
ImageStats stats_top = image_stats(extract_box_reference(screen, m_top));
70+
// cout << stats_top.average << stats_top.stddev << endl;
71+
if (stats_top.stddev.sum() > 20){
72+
return false;
73+
}
74+
6375
ImageStats stats_bottom_icons = image_stats(extract_box_reference(screen, m_bottom_icons));
6476
// cout << stats_bottom_icons.average << stats_bottom_icons.stddev << endl;
6577
if (stats_bottom_icons.stddev.sum() < 50){
@@ -97,6 +109,11 @@ bool HomeMenuDetector::detect_only(const ImageViewRGB32& screen){
97109
// cout << "zxcv" << endl;
98110
return false;
99111
}
112+
// cout << euclidean_distance(stats_top.average, stats_bottom_left.average) << endl;
113+
if (euclidean_distance(stats_top.average, stats_bottom_left.average) > 20){
114+
// cout << "xcvb" << endl;
115+
return false;
116+
}
100117

101118
ImageStats stats_user_icons = image_stats(extract_box_reference(screen, m_user_icons));
102119
// cout << stats_user_icons.stddev << endl;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class HomeMenuDetector : public StaticScreenDetector{
2929
private:
3030
Color m_color;
3131
ConsoleTypeDetector_Home m_console_type;
32+
ImageFloatBox m_top;
3233
ImageFloatBox m_bottom_row;
3334
ImageFloatBox m_bottom_icons;
3435
ImageFloatBox m_bottom_left;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen){
4040
}
4141
bool StartGameUserSelectDetector::detect_only(const ImageViewRGB32& screen){
4242
ConsoleType type = m_type_detector.detect_only(screen);
43-
// cout << "detection: " << (int)x << endl;
4443
m_console_type = type;
4544

4645
if (type == ConsoleType::Unknown){

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_ConsoleState.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ void ConsoleState::set_console_type(Logger& logger, ConsoleType type){
134134

135135
}while (false);
136136

137-
logger.log(std::string("Setting console type to: ") + ConsoleType_strings(type));
137+
logger.log(
138+
std::string("Setting console type to: ") + ConsoleType_strings(type),
139+
COLOR_BLUE
140+
);
138141

139142
m_data->m_console_type.store(type, std::memory_order_relaxed);
140143
m_data->m_console_type_confirmed.store(true, std::memory_order_relaxed);

0 commit comments

Comments
 (0)