|
| 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 | +} |
0 commit comments