diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 4c57913f7..fe0f00ab2 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -1348,12 +1348,10 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.h Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.cpp Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.h - # Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp - # Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h Source/PokemonSV/Inference/PokemonSV_MoneyReader.cpp Source/PokemonSV/Inference/PokemonSV_MoneyReader.h - # Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp - # Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h + Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp + Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.cpp Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.h Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp @@ -1424,12 +1422,6 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/PokemonSV_Panels.h Source/PokemonSV/PokemonSV_Settings.cpp Source/PokemonSV/PokemonSV_Settings.h - # Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp - # Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h - # Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp - # Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h - # Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp - # Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.cpp Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h Source/PokemonSV/Programs/Battles/PokemonSV_Battles.cpp diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index 4b52585cb..89d16c54b 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -674,9 +674,8 @@ SOURCES += \ Source/PokemonSV/Inference/PokemonSV_ClothingTopDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.cpp \ - #Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp \ Source/PokemonSV/Inference/PokemonSV_MoneyReader.cpp \ - #Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp \ + Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp \ Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp \ Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp \ @@ -711,9 +710,6 @@ SOURCES += \ Source/PokemonSV/Options/PokemonSV_TournamentPrizeTable.cpp \ Source/PokemonSV/PokemonSV_Panels.cpp \ Source/PokemonSV/PokemonSV_Settings.cpp \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_Battles.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.cpp \ @@ -1756,9 +1752,8 @@ HEADERS += \ Source/PokemonSV/Inference/PokemonSV_ClothingTopDetector.h \ Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.h \ Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.h \ - #Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h \ Source/PokemonSV/Inference/PokemonSV_MoneyReader.h \ - #Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h \ + Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h \ Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.h \ Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h \ Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.h \ @@ -1795,9 +1790,6 @@ HEADERS += \ Source/PokemonSV/Options/PokemonSV_TournamentPrizeTable.h \ Source/PokemonSV/PokemonSV_Panels.h \ Source/PokemonSV/PokemonSV_Settings.h \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \ - #Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h \ Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h \ Source/PokemonSV/Programs/Battles/PokemonSV_Battles.h \ Source/PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.h \ diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp new file mode 100644 index 000000000..7324871b6 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp @@ -0,0 +1,93 @@ +/* Pokemon Moves Reader + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonFramework/Tools/ConsoleHandle.h" +#include "PokemonSV_PokemonMovesReader.h" + +#include +using std::cout; +using std::endl; + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + + +PokemonMovesOCR& PokemonMovesOCR::instance(){ + static PokemonMovesOCR reader; + return reader; +} + +PokemonMovesOCR::PokemonMovesOCR() + : SmallDictionaryMatcher("PokemonSV/PokemonMovesOCR.json") +{} + +OCR::StringMatchResult PokemonMovesOCR::read_substring( + Logger& logger, + Language language, + const ImageViewRGB32& image, + const std::vector& text_color_ranges, + double min_text_ratio, double max_text_ratio +) const{ + return match_substring_from_image_multifiltered( + &logger, language, image, text_color_ranges, + MAX_LOG10P, MAX_LOG10P_SPREAD, min_text_ratio, max_text_ratio + ); +} + +PokemonMovesReader::PokemonMovesReader(Language language) + : m_language(language) +{ + for (size_t c = 0; c < 4; c++){ + m_boxes_rearrange[c] = ImageFloatBox(0.345, 0.245 + c * 0.074, 0.250, 0.065); + } +} + +void PokemonMovesReader::make_overlays(VideoOverlaySet& items) const{ + for (size_t c = 0; c < 4; c++){ + items.add(COLOR_GREEN, m_boxes_rearrange[c]); + } +} + +std::string PokemonMovesReader::read_move(Logger& logger, const ImageViewRGB32& screen, int8_t index) const{ + ImageViewRGB32 cropped = extract_box_reference(screen, m_boxes_rearrange[index]); + const auto ocr_result = PokemonMovesOCR::instance().read_substring( + logger, m_language, + cropped, OCR::BLACK_OR_WHITE_TEXT_FILTERS() + ); + + std::multimap results; + if (!ocr_result.results.empty()){ + for (const auto& result : ocr_result.results){ + results.emplace(result.first, result.second); + } + } + + if (results.empty()){ + return ""; + } + + if (results.size() > 1){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, + logger, + "MenuOption::read_option(): Unable to read item. Ambiguous or multiple results." + ); + } + + return results.begin()->second.token; +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h new file mode 100644 index 000000000..386a7b422 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h @@ -0,0 +1,62 @@ +/* Pokemon Moves Reader + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_PokemonMovesReader_H +#define PokemonAutomation_PokemonSV_PokemonMovesReader_H + +#include +#include +#include "CommonFramework/Language.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonFramework/OCR/OCR_SmallDictionaryMatcher.h" + +namespace PokemonAutomation{ + class AsyncDispatcher; + class ConsoleHandle; + class BotBaseContext; +namespace NintendoSwitch{ +namespace PokemonSV{ + +class PokemonMovesOCR : public OCR::SmallDictionaryMatcher{ + static constexpr double MAX_LOG10P = -1.30; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + +public: + PokemonMovesOCR(); + + static PokemonMovesOCR& instance(); + + OCR::StringMatchResult read_substring( + Logger& logger, + Language language, + const ImageViewRGB32& image, + const std::vector& text_color_ranges, + double min_text_ratio = 0.01, double max_text_ratio = 0.50 + ) const; + + +}; + +class PokemonMovesReader{ + +public: + PokemonMovesReader(Language language); + + void make_overlays(VideoOverlaySet& items) const; + + std::string read_move(Logger& logger, const ImageViewRGB32& screen, int8_t index) const; + +private: + Language m_language; + std::array m_boxes_rearrange; +}; + + + +} +} +} +#endif