|
| 1 | +#include "CommonFramework/Globals.h" |
| 2 | +#include "CommonFramework/ImageTools/ImageDiff.h" |
| 3 | +#include "CommonTools/Images/ImageFilter.h" |
| 4 | +#include "PokemonLZA_WeatherDetector.h" |
| 5 | + |
| 6 | +namespace PokemonAutomation { |
| 7 | +namespace NintendoSwitch { |
| 8 | +namespace PokemonLZA { |
| 9 | + |
| 10 | + |
| 11 | +//----------------------------------------------------- |
| 12 | +// Weather Info Table (two images per weather) |
| 13 | +//----------------------------------------------------- |
| 14 | + |
| 15 | +static const WeatherTemplateInfo WEATHER_TABLE[] = { |
| 16 | + |
| 17 | + // Clear |
| 18 | + { |
| 19 | + "PokemonLZA/Weather/sun_drop.png", |
| 20 | + "PokemonLZA/Weather/clear_core.png", |
| 21 | + ImageFloatBox(0.8945, 0.0570, 0.0050, 0.0100), |
| 22 | + ImageFloatBox(0.8910, 0.0360, 0.0110, 0.0210), |
| 23 | + COLOR_RED, |
| 24 | + COLOR_GREEN |
| 25 | + }, |
| 26 | + |
| 27 | + // Sunny |
| 28 | + { |
| 29 | + "PokemonLZA/Weather/sun_drop.png", |
| 30 | + "PokemonLZA/Weather/sunny_core.png", |
| 31 | + ImageFloatBox(0.8945, 0.0570, 0.0050, 0.0100), |
| 32 | + ImageFloatBox(0.8910, 0.0360, 0.0110, 0.0210), |
| 33 | + COLOR_RED, |
| 34 | + COLOR_GREEN |
| 35 | + }, |
| 36 | + |
| 37 | + // Rain |
| 38 | + { |
| 39 | + "PokemonLZA/Weather/rain_cloud.png", |
| 40 | + "PokemonLZA/Weather/rain_drop.png", |
| 41 | + ImageFloatBox(0.8865, 0.0265, 0.0210, 0.0270), |
| 42 | + ImageFloatBox(0.8885, 0.0525, 0.0050, 0.0150), |
| 43 | + COLOR_RED, |
| 44 | + COLOR_GREEN |
| 45 | + }, |
| 46 | + |
| 47 | + // Cloudy |
| 48 | + { |
| 49 | + "PokemonLZA/Weather/cloudy_cloud.png", |
| 50 | + "PokemonLZA/Weather/cloudy_drop.png", |
| 51 | + ImageFloatBox(0.8895, 0.0430, 0.0210, 0.0265), |
| 52 | + ImageFloatBox(0.8915, 0.0255, 0.0050, 0.0100), |
| 53 | + COLOR_RED, |
| 54 | + COLOR_GREEN |
| 55 | + }, |
| 56 | + |
| 57 | + // Foggy |
| 58 | + { |
| 59 | + "PokemonLZA/Weather/foggy_tray_1.png", |
| 60 | + "PokemonLZA/Weather/foggy_tray_2.png", |
| 61 | + ImageFloatBox(0.8893, 0.0487, 0.0218, 0.0080), |
| 62 | + ImageFloatBox(0.8880, 0.0555, 0.0225, 0.0080), |
| 63 | + COLOR_RED, |
| 64 | + COLOR_GREEN |
| 65 | + }, |
| 66 | + |
| 67 | + // Rainbow |
| 68 | + { |
| 69 | + "PokemonLZA/Weather/rainbow_cloud.png", |
| 70 | + "PokemonLZA/Weather/rainbow_arch.png", |
| 71 | + ImageFloatBox(0.8840, 0.0465, 0.0140, 0.0165), |
| 72 | + ImageFloatBox(0.8930, 0.0420, 0.0120, 0.0100), |
| 73 | + COLOR_RED, |
| 74 | + COLOR_GREEN |
| 75 | + }, |
| 76 | +}; |
| 77 | + |
| 78 | + |
| 79 | +const WeatherTemplateInfo& weather_template_info(WeatherIconType icon){ |
| 80 | + return WEATHER_TABLE[(int)icon]; |
| 81 | +} |
| 82 | + |
| 83 | +//----------------------------------------------------- |
| 84 | +// Detector |
| 85 | +//----------------------------------------------------- |
| 86 | + |
| 87 | +WeatherIconDetector::WeatherIconDetector(WeatherIconType type, VideoOverlay* overlay) |
| 88 | +{ |
| 89 | + m_info = &weather_template_info(type); |
| 90 | + |
| 91 | + if (overlay){ |
| 92 | + m_overlay1.emplace(*overlay, m_info->box1, m_info->color1); |
| 93 | + m_overlay2.emplace(*overlay, m_info->box2, m_info->color2); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +void WeatherIconDetector::make_overlays(VideoOverlaySet& items) const { |
| 98 | + items.add(m_info->color1, m_info->box1); |
| 99 | + items.add(m_info->color2, m_info->box2); |
| 100 | +} |
| 101 | + |
| 102 | +bool WeatherIconDetector::detect(const ImageViewRGB32& screen){ |
| 103 | + |
| 104 | + // Extract screen patches |
| 105 | + ImageRGB32 c1 = extract_box_reference(screen, m_info->box1).copy(); |
| 106 | + ImageRGB32 c2 = extract_box_reference(screen, m_info->box2).copy(); |
| 107 | + |
| 108 | + // Load templates |
| 109 | + ImageRGB32 t1(RESOURCE_PATH() + m_info->path1); |
| 110 | + ImageRGB32 t2(RESOURCE_PATH() + m_info->path2); |
| 111 | + |
| 112 | + if (t1.width() == 0 || t2.width() == 0){ |
| 113 | + return false; |
| 114 | + } |
| 115 | + |
| 116 | + double rms1 = ImageMatch::pixel_RMSD(c1, t1); |
| 117 | + double rms2 = ImageMatch::pixel_RMSD(c2, t2); |
| 118 | + |
| 119 | + return rms1 < 90 && rms2 < 90; |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | +} |
| 124 | +} |
| 125 | +} |
0 commit comments