diff --git a/3rdparty/include/cpp-base64/base64.hpp b/3rdparty/include/cpp-base64/base64.hpp deleted file mode 100644 index 5ae3c6e5b9..0000000000 --- a/3rdparty/include/cpp-base64/base64.hpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - base64.cpp and base64.h - - base64 encoding and decoding with C++. - More information at - https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp - - Version: 2.rc.08 (release candidate) - - Copyright (C) 2004-2017, 2020, 2021 René Nyffenegger - - This source code is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this source code must not be misrepresented; you must not - claim that you wrote the original source code. If you use this source code - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original source code. - - 3. This notice may not be removed or altered from any source distribution. - - René Nyffenegger rene.nyffenegger@adp-gmbh.ch - -*/ -#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A -#define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A - -#include - -#if __cplusplus >= 201703L -#include -#endif // __cplusplus >= 201703L - -std::string base64_encode (std::string const& s, bool url = false); -std::string base64_encode_pem (std::string const& s); -std::string base64_encode_mime(std::string const& s); - -std::string base64_decode(std::string const& s, bool remove_linebreaks = false); -std::string base64_encode(unsigned char const*, size_t len, bool url = false); - -#if __cplusplus >= 201703L -// -// Interface with std::string_view rather than const std::string& -// Requires C++17 -// Provided by Yannic Bonenberger (https://github.com/Yannic) -// -std::string base64_encode (std::string_view s, bool url = false); -std::string base64_encode_pem (std::string_view s); -std::string base64_encode_mime(std::string_view s); - -std::string base64_decode(std::string_view s, bool remove_linebreaks = false); -#endif // __cplusplus >= 201703L - -#include -#include - - // - // Depending on the url parameter in base64_chars, one of - // two sets of base64 characters needs to be chosen. - // They differ in their last two characters. - // -static const char* base64_chars[2] = { - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" - "+/", - - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" - "-_"}; - -static unsigned int pos_of_char(const unsigned char chr) { - // - // Return the position of chr within base64_encode() - // - - if (chr >= 'A' && chr <= 'Z') return chr - 'A'; - else if (chr >= 'a' && chr <= 'z') return chr - 'a' + ('Z' - 'A') + 1; - else if (chr >= '0' && chr <= '9') return chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2; - else if (chr == '+' || chr == '-') return 62; // Be liberal with input and accept both url ('-') and non-url ('+') base 64 characters ( - else if (chr == '/' || chr == '_') return 63; // Ditto for '/' and '_' - else - // - // 2020-10-23: Throw std::exception rather than const char* - //(Pablo Martin-Gomez, https://github.com/Bouska) - // - throw std::runtime_error("Input is not valid base64-encoded data."); -} - -static std::string insert_linebreaks(std::string str, size_t distance) { - // - // Provided by https://github.com/JomaCorpFX, adapted by me. - // - if (!str.length()) { - return ""; - } - - size_t pos = distance; - - while (pos < str.size()) { - str.insert(pos, "\n"); - pos += distance + 1; - } - - return str; -} - -template -static std::string encode_with_line_breaks(String s) { - return insert_linebreaks(base64_encode(s, false), line_length); -} - -template -static std::string encode_pem(String s) { - return encode_with_line_breaks(s); -} - -template -static std::string encode_mime(String s) { - return encode_with_line_breaks(s); -} - -template -static std::string encode(String s, bool url) { - return base64_encode(reinterpret_cast(s.data()), s.length(), url); -} - -std::string base64_encode(unsigned char const* bytes_to_encode, size_t in_len, bool url) { - - size_t len_encoded = (in_len +2) / 3 * 4; - - unsigned char trailing_char = url ? '.' : '='; - - // - // Choose set of base64 characters. They differ - // for the last two positions, depending on the url - // parameter. - // A bool (as is the parameter url) is guaranteed - // to evaluate to either 0 or 1 in C++ therefore, - // the correct character set is chosen by subscripting - // base64_chars with url. - // - const char* base64_chars_ = base64_chars[url]; - - std::string ret; - ret.reserve(len_encoded); - - unsigned int pos = 0; - - while (pos < in_len) { - ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]); - - if (pos+1 < in_len) { - ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) + ((bytes_to_encode[pos + 1] & 0xf0) >> 4)]); - - if (pos+2 < in_len) { - ret.push_back(base64_chars_[((bytes_to_encode[pos + 1] & 0x0f) << 2) + ((bytes_to_encode[pos + 2] & 0xc0) >> 6)]); - ret.push_back(base64_chars_[ bytes_to_encode[pos + 2] & 0x3f]); - } - else { - ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]); - ret.push_back(trailing_char); - } - } - else { - - ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]); - ret.push_back(trailing_char); - ret.push_back(trailing_char); - } - - pos += 3; - } - - - return ret; -} - -template -static std::string decode(String encoded_string, bool remove_linebreaks) { - // - // decode(…) is templated so that it can be used with String = const std::string& - // or std::string_view (requires at least C++17) - // - - if (encoded_string.empty()) return std::string(); - - if (remove_linebreaks) { - - std::string copy(encoded_string); - - copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end()); - - return base64_decode(copy, false); - } - - size_t length_of_string = encoded_string.length(); - size_t pos = 0; - - // - // The approximate length (bytes) of the decoded string might be one or - // two bytes smaller, depending on the amount of trailing equal signs - // in the encoded string. This approximation is needed to reserve - // enough space in the string to be returned. - // - size_t approx_length_of_decoded_string = length_of_string / 4 * 3; - std::string ret; - ret.reserve(approx_length_of_decoded_string); - - while (pos < length_of_string) { - // - // Iterate over encoded input string in chunks. The size of all - // chunks except the last one is 4 bytes. - // - // The last chunk might be padded with equal signs or dots - // in order to make it 4 bytes in size as well, but this - // is not required as per RFC 2045. - // - // All chunks except the last one produce three output bytes. - // - // The last chunk produces at least one and up to three bytes. - // - - size_t pos_of_char_1 = pos_of_char(encoded_string[pos+1] ); - - // - // Emit the first output byte that is produced in each chunk: - // - ret.push_back(static_cast( ( (pos_of_char(encoded_string[pos+0]) ) << 2 ) + ( (pos_of_char_1 & 0x30 ) >> 4))); - - if ( ( pos + 2 < length_of_string ) && // Check for data that is not padded with equal signs (which is allowed by RFC 2045) - encoded_string[pos+2] != '=' && - encoded_string[pos+2] != '.' // accept URL-safe base 64 strings, too, so check for '.' also. - ) - { - // - // Emit a chunk's second byte (which might not be produced in the last chunk). - // - unsigned int pos_of_char_2 = pos_of_char(encoded_string[pos+2] ); - ret.push_back(static_cast( (( pos_of_char_1 & 0x0f) << 4) + (( pos_of_char_2 & 0x3c) >> 2))); - - if ( ( pos + 3 < length_of_string ) && - encoded_string[pos+3] != '=' && - encoded_string[pos+3] != '.' - ) - { - // - // Emit a chunk's third byte (which might not be produced in the last chunk). - // - ret.push_back(static_cast( ( (pos_of_char_2 & 0x03 ) << 6 ) + pos_of_char(encoded_string[pos+3]) )); - } - } - - pos += 4; - } - - return ret; -} - -std::string base64_decode(std::string const& s, bool remove_linebreaks) { - return decode(s, remove_linebreaks); -} - -std::string base64_encode(std::string const& s, bool url) { - return encode(s, url); -} - -std::string base64_encode_pem (std::string const& s) { - return encode_pem(s); -} - -std::string base64_encode_mime(std::string const& s) { - return encode_mime(s); -} - -#if __cplusplus >= 201703L -// -// Interface with std::string_view rather than const std::string& -// Requires C++17 -// Provided by Yannic Bonenberger (https://github.com/Yannic) -// - -std::string base64_encode(std::string_view s, bool url) { - return encode(s, url); -} - -std::string base64_encode_pem(std::string_view s) { - return encode_pem(s); -} - -std::string base64_encode_mime(std::string_view s) { - return encode_mime(s); -} - -std::string base64_decode(std::string_view s, bool remove_linebreaks) { - return decode(s, remove_linebreaks); -} - -#endif // __cplusplus >= 201703L - -#endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */ \ No newline at end of file diff --git a/README-en.md b/README-en.md index 9e3da470eb..67c2ebdd94 100644 --- a/README-en.md +++ b/README-en.md @@ -96,7 +96,7 @@ Please refer to: [FAQ](docs/en/FAQ.md) - Map tile recognition: [Arknights-Tile-Pos](https://github.com/yuanyan3060/Arknights-Tile-Pos) - C++ JSON library: [meojson](https://github.com/MistEO/meojson.git) - C++ operator parser: [calculator](https://github.com/kimwalisch/calculator) -- C++ Base64 encoding/decoding[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64) +- ~~C++ Base64 encoding/decoding[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64)~~ - C++ ZIP library: [zlib](https://github.com/madler/zlib) - C++ Gzip library: [gzip-hpp](https://github.com/mapbox/gzip-hpp) - WPF MVVW framework: [Stylet](https://github.com/canton7/Stylet) diff --git a/README.md b/README.md index d6eb07d18b..672167bfce 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ MAA 的意思是 MAA Assistant Arknights - 地图格子识别:[Arknights-Tile-Pos](https://github.com/yuanyan3060/Arknights-Tile-Pos) - C++ JSON库:[meojson](https://github.com/MistEO/meojson.git) - C++ 运算符解析器:[calculator](https://github.com/kimwalisch/calculator) -- C++ base64编解码:[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64) +- ~~C++ base64编解码:[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64)~~ - C++ 解压压缩库:[zlib](https://github.com/madler/zlib) - C++ Gzip封装:[gzip-hpp](https://github.com/mapbox/gzip-hpp) - WPF MVVW框架:[Stylet](https://github.com/canton7/Stylet) diff --git a/src/MeoAssistant/AipOcr.cpp b/src/MeoAssistant/AipOcr.cpp deleted file mode 100644 index 3d43a91161..0000000000 --- a/src/MeoAssistant/AipOcr.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "AipOcr.h" - -#include - -#include -#include -#include - -#include "AsstUtils.hpp" -#include "Logger.hpp" -#include "Resource.h" - -bool asst::AipOcr::request_access_token(const std::string& client_id, const std::string& client_secret) -{ - LogTraceFunction; - - m_access_token.clear(); - - std::string_view cmd_fmt = - R"(curl -s -k "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s")"; - - constexpr int cmd_len = 256; - char cmd[cmd_len] = { 0 }; -#ifdef _MSC_VER - sprintf_s(cmd, cmd_len, cmd_fmt.data(), client_id.c_str(), client_secret.c_str()); -#else - sprintf(cmd, cmd_fmt.data(), client_id.c_str(), client_secret.c_str()); -#endif - - Log.trace("call cmd:", cmd); - - std::string response = utils::callcmd(cmd); - - Log.trace("response:", response); - - auto parse_res = json::parse(response); - if (!parse_res) { - return false; - } - try { - auto json = parse_res.value(); - m_access_token = json.at("access_token").as_string(); - } - catch (...) { - return false; - } - return true; -} - -bool asst::AipOcr::request_ocr_general(const cv::Mat& image, std::vector& out_result, const TextRectProc& pred) -{ - LogTraceFunction; - - if (m_access_token.empty()) { - auto& cfg = Resrc.cfg().get_options().aip_ocr; - request_access_token(cfg.client_id, cfg.client_secret); - } - - std::string_view cmd_fmt = - R"(curl -s -k "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=%s" --data "image=%s" -H "Content-Type:application/x-www-form-urlencoded")"; - - return request_ocr_and_parse(cmd_fmt, image, out_result, pred); -} - -bool asst::AipOcr::request_ocr_accurate(const cv::Mat& image, std::vector& out_result, const TextRectProc& pred) -{ - LogTraceFunction; - - if (m_access_token.empty()) { - auto& cfg = Resrc.cfg().get_options().aip_ocr; - request_access_token(cfg.client_id, cfg.client_secret); - } - - std::string_view cmd_fmt = - R"(curl -s -k "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate?access_token=%s" --data "image=%s" -H "Content-Type:application/x-www-form-urlencoded")"; - - return request_ocr_and_parse(cmd_fmt, image, out_result, pred); -} - -bool asst::AipOcr::request_ocr_and_parse(std::string_view cmd_fmt, const cv::Mat& image, std::vector& out_result, const TextRectProc& pred) -{ - if (m_access_token.empty()) { - return false; - } - // CreateProcess 最大只能接受 32767 chars,一张图片随便就超过了 - // 这个功能暂时没法用,得集成下 libcurl 或者别的 - std::vector buf; - cv::imencode(".png", image, buf); - auto* enc_msg = reinterpret_cast(buf.data()); - std::string encoded = base64_encode(enc_msg, buf.size()); - - size_t cmd_len = encoded.size() + cmd_fmt.size() + m_access_token.size(); - auto cmd = new char[cmd_len]; - memset(cmd, 0, cmd_len); -#ifdef _MSC_VER - sprintf_s(cmd, cmd_len, cmd_fmt.data(), m_access_token.c_str(), encoded.c_str()); -#else - sprintf(cmd, cmd_fmt.data(), m_access_token.c_str(), encoded.c_str()); -#endif - Log.trace("call cmd:", cmd); - std::string response = utils::callcmd(cmd); - delete[] cmd; - Log.trace("response:", response); - - auto parse_res = json::parse(response); - if (!parse_res) { - return false; - } - try { - auto json = parse_res.value(); - return parse_response(json, out_result, pred); - } - catch (...) { - return false; - } -} - -bool asst::AipOcr::parse_response(const json::value& json, std::vector& out_result, const TextRectProc& pred) -{ - if (!json.contains("words_result")) { - return false; - } - - std::vector result; - std::string log_str_raw; - std::string log_str_proc; - for (const auto& word : json.at("words_result").as_array()) { - std::string text = word.at("words").as_string(); - - auto& loc = word.at("location").as_object(); - int left = loc.at("left").as_integer(); - int right = loc.at("right").as_integer(); - int top = loc.at("top").as_integer(); - int bottom = loc.at("bottom").as_integer(); - - Rect rect(left, top, right - left, bottom - top); - - TextRect tr{ 0, rect, text }; - - log_str_raw += tr.to_string() + ", "; - if (!pred || pred(tr)) { - log_str_proc += tr.to_string() + ", "; - result.emplace_back(std::move(tr)); - } - } - - Log.trace("AipOcr::parse_response | raw : ", log_str_raw); - Log.trace("AipOcr::parse_response | proc : ", log_str_proc); - - out_result = result; - return true; -} diff --git a/src/MeoAssistant/AipOcr.h b/src/MeoAssistant/AipOcr.h deleted file mode 100644 index 90f2c87a77..0000000000 --- a/src/MeoAssistant/AipOcr.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -#include "AsstTypes.h" - -namespace cv -{ - class Mat; -} -namespace json -{ - class value; -} - -namespace asst -{ - class AipOcr - { - public: - ~AipOcr() = default; - - static AipOcr& get_instance() - { - static AipOcr unique_instance; - return unique_instance; - } - - bool request_access_token(const std::string& client_id, const std::string& client_secret); - bool request_ocr_general(const cv::Mat& image, std::vector& out_result, const TextRectProc& pred = nullptr); - bool request_ocr_accurate(const cv::Mat& image, std::vector& out_result, const TextRectProc& pred = nullptr); - - private: - AipOcr() = default; - AipOcr(const AipOcr&) = default; - AipOcr(AipOcr&&) noexcept = default; - - bool request_ocr_and_parse(std::string_view cmd_fmt, const cv::Mat& image, std::vector& out_result, const TextRectProc& pred = nullptr); - bool parse_response(const json::value& json, std::vector& out_result, const TextRectProc& pred = nullptr); - - std::string m_access_token; - }; -} diff --git a/src/MeoAssistant/BattleProcessTask.cpp b/src/MeoAssistant/BattleProcessTask.cpp index fb4c396c16..95221d32c3 100644 --- a/src/MeoAssistant/BattleProcessTask.cpp +++ b/src/MeoAssistant/BattleProcessTask.cpp @@ -137,12 +137,16 @@ bool asst::BattleProcessTask::analyze_opers_preview() } auto draw_future = std::async(std::launch::async, [&]() { + std::filesystem::create_directory("map"); for (const auto& [loc, info] : m_normal_tile_info) { std::string text = "( " + std::to_string(loc.x) + ", " + std::to_string(loc.y) + " )"; cv::putText(draw, text, cv::Point(info.pos.x - 30, info.pos.y), 1, 1.2, cv::Scalar(0, 0, 255), 2); } - - cv::imwrite("map.png", draw); +#ifdef WIN32 + cv::imwrite("map/" + utils::utf8_to_ansi(m_stage_name) + ".png", image); +#else + cv::imwrite("map/" + m_stage_name + ".png", image); +#endif }); auto opers = oper_analyzer.get_opers(); diff --git a/src/MeoAssistant/GeneralConfiger.cpp b/src/MeoAssistant/GeneralConfiger.cpp index 6bf315d9a0..a2a4d8dde6 100644 --- a/src/MeoAssistant/GeneralConfiger.cpp +++ b/src/MeoAssistant/GeneralConfiger.cpp @@ -20,14 +20,6 @@ bool asst::GeneralConfiger::parse(const json::value& json) auto& penguin_report = options_json.at("penguinReport"); m_options.penguin_report.cmd_format = penguin_report.get("cmdFormat", std::string()); - - if (options_json.contains("aipOcr")) { - auto& aip_ocr = options_json.at("aipOcr"); - m_options.aip_ocr.enable = aip_ocr.get("enable", false); - m_options.aip_ocr.accurate = aip_ocr.get("accurate", false); - m_options.aip_ocr.client_id = aip_ocr.get("clientId", std::string()); - m_options.aip_ocr.client_secret = aip_ocr.get("clientSerect", std::string()); - } } for (const auto& [client_type, intent_name] : json.at("intent").as_object()) { diff --git a/src/MeoAssistant/GeneralConfiger.h b/src/MeoAssistant/GeneralConfiger.h index 913fdd8faa..4e86fa8c53 100644 --- a/src/MeoAssistant/GeneralConfiger.h +++ b/src/MeoAssistant/GeneralConfiger.h @@ -11,14 +11,6 @@ namespace asst { - struct AipOcrCfg // 百度 OCR API 的配置 - { - bool enable = false; - bool accurate = false; // 是否使用高精度识别 - std::string client_id; - std::string client_secret; - }; - struct PenguinReportCfg // 企鹅物流数据汇报 的配置 { std::string cmd_format; // 命令格式 @@ -33,7 +25,6 @@ namespace asst int adb_extra_swipe_dist = 0; // 额外的滑动距离:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来 int adb_extra_swipe_duration = -1; // 额外的滑动持续时间:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来。若小于0,则关闭额外滑动功能 PenguinReportCfg penguin_report; // 企鹅数据汇报:每次到结算界面,汇报掉落数据至企鹅数据 https://penguin-stats.cn/ - AipOcrCfg aip_ocr; // 百度 OCR API 的配置 }; struct AdbCfg diff --git a/src/MeoAssistant/MeoAssistant.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj index 3ee652d33e..647ce4c724 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -67,7 +67,6 @@ - @@ -146,7 +145,6 @@ - diff --git a/src/MeoAssistant/MeoAssistant.vcxproj.filters b/src/MeoAssistant/MeoAssistant.vcxproj.filters index 1f2f42da05..0f43951093 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj.filters +++ b/src/MeoAssistant/MeoAssistant.vcxproj.filters @@ -46,12 +46,6 @@ {c600668a-0d70-4694-b1e5-6a78cffd0b1a} - - {a5c43813-70af-4b0e-94ac-9ddecc2e4a3c} - - - {6cd85910-b561-4cf3-85a2-20be3cd1dd76} - {de865908-2cef-4993-b3ab-1e20290d97b9} @@ -201,9 +195,6 @@ 头文件\Task\Sub\Infrast - - 头文件\Requester - 头文件\Task\Plugin @@ -440,9 +431,6 @@ 源文件\Task\Sub\Infrast - - 源文件\Requester - 源文件\Task\Plugin diff --git a/src/MeoAssistant/OcrImageAnalyzer.cpp b/src/MeoAssistant/OcrImageAnalyzer.cpp index c5013f9a8a..ba7b3be165 100644 --- a/src/MeoAssistant/OcrImageAnalyzer.cpp +++ b/src/MeoAssistant/OcrImageAnalyzer.cpp @@ -5,7 +5,6 @@ #include "Logger.hpp" #include "Resource.h" -#include "AipOcr.h" bool asst::OcrImageAnalyzer::analyze() { @@ -58,36 +57,25 @@ bool asst::OcrImageAnalyzer::analyze() return true; }; - auto& aip_ocr = Resrc.cfg().get_options().aip_ocr; - bool need_local = true; - if (aip_ocr.enable) { - if (aip_ocr.accurate) { - need_local = !AipOcr::get_instance().request_ocr_accurate(m_image, m_ocr_result, all_pred); - } - else { - need_local = !AipOcr::get_instance().request_ocr_general(m_image, m_ocr_result, all_pred); - } + if (m_roi.x < 0) { + Log.warn("roi is out of range", m_roi.to_string()); + m_roi.x = 0; + } + if (m_roi.y < 0) { + Log.warn("roi is out of range", m_roi.to_string()); + m_roi.y = 0; + } + if (m_roi.x + m_roi.width > m_image.cols) { + Log.warn("roi is out of range", m_roi.to_string()); + m_roi.width = m_image.cols - m_roi.x; + } + if (m_roi.y + m_roi.height > m_image.rows) { + Log.warn("roi is out of range", m_roi.to_string()); + m_roi.height = m_image.rows - m_roi.y; } - if (need_local) { - if (m_roi.x < 0) { - Log.warn("roi is out of range", m_roi.to_string()); - m_roi.x = 0; - } - if (m_roi.y < 0) { - Log.warn("roi is out of range", m_roi.to_string()); - m_roi.y = 0; - } - if (m_roi.x + m_roi.width > m_image.cols) { - Log.warn("roi is out of range", m_roi.to_string()); - m_roi.width = m_image.cols - m_roi.x; - } - if (m_roi.y + m_roi.height > m_image.rows) { - Log.warn("roi is out of range", m_roi.to_string()); - m_roi.height = m_image.rows - m_roi.y; - } - m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred, m_without_det); - } + m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred, m_without_det); + //log.trace("ocr result", m_ocr_result); return !m_ocr_result.empty(); } diff --git a/src/MeoAssistant/README.md b/src/MeoAssistant/README.md index 60a5e6f055..2502a8138b 100644 --- a/src/MeoAssistant/README.md +++ b/src/MeoAssistant/README.md @@ -7,21 +7,26 @@ - ~~窗口控制、点击、截图,使用Win32 Api~~ 新版本已全面使用Adb控制 - 部分不响应句柄消息的模拟器,使用Adb控制 -## 识别及解析 +## 开源库 - 图像识别库:[opencv](https://github.com/opencv/opencv.git) - ~~文字识别库:[chineseocr_lite](https://github.com/DayBreak-u/chineseocr_lite.git)~~ - 文字识别库:[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) - ~~关卡掉落识别:[企鹅物流识别](https://github.com/penguin-statistics/recognizer)~~ +- 地图格子识别:[Arknights-Tile-Pos](https://github.com/yuanyan3060/Arknights-Tile-Pos) - C++ JSON库:[meojson](https://github.com/MistEO/meojson.git) - C++ 运算符解析器:[calculator](https://github.com/kimwalisch/calculator) -- C++ base64编解码:[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64) +- ~~C++ base64编解码:[cpp-base64](https://github.com/ReneNyffenegger/cpp-base64)~~ - C++ 解压压缩库:[zlib](https://github.com/madler/zlib) - C++ Gzip封装:[gzip-hpp](https://github.com/mapbox/gzip-hpp) +- WPF MVVW框架:[Stylet](https://github.com/canton7/Stylet) +- WPF控件库:[HandyControl](https://github.com/HandyOrg/HandyControl) +- C# JSON库: [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) +- 下载器:[aria2](https://github.com/aria2/aria2) -## 数据 +## 数据源 -- 公开招募数据:[明日方舟工具箱](https://www.bigfun.cn/tools/aktools/hr) +- ~~公开招募数据:[明日方舟工具箱](https://www.bigfun.cn/tools/aktools/hr)~~ - 干员及基建数据:[PRTS明日方舟中文WIKI](http://prts.wiki/) - 关卡数据:[企鹅物流数据统计](https://penguin-stats.cn/) - 材料数据:[明日方舟bot常用素材](https://github.com/yuanyan3060/Arknights-Bot-Resource) diff --git a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp index 4e87eb7955..443c396f01 100644 --- a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp +++ b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp @@ -1,6 +1,7 @@ #include "RoguelikeBattleTaskPlugin.h" #include +#include #include "BattleImageAnalyzer.h" #include "Controller.h" @@ -117,28 +118,6 @@ bool asst::RoguelikeBattleTaskPlugin::get_stage_info() } if (calced) { - //#ifdef ASST_DEBUG - // auto normal_tiles = tile.calc(m_stage_name, true); - // cv::Mat draw = cv::imread("j.png"); - // for (const auto& [point, info] : normal_tiles) { - // using TileKey = TilePack::TileKey; - // static const std::unordered_map TileKeyMapping = { - // { TileKey::Invalid, "invalid" }, - // { TileKey::Forbidden, "forbidden" }, - // { TileKey::Wall, "wall" }, - // { TileKey::Road, "road" }, - // { TileKey::Home, "end" }, - // { TileKey::EnemyHome, "start" }, - // { TileKey::Floor, "floor" }, - // { TileKey::Hole, "hole" }, - // { TileKey::Telin, "telin" }, - // { TileKey::Telout, "telout" } - // }; - // - // cv::putText(draw, TileKeyMapping.at(info.key), cv::Point(info.pos.x, info.pos.y), 1, 1, cv::Scalar(0, 0, 255)); - // } - //#endif - auto cb_info = basic_info_with_what("StageInfo"); auto& details = cb_info["details"]; details["name"] = m_stage_name; @@ -408,6 +387,17 @@ bool asst::RoguelikeBattleTaskPlugin::wait_start() std::this_thread::yield(); } + std::filesystem::create_directory("map"); + for (const auto& [loc, info] : m_normal_tile_info) { + std::string text = "( " + std::to_string(loc.x) + ", " + std::to_string(loc.y) + " )"; + cv::putText(image, text, cv::Point(info.pos.x - 30, info.pos.y), 1, 1.2, cv::Scalar(0, 0, 255), 2); + } +#ifdef WIN32 + cv::imwrite("map/" + utils::utf8_to_ansi(m_stage_name) + ".png", image); +#else + cv::imwrite("map/" + m_stage_name + ".png", image); +#endif + return true; }