|
| 1 | +/* Date Change Detector |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/ImageTools/ImageStats.h" |
| 8 | +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" |
| 9 | +#include "NintendoSwitch_DateChangeDetector.h" |
| 10 | + |
| 11 | +namespace PokemonAutomation{ |
| 12 | +namespace NintendoSwitch{ |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +DateChangeDetector_Switch1::DateChangeDetector_Switch1(Color color) |
| 18 | + : m_color(color) |
| 19 | + , m_background_top(0.50, 0.02, 0.45, 0.08) |
| 20 | + , m_window_top(0.50, 0.36, 0.45, 0.07) |
| 21 | + , m_window_text(0.05, 0.36, 0.10, 0.07) |
| 22 | + , m_jp_year(0.136, 0.61, 0.11, 0.09) |
| 23 | + , m_us_hour(0.473, 0.61, 0.06, 0.09) |
| 24 | + , m_jp_month_arrow(0.30, 0.50, 0.05, 0.06) |
| 25 | +{} |
| 26 | +void DateChangeDetector_Switch1::make_overlays(VideoOverlaySet& items) const{ |
| 27 | + items.add(m_color, m_background_top); |
| 28 | + items.add(m_color, m_window_top); |
| 29 | + items.add(m_color, m_window_text); |
| 30 | + items.add(m_color, m_jp_year); |
| 31 | + items.add(m_color, m_us_hour); |
| 32 | + items.add(m_color, m_jp_month_arrow); |
| 33 | +} |
| 34 | +bool DateChangeDetector_Switch1::detect(const ImageViewRGB32& screen){ |
| 35 | + ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top)); |
| 36 | + if (stats_background_top.stddev.sum() > 10){ |
| 37 | +// cout << "asdf" << endl; |
| 38 | + return false; |
| 39 | + } |
| 40 | + ImageStats stats_window_top = image_stats(extract_box_reference(screen, m_window_top)); |
| 41 | +// cout << stats_window_top.average << stats_window_top.stddev << endl; |
| 42 | + if (stats_window_top.stddev.sum() > 10){ |
| 43 | +// cout << "qwer" << endl; |
| 44 | + return false; |
| 45 | + } |
| 46 | + ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text)); |
| 47 | +// cout << stats_window_text.stddev << endl; |
| 48 | + if (stats_window_text.stddev.sum() < 100){ |
| 49 | +// cout << "zxcv" << endl; |
| 50 | + return false; |
| 51 | + } |
| 52 | +// cout << "stats_background_top: " << stats_background_top.average.sum() << endl; |
| 53 | +// cout << "stats_window_top: " << stats_window_top.average.sum() << endl; |
| 54 | + if (std::abs(stats_background_top.average.sum() - stats_window_top.average.sum()) < 50){ |
| 55 | +// cout << "xcvb" << endl; |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | +// bool white_theme = stats_window_top.average.sum() > 600; |
| 60 | + |
| 61 | + ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year); |
| 62 | + ImageStats year_stats = image_stats(year_box); |
| 63 | +// cout << year_stats.average << year_stats.stddev << endl; |
| 64 | + |
| 65 | + double stddev = year_stats.stddev.sum(); |
| 66 | + if (stddev < 80){ |
| 67 | +// cout << "sdfg" << endl; |
| 68 | + return false; |
| 69 | + } |
| 70 | + |
| 71 | + return true; |
| 72 | +} |
| 73 | +DateFormat DateChangeDetector_Switch1::detect_date_format(const ImageViewRGB32& screen) const{ |
| 74 | + ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour); |
| 75 | + ImageStats stats_us_hours = image_stats(us_hours); |
| 76 | + |
| 77 | + if (stats_us_hours.stddev.sum() > 30){ |
| 78 | + return DateFormat::US; |
| 79 | + } |
| 80 | + |
| 81 | + ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow); |
| 82 | + ImageStats stats_arrow = image_stats(jp_arrow); |
| 83 | + if (stats_arrow.stddev.sum() > 30){ |
| 84 | + return DateFormat::JP; |
| 85 | + } |
| 86 | + |
| 87 | + return DateFormat::EU; |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +DateChangeDetector_Switch2::DateChangeDetector_Switch2(Color color) |
| 93 | + : m_color(color) |
| 94 | + , m_background_top(0.50, 0.02, 0.45, 0.08) |
| 95 | + , m_window_bottom(0.50, 0.80, 0.45, 0.07) |
| 96 | + , m_window_text(0.05, 0.02, 0.10, 0.08) |
| 97 | + , m_jp_year(0.139, 0.436, 0.088, 0.095) |
| 98 | + , m_us_hour(0.473, 0.61, 0.06, 0.09) |
| 99 | + , m_jp_month_arrow(0.291705, 0.331675, 0.054986, 0.069652) |
| 100 | +{} |
| 101 | +void DateChangeDetector_Switch2::make_overlays(VideoOverlaySet& items) const{ |
| 102 | + items.add(m_color, m_background_top); |
| 103 | + items.add(m_color, m_window_bottom); |
| 104 | + items.add(m_color, m_window_text); |
| 105 | + items.add(m_color, m_jp_year); |
| 106 | + items.add(m_color, m_us_hour); |
| 107 | + items.add(m_color, m_jp_month_arrow); |
| 108 | +} |
| 109 | +bool DateChangeDetector_Switch2::detect(const ImageViewRGB32& screen){ |
| 110 | + ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top)); |
| 111 | + if (stats_background_top.stddev.sum() > 10){ |
| 112 | +// cout << "asdf" << endl; |
| 113 | + return false; |
| 114 | + } |
| 115 | + ImageStats stats_window_bottom = image_stats(extract_box_reference(screen, m_window_bottom)); |
| 116 | +// cout << stats_window_bottom.average << stats_window_top.stddev << endl; |
| 117 | + if (stats_window_bottom.stddev.sum() > 10){ |
| 118 | +// cout << "qwer" << endl; |
| 119 | + return false; |
| 120 | + } |
| 121 | + ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text)); |
| 122 | +// cout << stats_window_text.stddev << endl; |
| 123 | + if (stats_window_text.stddev.sum() < 100){ |
| 124 | +// cout << "zxcv" << endl; |
| 125 | + return false; |
| 126 | + } |
| 127 | +// cout << "stats_background_top: " << stats_background_top.average.sum() << endl; |
| 128 | +// cout << "stats_window_top: " << stats_window_top.average.sum() << endl; |
| 129 | + |
| 130 | + if (euclidean_distance(stats_background_top.average, stats_window_bottom.average) > 10){ |
| 131 | +// cout << "xcvb" << endl; |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | +// bool white_theme = stats_window_top.average.sum() > 600; |
| 136 | + |
| 137 | + ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year); |
| 138 | + ImageStats year_stats = image_stats(year_box); |
| 139 | +// cout << year_stats.average << year_stats.stddev << endl; |
| 140 | + |
| 141 | + double stddev = year_stats.stddev.sum(); |
| 142 | + if (stddev < 80){ |
| 143 | +// cout << "sdfg" << endl; |
| 144 | + return false; |
| 145 | + } |
| 146 | + |
| 147 | + return true; |
| 148 | +} |
| 149 | +DateFormat DateChangeDetector_Switch2::detect_date_format(const ImageViewRGB32& screen) const{ |
| 150 | + ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour); |
| 151 | + ImageStats stats_us_hours = image_stats(us_hours); |
| 152 | + |
| 153 | + if (stats_us_hours.stddev.sum() > 30){ |
| 154 | + return DateFormat::US; |
| 155 | + } |
| 156 | + |
| 157 | + ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow); |
| 158 | + ImageStats stats_arrow = image_stats(jp_arrow); |
| 159 | + if (stats_arrow.stddev.sum() > 30){ |
| 160 | + return DateFormat::JP; |
| 161 | + } |
| 162 | + |
| 163 | + return DateFormat::EU; |
| 164 | +} |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | +} |
| 173 | +} |
0 commit comments