Skip to content

Commit 5cd6db0

Browse files
committed
Selection arrow can be right or down.
1 parent 7b3bb17 commit 5cd6db0

File tree

5 files changed

+70
-18
lines changed

5 files changed

+70
-18
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,39 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
293293
#endif
294294

295295

296-
#if 0
297-
ImageRGB32 image("Screenshots/screenshot-20251012-174842583706.png");
296+
#if 1
297+
// ImageRGB32 image("Screenshots/screenshot-20251012-174842583706.png");
298298

299-
ImageFloatBox box(0.724479, 0.869141, 0.039517, 0.070312);
299+
auto screen = feed.snapshot();
300+
301+
ImageFloatBox box(0.763359, 0.089320, 0.021810, 0.044660);
300302
// ImageFloatBox box(0.712404, 0.589844, 0.043908, 0.085938);
301303

302304
overlays.add(COLOR_RED, box);
303305

304-
ImageViewRGB32 cropped = extract_box_reference(image, box);
306+
ImageViewRGB32 cropped = extract_box_reference(screen, box);
307+
308+
// Remove background.
309+
{
310+
PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(
311+
cropped,
312+
0xffe0e0e0, 0xffffffff
313+
);
314+
matrix.invert();
315+
316+
cout << matrix.dump() << endl;
317+
318+
auto session = Waterfill::make_WaterfillSession(matrix);
319+
auto iter = session->make_iterator(10);
320+
WaterfillObject object;
321+
iter->find_next(object, true);
322+
ImageRGB32 masked = extract_box_reference(cropped, object).copy();
323+
filter_by_mask(object.packed_matrix(), masked, Color(0x00000000), false);
324+
masked.save("ButtonL.png");
325+
}
326+
305327

328+
#if 0
306329
PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(
307330
cropped,
308331
0xffc0c0c0, 0xffffffff
@@ -311,15 +334,16 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
311334
cout << matrix.dump() << endl;
312335

313336
ImageRGB32 tmp = cropped.copy();
314-
filter_by_mask(matrix, tmp, Color(0x00000000), true);
337+
// filter_by_mask(matrix, tmp, Color(0x00000000), true);
338+
339+
{
340+
}
315341

316-
#if 1
317342
auto session = Waterfill::make_WaterfillSession(matrix);
318343
auto iter = session->make_iterator(10);
319344
WaterfillObject object;
320345
while (iter->find_next(object, false)){
321-
322-
346+
break;
323347
}
324348
cout << "area = " << object.area << endl;
325349

@@ -335,7 +359,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
335359

336360
// reset_game_to_gamemenu(console, context);
337361

338-
#if 1
362+
#if 0
339363
while (true){
340364
go_home(console, context);
341365
PokemonLZA::reset_game_from_home(env, console, context, true);

SerialPrograms/Source/PanelLists.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ ProgramSelect::ProgramSelect(QWidget& parent, PanelHolder& holder)
4141
QVBoxLayout* layout = new QVBoxLayout(this);
4242
layout->setAlignment(Qt::AlignTop);
4343
m_dropdown = new NoWheelComboBox(this);
44+
m_dropdown->setMaxVisibleItems(20);
4445
layout->addWidget(m_dropdown);
4546

4647

47-
4848
add(std::make_unique<NintendoSwitch::PanelListFactory>());
4949
add(std::make_unique<NintendoSwitch::PokemonHome::PanelListFactory>());
5050
add(std::make_unique<NintendoSwitch::PokemonLGPE::PanelListFactory>());

SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.cpp

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

7+
#include "Common/Cpp/Exceptions.h"
78
#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
89
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
910
#include "CommonTools/Images/WaterfillUtilities.h"
@@ -19,9 +20,9 @@ class SelectionArrowMatcher : public ImageMatch::WaterfillTemplateMatcher{
1920
public:
2021
// The white background for the template file is of color range [r=240, g=255, b=230] to [255, 255, 255]
2122
// the black arrow color is about [r=36,g=38,b=51]
22-
SelectionArrowMatcher()
23+
SelectionArrowMatcher(const char* path)
2324
: WaterfillTemplateMatcher(
24-
"PokemonLZA/SelectionArrow-full.png",
25+
path,
2526
Color(0xff80c000), Color(0xffffff7f), 100
2627
)
2728
{
@@ -31,8 +32,22 @@ class SelectionArrowMatcher : public ImageMatch::WaterfillTemplateMatcher{
3132
m_area_ratio_upper = 1.1;
3233
}
3334

34-
static const ImageMatch::WaterfillTemplateMatcher& instance() {
35-
static SelectionArrowMatcher matcher;
35+
static const SelectionArrowMatcher& matcher(SelectionArrowType type){
36+
switch (type){
37+
case SelectionArrowType::RIGHT:
38+
return RIGHT_ARROW();
39+
case SelectionArrowType::DOWN:
40+
return DOWN_ARROW();
41+
default:
42+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid enum.");
43+
}
44+
}
45+
static const SelectionArrowMatcher& RIGHT_ARROW(){
46+
static SelectionArrowMatcher matcher("PokemonLZA/SelectionArrowRight.png");
47+
return matcher;
48+
}
49+
static const SelectionArrowMatcher& DOWN_ARROW(){
50+
static SelectionArrowMatcher matcher("PokemonLZA/SelectionArrowDown.png");
3651
return matcher;
3752
}
3853
};
@@ -42,10 +57,12 @@ class SelectionArrowMatcher : public ImageMatch::WaterfillTemplateMatcher{
4257
SelectionArrowDetector::SelectionArrowDetector(
4358
Color color,
4459
VideoOverlay* overlay,
60+
SelectionArrowType type,
4561
const ImageFloatBox& box
4662
)
4763
: m_color(color)
4864
, m_overlay(overlay)
65+
, m_type(type)
4966
, m_arrow_box(box)
5067
{}
5168
void SelectionArrowDetector::make_overlays(VideoOverlaySet& items) const{
@@ -66,7 +83,7 @@ bool SelectionArrowDetector::detect(const ImageViewRGB32& screen){
6683

6784
bool found = match_template_by_waterfill(
6885
extract_box_reference(screen, m_arrow_box),
69-
SelectionArrowMatcher::instance(),
86+
SelectionArrowMatcher::matcher(m_type),
7087
FILTERS,
7188
{min_area, SIZE_MAX},
7289
rmsd_threshold,

SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ namespace NintendoSwitch{
1717
namespace PokemonLZA{
1818

1919

20+
enum class SelectionArrowType{
21+
RIGHT,
22+
DOWN,
23+
};
24+
25+
2026

2127
class SelectionArrowDetector : public StaticScreenDetector{
2228
public:
2329
SelectionArrowDetector(
2430
Color color,
2531
VideoOverlay* overlay,
32+
SelectionArrowType type,
2633
const ImageFloatBox& box
2734
);
2835

@@ -36,6 +43,7 @@ class SelectionArrowDetector : public StaticScreenDetector{
3643

3744
const Color m_color;
3845
VideoOverlay* m_overlay;
46+
const SelectionArrowType m_type;
3947
const ImageFloatBox m_arrow_box;
4048

4149
ImageFloatBox m_last_detected;
@@ -46,10 +54,11 @@ class SelectionArrowWatcher : public DetectorToFinder<SelectionArrowDetector>{
4654
SelectionArrowWatcher(
4755
Color color,
4856
VideoOverlay* overlay,
57+
SelectionArrowType type,
4958
const ImageFloatBox& box,
5059
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
5160
)
52-
: DetectorToFinder("SelectionArrowWatcher", hold_duration, color, overlay, box)
61+
: DetectorToFinder("SelectionArrowWatcher", hold_duration, color, overlay, type, box)
5362
{}
5463
};
5564

SerialPrograms/Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_OverworldWatcher.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void OverworldWatcher::program(SingleSwitchProgramEnvironment& env, ProControlle
4242
FlatWhiteDialogWatcher dialog_white(COLOR_RED, &overlay);
4343
BlueDialogWatcher dialog_blue(COLOR_RED, &overlay);
4444
TealDialogWatcher dialog_teal(COLOR_RED, &overlay);
45-
SelectionArrowWatcher selection_arrow(COLOR_RED, &overlay, {0, 0, 1, 1});
45+
SelectionArrowWatcher selection_arrow_right(COLOR_RED, &overlay, SelectionArrowType::RIGHT, {0, 0, 1, 1});
46+
SelectionArrowWatcher selection_arrow_down(COLOR_RED, &overlay, SelectionArrowType::DOWN, {0, 0, 1, 1});
4647

4748
CancellableHolder<CancellableScope> scope(*context.scope());
4849
InferenceSession session(
@@ -51,7 +52,8 @@ void OverworldWatcher::program(SingleSwitchProgramEnvironment& env, ProControlle
5152
dialog_white,
5253
dialog_blue,
5354
dialog_teal,
54-
selection_arrow,
55+
selection_arrow_right,
56+
selection_arrow_down,
5557
}
5658
);
5759
context.wait_until_cancel();

0 commit comments

Comments
 (0)