|
4 | 4 | * |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include "CommonFramework/ImageTools/ImageBoxes.h" |
| 8 | +#include "CommonFramework/ImageTypes/ImageRGB32.h" |
7 | 9 | #include "CommonFramework/ImageTools/ImageStats.h" |
8 | 10 | #include "CommonFramework/VideoPipeline/VideoOverlay.h" |
9 | 11 | #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" |
| 12 | +#include "CommonTools/Images/ImageFilter.h" |
| 13 | +#include "CommonTools/OCR/OCR_NumberReader.h" |
10 | 14 | #include "Kernels/Waterfill/Kernels_Waterfill_Types.h" |
11 | 15 | #include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h" |
12 | 16 | #include "CommonTools/Images/WaterfillUtilities.h" |
| 17 | +#include "PokemonLZA/Resources/PokemonLZA_AvailablePokemon.h" |
13 | 18 | #include "PokemonLZA_BoxInfoDetector.h" |
14 | 19 |
|
15 | 20 | namespace PokemonAutomation{ |
@@ -190,7 +195,40 @@ std::string BoxPageInfoWatcher::info_str() const{ |
190 | 195 | return "Regular"; |
191 | 196 | } |
192 | 197 |
|
| 198 | +BoxDexNummberDetector::BoxDexNummberDetector(Logger& logger) : m_logger(logger), m_dex_number_box{0.510, 0.203, 0.039, 0.031}, m_dex_type_box{0.472, 0.204, 0.018, 0.030}{} |
193 | 199 |
|
| 200 | +void BoxDexNummberDetector::make_overlays(VideoOverlaySet& items) const{ |
| 201 | + items.add(COLOR_GRAY, m_dex_number_box); |
| 202 | + items.add(COLOR_GRAY, m_dex_type_box); |
| 203 | +} |
| 204 | + |
| 205 | +bool BoxDexNummberDetector::detect(const ImageViewRGB32& screen){ |
| 206 | + const size_t max_dex_number = std::max(LUMIOSE_DEX_SLUGS().size(), HYPERSPACE_DEX_SLUGS().size()); |
| 207 | + |
| 208 | + const int dex_number = OCR::read_number_waterfill(m_logger, extract_box_reference(screen, m_dex_number_box), 0xff808080, 0xffffffff, false); |
| 209 | + if (dex_number <= 0 || dex_number > static_cast<int>(max_dex_number)) { |
| 210 | + m_dex_number = 0; |
| 211 | + m_dex_number_when_error = dex_number; |
| 212 | + return false; |
| 213 | + } |
| 214 | + m_dex_number = static_cast<uint16_t>(dex_number); |
| 215 | + m_dex_number_when_error = 0; |
| 216 | + |
| 217 | + // Replacing white background with zero-alpha color so that they won't be counted in |
| 218 | + // the following image_stats() |
| 219 | + // The white background is defined as the color between 0xffa0a0a0 and 0xffffffff. |
| 220 | + const bool replace_color_within_range = true; |
| 221 | + ImageRGB32 region = filter_rgb32_range( |
| 222 | + extract_box_reference(screen, m_dex_type_box), |
| 223 | + 0xffa0a0a0, 0xffffffff, Color(0), replace_color_within_range |
| 224 | + ); |
| 225 | + |
| 226 | + ImageStats stats = image_stats(region); |
| 227 | + m_dex_type_color_ratio = stats.count / ((double)region.width() * region.height()); |
| 228 | + m_dex_type = (m_dex_type_color_ratio > 0.2) ? DexType::LUMIOSE : DexType::HYPERSPACE; |
| 229 | + |
| 230 | + return true; |
| 231 | +} |
194 | 232 |
|
195 | 233 | } |
196 | 234 | } |
|
0 commit comments