Skip to content

Commit 9b29e5f

Browse files
committed
Switch 2 update menu detector.
1 parent 9cf3c44 commit 9b29e5f

12 files changed

+440
-110
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,16 @@ file(GLOB MAIN_SOURCES
953953
Source/NintendoSwitch/Framework/UI/NintendoSwitch_SingleSwitchProgramWidget.h
954954
Source/NintendoSwitch/Framework/UI/NintendoSwitch_SwitchSystemWidget.cpp
955955
Source/NintendoSwitch/Framework/UI/NintendoSwitch_SwitchSystemWidget.h
956+
Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.cpp
957+
Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h
956958
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp
957959
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h
958960
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.cpp
959961
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.h
960962
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.cpp
961963
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h
964+
Source/NintendoSwitch/Inference/NintendoSwitch_UpdateMenuDetector.cpp
965+
Source/NintendoSwitch/Inference/NintendoSwitch_UpdateMenuDetector.h
962966
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp
963967
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.h
964968
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp

SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class VideoSourceDescriptor_StillImage : public VideoSourceDescriptor{
3838

3939
virtual bool operator==(const VideoSourceDescriptor& x) const override;
4040
virtual std::string display_name() const override{
41-
return "Display a Still Image";
41+
return "Display Image";
4242
}
4343

4444
virtual void run_post_select() override;

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
#include "CommonTools/Images/ImageFilter.h"
124124
#include "NintendoSwitch/Options/NintendoSwitch_ModelType.h"
125125
#include "NintendoSwitch/Programs/NintendoSwitch_Navigation.h"
126+
#include "NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h"
127+
#include "NintendoSwitch/Inference/NintendoSwitch_UpdateMenuDetector.h"
126128

127129
#include <QPixmap>
128130
#include <QVideoFrame>
@@ -318,8 +320,21 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
318320
VideoOverlaySet overlays(overlay);
319321

320322

323+
#if 0
324+
ConsoleTypeDetector_Home detector;
325+
detector.make_overlays(overlays);
326+
327+
cout << (int)detector.detect(feed.snapshot()) << endl;
328+
#endif
329+
321330

322331

332+
#if 1
333+
UpdateMenuDetector detector;
334+
detector.make_overlays(overlays);
335+
336+
cout << detector.detect(feed.snapshot()) << endl;
337+
#endif
323338

324339

325340

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Console Type Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
8+
#include "CommonFramework/ImageTools/ImageStats.h"
9+
#include "NintendoSwitch_ConsoleTypeDetector.h"
10+
11+
//#include <iostream>
12+
//using std::cout;
13+
//using std::endl;
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
18+
19+
ConsoleTypeDetector_Home::ConsoleTypeDetector_Home(Color color)
20+
: m_color(color)
21+
, m_bottom_line(0.10, 0.88, 0.80, 0.03)
22+
{}
23+
24+
void ConsoleTypeDetector_Home::make_overlays(VideoOverlaySet& items) const{
25+
items.add(m_color, m_bottom_line);
26+
}
27+
ConsoleTypeDetection ConsoleTypeDetector_Home::detect(const ImageViewRGB32& screen) const{
28+
ImageStats stats = image_stats(extract_box_reference(screen, m_bottom_line));
29+
// cout << stats.stddev.sum() << endl;
30+
if (stats.stddev.sum() < 10){
31+
return ConsoleTypeDetection::Switch2_Unknown;
32+
}else{
33+
return ConsoleTypeDetection::Switch1;
34+
}
35+
}
36+
37+
38+
39+
40+
}
41+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Console Type Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_NintendoSwitch_ConsoleTypeDetector_H
8+
#define PokemonAutomation_NintendoSwitch_ConsoleTypeDetector_H
9+
10+
#include "Common/Cpp/Color.h"
11+
#include "CommonFramework/ImageTools/ImageBoxes.h"
12+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
13+
#include "CommonTools/VisualDetector.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
18+
19+
20+
enum class ConsoleTypeDetection{
21+
Unknown,
22+
Switch1,
23+
Switch2_Unknown,
24+
Switch2_International,
25+
Switch2_JapanLocked,
26+
};
27+
inline bool is_switch2(ConsoleTypeDetection detection){
28+
return detection == ConsoleTypeDetection::Switch2_Unknown
29+
|| detection == ConsoleTypeDetection::Switch2_International
30+
|| detection == ConsoleTypeDetection::Switch2_JapanLocked;
31+
}
32+
33+
34+
35+
36+
class ConsoleTypeDetector_Home{
37+
public:
38+
ConsoleTypeDetector_Home(Color color = COLOR_RED);
39+
40+
void make_overlays(VideoOverlaySet& items) const;
41+
ConsoleTypeDetection detect(const ImageViewRGB32& screen) const;
42+
43+
private:
44+
Color m_color;
45+
ImageFloatBox m_bottom_line;
46+
};
47+
48+
49+
50+
51+
52+
}
53+
}
54+
#endif

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -174,88 +174,6 @@ bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen) const{
174174

175175

176176

177-
UpdateMenuDetector::UpdateMenuDetector(Color color, bool invert)
178-
: m_color(color)
179-
, m_invert(invert)
180-
, m_box_top(0.25, 0.26, 0.50, 0.02)
181-
, m_box_mid(0.25, 0.52, 0.50, 0.02)
182-
, m_top(0.10, 0.15, 0.80, 0.03)
183-
, m_left(0.08, 0.25, 0.10, 0.38)
184-
, m_bottom_solid(0.10, 0.84, 0.80, 0.04)
185-
, m_bottom_buttons(0.70, 0.92, 0.28, 0.05)
186-
{}
187-
void UpdateMenuDetector::make_overlays(VideoOverlaySet& items) const{
188-
items.add(m_color, m_box_top);
189-
items.add(m_color, m_box_mid);
190-
items.add(m_color, m_top);
191-
items.add(m_color, m_left);
192-
items.add(m_color, m_bottom_solid);
193-
items.add(m_color, m_bottom_buttons);
194-
}
195-
bool UpdateMenuDetector::detect(const ImageViewRGB32& screen) const{
196-
ImageStats stats_box_top = image_stats(extract_box_reference(screen, m_box_top));
197-
// cout << stats_box_top.average << stats_box_top.stddev << endl;
198-
bool white;
199-
if (stats_box_top.average.sum() < 300){
200-
white = false;
201-
}else if (stats_box_top.average.sum() > 500){
202-
white = true;
203-
}else{
204-
return m_invert;
205-
}
206-
if (stats_box_top.stddev.sum() > 10){
207-
return m_invert;
208-
}
209-
210-
// cout << "white: " << white << endl;
211-
212-
ImageStats stats_box_mid = image_stats(extract_box_reference(screen, m_box_mid));
213-
if (stats_box_mid.stddev.sum() > 10){
214-
return m_invert;
215-
}
216-
if (euclidean_distance(stats_box_top.average, stats_box_mid.average) > 10){
217-
return m_invert;
218-
}
219-
220-
ImageStats stats_left = image_stats(extract_box_reference(screen, m_left));
221-
// cout << stats_left.stddev << endl;
222-
if (stats_left.stddev.sum() < 30){
223-
// cout << "zxcv" << endl;
224-
return m_invert;
225-
}
226-
227-
ImageStats stats_top = image_stats(extract_box_reference(screen, m_top));
228-
// cout << stats_top.average << stats_top.stddev << endl;
229-
230-
ImageStats bottom_solid = image_stats(extract_box_reference(screen, m_bottom_solid));
231-
// cout << bottom_solid.average << bottom_solid.stddev << endl;
232-
233-
if (euclidean_distance(stats_top.average, bottom_solid.average) > 10){
234-
// cout << "qwer" << endl;
235-
return m_invert;
236-
}
237-
238-
if (white){
239-
if (!is_grey(stats_top, 100, 300) || !is_grey(bottom_solid, 100, 300)){
240-
// cout << "asdf" << endl;
241-
return m_invert;
242-
}
243-
}else{
244-
if (!is_grey(stats_top, 0, 100) || !is_grey(bottom_solid, 0, 100)){
245-
// cout << "zxcv" << endl;
246-
return m_invert;
247-
}
248-
}
249-
250-
ImageStats stats_bottom_buttons = image_stats(extract_box_reference(screen, m_bottom_buttons));
251-
// cout << stats_bottom_buttons.average << stats_bottom_buttons.stddev << endl;
252-
if (stats_bottom_buttons.stddev.sum() < 30){
253-
return m_invert;
254-
}
255-
256-
return !m_invert;
257-
}
258-
259177

260178

261179

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,6 @@ class StartGameUserSelectWatcher : public DetectorToFinder<StartGameUserSelectDe
6363
};
6464

6565

66-
// Detect the Switch system update screen when you are about to enter a game from Switch Home screen
67-
class UpdateMenuDetector : public StaticScreenDetector{
68-
public:
69-
UpdateMenuDetector(Color color = COLOR_RED, bool invert = false);
70-
71-
virtual void make_overlays(VideoOverlaySet& items) const override;
72-
virtual bool detect(const ImageViewRGB32& screen) const override;
73-
74-
private:
75-
Color m_color;
76-
bool m_invert;
77-
ImageFloatBox m_box_top;
78-
ImageFloatBox m_box_mid;
79-
ImageFloatBox m_top;
80-
ImageFloatBox m_left;
81-
ImageFloatBox m_bottom_solid;
82-
ImageFloatBox m_bottom_buttons;
83-
};
84-
class UpdateMenuWatcher : public DetectorToFinder<UpdateMenuDetector>{
85-
public:
86-
UpdateMenuWatcher(Color color = COLOR_RED, bool invert = false)
87-
: DetectorToFinder("UpdateMenuWatcher", std::chrono::milliseconds(250), color, invert)
88-
{}
89-
};
90-
9166

9267

9368
// Detect the "Checking if the software can be played..." menu.

0 commit comments

Comments
 (0)