|
| 1 | +/* Dialog Detector |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/Arduino-Source |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonTools/Images/SolidColorTest.h" |
| 8 | +#include "CommonTools/Images/ImageFilter.h" |
| 9 | +#include "CommonFramework/ImageTools/ImageBoxes.h" |
| 10 | +#include "CommonFramework/ImageTypes/ImageRGB32.h" |
| 11 | +#include "CommonFramework/ImageTools/ImageStats.h" |
| 12 | +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" |
| 13 | +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" |
| 14 | +#include "PokemonRSE_DialogDetector.h" |
| 15 | + |
| 16 | +#include <iostream> |
| 17 | +using std::cout; |
| 18 | +using std::endl; |
| 19 | + |
| 20 | +namespace PokemonAutomation{ |
| 21 | +namespace NintendoSwitch{ |
| 22 | +namespace PokemonRSE{ |
| 23 | + |
| 24 | +/* |
| 25 | +DialogDetector::DialogDetector(Color color) |
| 26 | + : m_left_box(0.155, 0.727, 0.015, 0.168) |
| 27 | + , m_right_box(0.837, 0.729, 0.008, 0.161) |
| 28 | +{} |
| 29 | +void DialogDetector::make_overlays(VideoOverlaySet& items) const{ |
| 30 | + items.add(COLOR_RED, m_left_box); |
| 31 | + items.add(COLOR_RED, m_right_box); |
| 32 | +} |
| 33 | +bool DialogDetector::detect(const ImageViewRGB32& screen) const{ |
| 34 | + ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box); |
| 35 | + ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box); |
| 36 | + if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){ |
| 37 | + return true; |
| 38 | + } |
| 39 | + return false; |
| 40 | +} |
| 41 | +*/ |
| 42 | + |
| 43 | +BattleDialogDetector::BattleDialogDetector(Color color) |
| 44 | + : m_left_box(0.158, 0.725, 0.011, 0.176) |
| 45 | + , m_right_box(0.827, 0.722, 0.013, 0.178) |
| 46 | +{} |
| 47 | +void BattleDialogDetector::make_overlays(VideoOverlaySet& items) const{ |
| 48 | + items.add(COLOR_RED, m_left_box); |
| 49 | + items.add(COLOR_RED, m_right_box); |
| 50 | +} |
| 51 | +bool BattleDialogDetector::detect(const ImageViewRGB32& screen) const{ |
| 52 | + ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box); |
| 53 | + ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box); |
| 54 | + if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){ |
| 55 | + return true; |
| 56 | + } |
| 57 | + return false; |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +BattleMenuDetector::BattleMenuDetector(Color color) |
| 62 | + : m_left_box(0.439, 0.717, 0.021, 0.192) |
| 63 | + , m_right_box(0.821, 0.725, 0.030, 0.181) |
| 64 | +{} |
| 65 | +void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{ |
| 66 | + items.add(COLOR_RED, m_left_box); |
| 67 | + items.add(COLOR_RED, m_right_box); |
| 68 | +} |
| 69 | +bool BattleMenuDetector::detect(const ImageViewRGB32& screen) const{ |
| 70 | + ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box); |
| 71 | + ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box); |
| 72 | + if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.25, 0.38, 0.369 })){ |
| 73 | + return true; |
| 74 | + } |
| 75 | + return false; |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +AdvanceBattleDialogDetector::AdvanceBattleDialogDetector(Color color) |
| 80 | + : m_dialog_box(0.156, 0.715, 0.686, 0.193) |
| 81 | + , m_left_box(0.156, 0.724, 0.010, 0.176) |
| 82 | + , m_right_box(0.836, 0.717, 0.008, 0.189) |
| 83 | +{} |
| 84 | +void AdvanceBattleDialogDetector::make_overlays(VideoOverlaySet& items) const{ |
| 85 | + items.add(COLOR_RED, m_dialog_box); |
| 86 | + items.add(COLOR_RED, m_left_box); |
| 87 | + items.add(COLOR_RED, m_right_box); |
| 88 | +} |
| 89 | +bool AdvanceBattleDialogDetector::detect(const ImageViewRGB32& screen) const{ |
| 90 | + const bool replace_color_within_range = false; |
| 91 | + |
| 92 | + //Filter out background |
| 93 | + ImageRGB32 filtered_region = filter_rgb32_range( |
| 94 | + extract_box_reference(screen, m_dialog_box), |
| 95 | + combine_rgb(185, 0, 1), combine_rgb(255, 32, 33), Color(0), replace_color_within_range |
| 96 | + ); |
| 97 | + ImageStats stats = image_stats(filtered_region); |
| 98 | + |
| 99 | + /* |
| 100 | + filtered_region.save("./filtered_only.png"); |
| 101 | + cout << stats.average.r << endl; |
| 102 | + cout << stats.average.g << endl; |
| 103 | + cout << stats.average.b << endl; |
| 104 | + */ |
| 105 | + |
| 106 | + ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box); |
| 107 | + ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box); |
| 108 | + |
| 109 | + if (is_solid(left_image, { 0.335, 0.331, 0.332 }) |
| 110 | + && is_solid(right_image, { 0.335, 0.331, 0.332 }) |
| 111 | + && (stats.average.r > stats.average.b + 200) |
| 112 | + && (stats.average.r > stats.average.g + 200) |
| 113 | + ) |
| 114 | + { |
| 115 | + return true; |
| 116 | + } |
| 117 | + return false; |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +} |
| 123 | +} |
| 124 | +} |
0 commit comments