Skip to content

Commit 595363d

Browse files
author
Gin
committed
Add missing files
1 parent 8618556 commit 595363d

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* Alert Eye Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Exceptions.h"
8+
#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
9+
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
10+
#include "CommonTools/Images/WaterfillUtilities.h"
11+
#include "PokemonLZA_AlertEyeDetector.h"
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonLZA{
16+
17+
18+
19+
class AlertEyeMatcher : public ImageMatch::WaterfillTemplateMatcher{
20+
public:
21+
AlertEyeMatcher()
22+
: WaterfillTemplateMatcher(
23+
"PokemonLZA/AlertEye-Template.png",
24+
Color(200, 100, 100), Color(255, 255, 255), 100
25+
)
26+
{
27+
m_aspect_ratio_lower = 0.9;
28+
m_aspect_ratio_upper = 1.1;
29+
m_area_ratio_lower = 0.85;
30+
m_area_ratio_upper = 1.1;
31+
}
32+
33+
static const AlertEyeMatcher& instance(){
34+
static AlertEyeMatcher matcher;
35+
return matcher;
36+
}
37+
};
38+
39+
40+
41+
AlertEyeDetector::AlertEyeDetector(
42+
Color color,
43+
VideoOverlay* overlay
44+
)
45+
: m_color(color)
46+
, m_overlay(overlay)
47+
, m_alert_eye_box(0.485, 0.088, 0.029, 0.034)
48+
{}
49+
50+
void AlertEyeDetector::make_overlays(VideoOverlaySet& items) const{
51+
items.add(m_color, m_alert_eye_box);
52+
}
53+
54+
bool AlertEyeDetector::detect(const ImageViewRGB32& screen){
55+
const double screen_rel_size = (screen.height() / 1080.0);
56+
const double screen_rel_size_2 = screen_rel_size * screen_rel_size;
57+
58+
const double min_area_1080p = 300;
59+
const double rmsd_threshold = 80;
60+
const size_t min_area = size_t(screen_rel_size_2 * min_area_1080p);
61+
62+
const std::vector<std::pair<uint32_t, uint32_t>> FILTERS = {
63+
{ 0xff808080, 0xffffffff },
64+
{ 0xff909090, 0xffffffff },
65+
{ 0xffa0a0a0, 0xffffffff },
66+
{ 0xffb0b0b0, 0xffffffff },
67+
{ 0xffc0c0c0, 0xffffffff },
68+
{ 0xffd0d0d0, 0xffffffff },
69+
{ 0xffe0e0e0, 0xffffffff },
70+
{ 0xfff0f0f0, 0xffffffff },
71+
};
72+
73+
bool found = match_template_by_waterfill(
74+
screen.size(),
75+
extract_box_reference(screen, m_alert_eye_box),
76+
AlertEyeMatcher::instance(),
77+
FILTERS,
78+
{min_area, SIZE_MAX},
79+
rmsd_threshold,
80+
[&](Kernels::Waterfill::WaterfillObject& object) -> bool {
81+
m_last_detected = translate_to_parent(screen, m_alert_eye_box, object);
82+
return true;
83+
}
84+
);
85+
86+
if (m_overlay){
87+
if (found){
88+
m_last_detected_box.emplace(*m_overlay, m_last_detected, COLOR_GREEN);
89+
}else{
90+
m_last_detected_box.reset();
91+
}
92+
}
93+
94+
return found;
95+
}
96+
97+
98+
99+
100+
101+
102+
103+
104+
}
105+
}
106+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Alert Eye Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_AlertEyeDetector_H
8+
#define PokemonAutomation_PokemonLZA_AlertEyeDetector_H
9+
10+
#include <optional>
11+
#include "CommonFramework/ImageTools/ImageBoxes.h"
12+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13+
#include "CommonTools/VisualDetector.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
namespace PokemonLZA{
18+
19+
20+
// Detect the red warning symbol when you are under attack by wild pokemon
21+
class AlertEyeDetector : public StaticScreenDetector{
22+
public:
23+
AlertEyeDetector(
24+
Color color,
25+
VideoOverlay* overlay
26+
);
27+
28+
virtual void make_overlays(VideoOverlaySet& items) const override;
29+
30+
// This is not const so that detectors can save/cache state.
31+
virtual bool detect(const ImageViewRGB32& screen) override;
32+
33+
private:
34+
friend class AlertEyeWatcher;
35+
36+
const Color m_color;
37+
VideoOverlay* m_overlay;
38+
const ImageFloatBox m_alert_eye_box;
39+
40+
ImageFloatBox m_last_detected;
41+
std::optional<OverlayBoxScope> m_last_detected_box;
42+
};
43+
class AlertEyeWatcher : public DetectorToFinder<AlertEyeDetector>{
44+
public:
45+
AlertEyeWatcher(
46+
Color color,
47+
VideoOverlay* overlay,
48+
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
49+
)
50+
: DetectorToFinder("AlertEyeWatcher", hold_duration, color, overlay)
51+
{}
52+
};
53+
54+
55+
56+
57+
}
58+
}
59+
}
60+
#endif

0 commit comments

Comments
 (0)