Skip to content

Commit 5b80f0c

Browse files
author
Gin
committed
merge shiny and alpha detector into one file
1 parent 14505ab commit 5b80f0c

File tree

7 files changed

+110
-165
lines changed

7 files changed

+110
-165
lines changed

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

Lines changed: 0 additions & 93 deletions
This file was deleted.

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxAlphaDetector.h

Lines changed: 0 additions & 59 deletions
This file was deleted.

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.cpp renamed to SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Box Shiny Detector
1+
/* Box Info Detector
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
@@ -10,7 +10,7 @@
1010
#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
1111
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
1212
#include "CommonTools/Images/WaterfillUtilities.h"
13-
#include "PokemonLZA_BoxShinyDetector.h"
13+
#include "PokemonLZA_BoxInfoDetector.h"
1414

1515
namespace PokemonAutomation{
1616
namespace NintendoSwitch{
@@ -89,6 +89,75 @@ bool BoxShinyDetector::detect(const ImageViewRGB32& screen){
8989
}
9090

9191

92+
class BoxAlphaSymbolMatcher : public ImageMatch::WaterfillTemplateMatcher{
93+
public:
94+
BoxAlphaSymbolMatcher(const char* path)
95+
: WaterfillTemplateMatcher(
96+
path,
97+
Color(combine_rgb(200, 50, 50)), Color(combine_rgb(255, 100, 100)), 200
98+
)
99+
{
100+
m_aspect_ratio_lower = 0.9;
101+
m_aspect_ratio_upper = 1.1;
102+
m_area_ratio_lower = 0.85;
103+
m_area_ratio_upper = 1.1;
104+
}
105+
106+
static const BoxAlphaSymbolMatcher& matcher(){
107+
const static BoxAlphaSymbolMatcher matcher("PokemonLZA/AlphaSymbol-Template.png");
108+
return matcher;
109+
}
110+
};
111+
112+
BoxAlphaDetector::BoxAlphaDetector(Color color, VideoOverlay* overlay)
113+
: m_color(color)
114+
, m_box{0.820, 0.107, 0.085, 0.042}
115+
, m_overlay(overlay)
116+
{}
117+
118+
void BoxAlphaDetector::make_overlays(VideoOverlaySet& items) const{
119+
items.add(m_color, m_box);
120+
}
121+
122+
bool BoxAlphaDetector::detect(const ImageViewRGB32& screen){
123+
double screen_rel_size = (screen.height() / 1080.0);
124+
double screen_rel_size_2 = screen_rel_size * screen_rel_size;
125+
126+
double min_area_1080p = 300.0;
127+
size_t min_area = size_t(screen_rel_size_2 * min_area_1080p);
128+
129+
const std::vector<std::pair<uint32_t, uint32_t>> FILTERS = {
130+
{combine_rgb(200, 50, 50), combine_rgb(255, 100, 100)},
131+
{combine_rgb(150, 0, 0), combine_rgb(255, 100, 100)},
132+
};
133+
134+
const double max_rsmd = 100.0;
135+
bool found = match_template_by_waterfill(
136+
screen.size(),
137+
extract_box_reference(screen, m_box),
138+
BoxAlphaSymbolMatcher::matcher(),
139+
FILTERS,
140+
{min_area, SIZE_MAX},
141+
max_rsmd,
142+
[&](Kernels::Waterfill::WaterfillObject& object) -> bool {
143+
// cout << "width = " << object.width() << ", height = " << object.height() << endl;
144+
m_last_detected = translate_to_parent(screen, m_box, object);
145+
return true;
146+
}
147+
);
148+
149+
if (m_overlay){
150+
if (found){
151+
m_last_detected_box.emplace(*m_overlay, m_last_detected, COLOR_GREEN);
152+
}else{
153+
m_last_detected_box.reset();
154+
}
155+
}
156+
157+
return found;
158+
}
159+
160+
92161

93162

94163
}

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.h renamed to SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* Box Shiny Detector
1+
/* Box Info Detector
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_PokemonLZA_BoxShinyDetector_H
8-
#define PokemonAutomation_PokemonLZA_BoxShinyDetector_H
7+
#ifndef PokemonAutomation_PokemonLZA_BoxInfoDetector_H
8+
#define PokemonAutomation_PokemonLZA_BoxInfoDetector_H
99

1010
#include <optional>
1111
#include "Common/Cpp/Color.h"
@@ -50,6 +50,38 @@ class BoxShinyWatcher : public DetectorToFinder<BoxShinyDetector>{
5050
{}
5151
};
5252

53+
// Detect alpha symbol when viewing a Pokemon in the box system
54+
class BoxAlphaDetector : public StaticScreenDetector{
55+
public:
56+
BoxAlphaDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr);
57+
58+
virtual void make_overlays(VideoOverlaySet& items) const override;
59+
60+
// This is not const so that detectors can save/cache state.
61+
virtual bool detect(const ImageViewRGB32& screen) override;
62+
63+
private:
64+
friend class BoxAlphaWatcher;
65+
66+
Color m_color;
67+
ImageFloatBox m_box;
68+
VideoOverlay* m_overlay;
69+
70+
ImageFloatBox m_last_detected;
71+
std::optional<OverlayBoxScope> m_last_detected_box;
72+
};
73+
74+
class BoxAlphaWatcher : public DetectorToFinder<BoxAlphaDetector>{
75+
public:
76+
BoxAlphaWatcher(
77+
Color color = COLOR_RED,
78+
VideoOverlay* overlay = nullptr,
79+
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
80+
)
81+
: DetectorToFinder("BoxAlphaWatcher", FinderType::CONSISTENT, hold_duration, color, overlay)
82+
{}
83+
};
84+
5385

5486

5587

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "Pokemon/Pokemon_Strings.h"
1010
#include "CommonTools/Async/InferenceRoutines.h"
1111
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h"
12-
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.h"
13-
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxAlphaDetector.h"
12+
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h"
1413
#include "PokemonLZA_TestBoxCellInfo.h"
1514

1615
#include <iostream>

SerialPrograms/Source/Tests/PokemonLZA_Tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#include "PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
1717
#include "PokemonLZA/Inference/PokemonLZA_MainMenuDetector.h"
1818
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h"
19-
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.h"
20-
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxAlphaDetector.h"
19+
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h"
2120
#include <QFileInfo>
2221
#include <QDir>
2322
#include <algorithm>

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,12 +1539,10 @@ file(GLOB LIBRARY_SOURCES
15391539
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h
15401540
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp
15411541
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h
1542-
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxAlphaDetector.cpp
1543-
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxAlphaDetector.h
15441542
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp
15451543
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h
1546-
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.cpp
1547-
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxShinyDetector.h
1544+
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.cpp
1545+
Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h
15481546
Source/PokemonLZA/Inference/PokemonLZA_ButtonDetector.cpp
15491547
Source/PokemonLZA/Inference/PokemonLZA_ButtonDetector.h
15501548
Source/PokemonLZA/Inference/PokemonLZA_DialogDetector.cpp

0 commit comments

Comments
 (0)