Skip to content

Commit 5556462

Browse files
author
Gin
committed
add home button + detector
1 parent fc1a43d commit 5556462

File tree

4 files changed

+87
-12
lines changed

4 files changed

+87
-12
lines changed

SerialPrograms/Source/PokemonHome/Inference/PokemonHome_ButtonDetector.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class ButtonMatcher : public ImageMatch::WaterfillTemplateMatcher{
2828
ButtonMatcher(ButtonType type, size_t min_width, size_t min_height, double max_rmsd);
2929

3030
static const ButtonMatcher& B(){
31-
static ButtonMatcher matcher(ButtonType::ButtonB, 25, 25, 70);
31+
static ButtonMatcher matcher(ButtonType::ButtonB, 25, 25, 80);
32+
return matcher;
33+
}
34+
static const ButtonMatcher& Plus(){
35+
static ButtonMatcher matcher(ButtonType::ButtonPlus, 25, 25, 80);
3236
return matcher;
3337
}
3438

@@ -55,7 +59,9 @@ class ButtonMatcher : public ImageMatch::WaterfillTemplateMatcher{
5559
const char* template_path(ButtonType type){
5660
switch (type){
5761
case ButtonType::ButtonB:
58-
return "PokemonHome/Buttons/ButtonB.png";
62+
return "PokemonHome/Buttons/ButtonB-Template.png";
63+
case ButtonType::ButtonPlus:
64+
return "PokemonHome/Buttons/ButtonPlus-Template.png";
5965
default:
6066
return "";
6167
}
@@ -65,6 +71,8 @@ const char* button_name(ButtonType type){
6571
switch (type){
6672
case ButtonType::ButtonB:
6773
return "ButtonB";
74+
case ButtonType::ButtonPlus:
75+
return "ButtonPlus";
6876
default:
6977
return "";
7078
}
@@ -74,6 +82,8 @@ const ButtonMatcher& get_button_matcher(ButtonType type){
7482
switch (type){
7583
case ButtonType::ButtonB:
7684
return ButtonMatcher::B();
85+
case ButtonType::ButtonPlus:
86+
return ButtonMatcher::Plus();
7787
default:
7888
throw std::runtime_error("No corresponding ButtonMatcher for ButtonType");
7989
}
@@ -146,16 +156,26 @@ bool ButtonDetector::detect(const ImageViewRGB32& screen){
146156
}
147157

148158

159+
BoxViewDetector::BoxViewDetector(VideoOverlay* overlay) : m_button_plus_detector(COLOR_BLACK, ButtonType::ButtonPlus, {0.100, 0.956, 0.107, 0.041}, overlay){}
149160

161+
void BoxViewDetector::make_overlays(VideoOverlaySet& items) const{
162+
m_button_plus_detector.make_overlays(items);
163+
}
150164

165+
bool BoxViewDetector::detect(const ImageViewRGB32& screen){
166+
return m_button_plus_detector.detect(screen);
167+
}
151168

152169

170+
SummaryScreenDetector::SummaryScreenDetector(VideoOverlay* overlay) : m_button_B_detector(COLOR_BLACK, ButtonType::ButtonB, {0.100, 0.956, 0.107, 0.041}, overlay){}
153171

172+
void SummaryScreenDetector::make_overlays(VideoOverlaySet& items) const{
173+
m_button_B_detector.make_overlays(items);
174+
}
154175

155-
156-
157-
158-
176+
bool SummaryScreenDetector::detect(const ImageViewRGB32& screen){
177+
return m_button_B_detector.detect(screen);
178+
}
159179

160180

161181

SerialPrograms/Source/PokemonHome/Inference/PokemonHome_ButtonDetector.h

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace PokemonHome{
2020

2121
enum class ButtonType{
2222
ButtonB,
23+
ButtonPlus,
2324
};
2425

2526
class ButtonMatcher;
@@ -56,13 +57,53 @@ class ButtonWatcher : public DetectorToFinder<ButtonDetector>{
5657
ButtonType button_type,
5758
const ImageFloatBox& box,
5859
VideoOverlay* overlay = nullptr,
59-
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
60+
Milliseconds hold_duration = Milliseconds(50)
6061
)
6162
: DetectorToFinder("ButtonWatcher", hold_duration, color, button_type, box, overlay)
6263
{}
6364
};
6465

6566

67+
class BoxViewDetector : public StaticScreenDetector{
68+
public:
69+
BoxViewDetector(VideoOverlay* overlay = nullptr);
70+
71+
virtual void make_overlays(VideoOverlaySet& items) const override;
72+
virtual bool detect(const ImageViewRGB32& screen) override;
73+
74+
virtual void reset_state() override { m_button_plus_detector.reset_state(); }
75+
76+
private:
77+
ButtonDetector m_button_plus_detector;
78+
79+
};
80+
class BoxViewWatcher : public DetectorToFinder<BoxViewDetector>{
81+
public:
82+
BoxViewWatcher(VideoOverlay* overlay = nullptr)
83+
: DetectorToFinder("BoxViewWatcher", Milliseconds(100), overlay)
84+
{}
85+
};
86+
87+
88+
class SummaryScreenDetector : public StaticScreenDetector{
89+
public:
90+
SummaryScreenDetector(VideoOverlay* overlay = nullptr);
91+
92+
virtual void make_overlays(VideoOverlaySet& items) const override;
93+
virtual bool detect(const ImageViewRGB32& screen) override;
94+
95+
virtual void reset_state() override { m_button_B_detector.reset_state(); }
96+
97+
private:
98+
ButtonDetector m_button_B_detector;
99+
100+
};
101+
class SummaryScreenWatcher : public DetectorToFinder<SummaryScreenDetector>{
102+
public:
103+
SummaryScreenWatcher(VideoOverlay* overlay = nullptr)
104+
: DetectorToFinder("SummaryScreenWatcher", Milliseconds(100), overlay)
105+
{}
106+
};
66107

67108

68109

SerialPrograms/Source/Tests/PokemonHome_Tests.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77

8-
#include "Common/Compiler.h"
8+
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"
99
#include "PokemonHome_Tests.h"
1010
#include "TestUtils.h"
1111

@@ -16,14 +16,28 @@ using std::endl;
1616

1717
namespace PokemonAutomation{
1818

19+
using namespace NintendoSwitch;
20+
using namespace NintendoSwitch::PokemonHome;
1921

2022
int test_pokemonHome_BoxView(const ImageViewRGB32& image, const std::vector<std::string>& keywords){
21-
// TODO: Implement test
23+
SummaryScreenDetector summary_screen_detector;
24+
bool result = summary_screen_detector.detect(image);
25+
TEST_RESULT_EQUAL(result, false);
26+
27+
BoxViewDetector box_view_detector;
28+
result = box_view_detector.detect(image);
29+
TEST_RESULT_EQUAL(result, true);
2230
return 0;
2331
}
2432

2533
int test_pokemonHome_SummaryScreen(const ImageViewRGB32& image, const std::vector<std::string>& keywords){
26-
// TODO: Implement test
34+
SummaryScreenDetector summary_screen_detector;
35+
bool result = summary_screen_detector.detect(image);
36+
TEST_RESULT_EQUAL(result, true);
37+
38+
BoxViewDetector box_view_detector;
39+
result = box_view_detector.detect(image);
40+
TEST_RESULT_EQUAL(result, false);
2741
return 0;
2842
}
2943

SerialPrograms/Source/Tests/PokemonLZA_Tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*
55
*/
66

7-
#include "PokemonLZA_Tests.h"
8-
#include "TestUtils.h"
97
#include "Common/Cpp/Time.h"
108
#include "CommonFramework/Logging/Logger.h"
119
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
@@ -20,6 +18,8 @@
2018
#include "PokemonLZA/Inference/Map/PokemonLZA_DirectionArrowDetector.h"
2119
#include "PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h"
2220
#include "CommonFramework/ImageTools/ImageBoxes.h"
21+
#include "PokemonLZA_Tests.h"
22+
#include "TestUtils.h"
2323
#include <iostream>
2424
#include <fstream>
2525
#include <map>

0 commit comments

Comments
 (0)