diff --git a/src/MeoAssistant/ImageAnalyzer/General/MatchImageAnalyzer.cpp b/src/MeoAssistant/ImageAnalyzer/General/MatchImageAnalyzer.cpp index 65765ffc92..55b9338e46 100644 --- a/src/MeoAssistant/ImageAnalyzer/General/MatchImageAnalyzer.cpp +++ b/src/MeoAssistant/ImageAnalyzer/General/MatchImageAnalyzer.cpp @@ -102,19 +102,19 @@ void asst::MatchImageAnalyzer::set_task_info(MatchTaskInfo task_info) noexcept bool asst::MatchImageAnalyzer::match_templ(const cv::Mat templ) { if (m_roi.x < 0) { - Log.warn("roi is out of range", m_roi.to_string()); + Log.warn("roi is out of range", m_roi); m_roi.x = 0; } if (m_roi.y < 0) { - Log.warn("roi is out of range", m_roi.to_string()); + Log.warn("roi is out of range", m_roi); 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()); + Log.warn("roi is out of range", m_roi); 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()); + Log.warn("roi is out of range", m_roi); m_roi.height = m_image.rows - m_roi.y; } @@ -148,8 +148,7 @@ bool asst::MatchImageAnalyzer::match_templ(const cv::Mat templ) max_val = 0; } if (max_val > m_templ_thres * 0.7) { // 得分太低的肯定不对,没必要打印 - Log.trace("match_templ |", m_templ_name, "score:", max_val, "rect:", rect.to_string(), - "roi:", m_roi.to_string()); + Log.trace("match_templ |", m_templ_name, "score:", max_val, "rect:", rect, "roi:", m_roi); } if (m_templ_thres <= max_val && max_val < 2.0) { diff --git a/src/MeoAssistant/ImageAnalyzer/General/MultiMatchImageAnalyzer.cpp b/src/MeoAssistant/ImageAnalyzer/General/MultiMatchImageAnalyzer.cpp index 8cb93c8c86..bfd76abfb2 100644 --- a/src/MeoAssistant/ImageAnalyzer/General/MultiMatchImageAnalyzer.cpp +++ b/src/MeoAssistant/ImageAnalyzer/General/MultiMatchImageAnalyzer.cpp @@ -157,12 +157,7 @@ bool asst::MultiMatchImageAnalyzer::multi_match_templ(const cv::Mat templ) } #endif - std::string log_str = "[ "; - for (const auto& res : m_result) { - log_str += res.rect.to_string() + " : " + std::to_string(res.score) + "; "; - } - log_str += "]"; - Log.trace("multi_match_templ | ", m_templ_name, log_str, "roi:", m_roi.to_string()); + Log.trace("multi_match_templ | ", m_templ_name, "result:", m_result, "roi:", m_roi); if (!m_result.empty()) { return true; diff --git a/src/MeoAssistant/Resource/OcrPack.cpp b/src/MeoAssistant/Resource/OcrPack.cpp index 83b79c518c..5c83dd9147 100644 --- a/src/MeoAssistant/Resource/OcrPack.cpp +++ b/src/MeoAssistant/Resource/OcrPack.cpp @@ -105,8 +105,7 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const } std::vector result; - std::string log_str_raw; - std::string log_str_proc; + std::vector raw_result; #ifdef ASST_DEBUG cv::Mat draw = image.clone(); @@ -121,10 +120,8 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const int* box = m_boxes_buffer + i * 8; int x_collect[4] = { *(box + 0), *(box + 2), *(box + 4), *(box + 6) }; int y_collect[4] = { *(box + 1), *(box + 3), *(box + 5), *(box + 7) }; - int left = static_cast(*std::min_element(x_collect, x_collect + 4)); - int right = static_cast(*std::max_element(x_collect, x_collect + 4)); - int top = static_cast(*std::min_element(y_collect, y_collect + 4)); - int bottom = static_cast(*std::max_element(y_collect, y_collect + 4)); + auto [left, right] = ranges::minmax(x_collect); + auto [top, bottom] = ranges::minmax(y_collect); rect = Rect(left, top, right - left, bottom - top); } std::string text(*(m_strs_buffer + i)); @@ -137,15 +134,14 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const #ifdef ASST_DEBUG cv::rectangle(draw, utils::make_rect(rect), cv::Scalar(0, 0, 255), 2); #endif - log_str_raw += tr.to_string() + ", "; + raw_result.emplace_back(tr); if (!pred || pred(tr)) { - log_str_proc += tr.to_string() + ", "; result.emplace_back(std::move(tr)); } } - Log.trace("OcrPack::recognize | raw : ", log_str_raw); - Log.trace("OcrPack::recognize | proc : ", log_str_proc); + Log.trace("OcrPack::recognize | raw:", raw_result); + Log.trace("OcrPack::recognize | proc:", result); return result; } @@ -162,7 +158,7 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const } return pred(tr); }; - Log.trace("OcrPack::recognize | roi : ", roi.to_string()); + Log.trace("OcrPack::recognize | roi:", roi); cv::Mat roi_img = image(utils::make_rect(roi)); return recognize(roi_img, rect_cor, without_det); } diff --git a/src/MeoAssistant/Utils/AsstTypes.h b/src/MeoAssistant/Utils/AsstTypes.h index cee0aff934..d99b7ef5a6 100644 --- a/src/MeoAssistant/Utils/AsstTypes.h +++ b/src/MeoAssistant/Utils/AsstTypes.h @@ -38,7 +38,8 @@ namespace asst Point& operator=(Point&&) noexcept = default; Point operator-() const noexcept { return { -x, -y }; } bool operator==(const Point& rhs) const noexcept { return x == rhs.x && y == rhs.y; } - std::string to_string() const { return "[ " + std::to_string(x) + ", " + std::to_string(y) + " ]"; } + std::string to_string() const { return "(" + std::to_string(x) + ", " + std::to_string(y) + ")"; } + explicit operator std::string() const { return to_string(); } static constexpr Point right() { return { 1, 0 }; } static constexpr Point down() { return { 0, 1 }; } static constexpr Point left() { return { -1, 0 }; } @@ -115,11 +116,11 @@ namespace asst } Rect& operator=(const Rect&) noexcept = default; Rect& operator=(Rect&&) noexcept = default; - bool empty() const noexcept { return width == 0 || height == 0; } bool operator==(const Rect& rhs) const noexcept { return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height; } + bool empty() const noexcept { return width == 0 || height == 0; } bool include(const Rect& rhs) const noexcept { return x <= rhs.x && y <= rhs.y && (x + width) >= (rhs.x + rhs.width) && @@ -134,6 +135,7 @@ namespace asst return "[ " + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(width) + ", " + std::to_string(height) + " ]"; } + explicit operator std::string() const { return to_string(); } Rect move(Rect move) const { return { x + move.x, y + move.y, move.width, move.height }; } int x = 0; @@ -150,13 +152,16 @@ namespace asst TextRect(TextRect&&) noexcept = default; TextRect(double score, const Rect& rect, const std::string& text) : score(score), rect(rect), text(text) {} - explicit operator std::string() const noexcept { return text; } - explicit operator Rect() const noexcept { return rect; } - std::string to_string() const { return text + " : " + rect.to_string() + ", score: " + std::to_string(score); } TextRect& operator=(const TextRect&) = default; TextRect& operator=(TextRect&&) noexcept = default; bool operator==(const TextRect& rhs) const noexcept { return text == rhs.text && rect == rhs.rect; } bool operator==(const std::string& rhs) const noexcept { return text == rhs; } + explicit operator Rect() const noexcept { return rect; } + std::string to_string() const + { + return "{ " + text + ": " + rect.to_string() + ", score: " + std::to_string(score) + " }"; + } + explicit operator std::string() const { return to_string(); } double score = 0.0; Rect rect; @@ -184,6 +189,11 @@ namespace asst explicit operator Rect() const noexcept { return rect; } MatchRect& operator=(const MatchRect&) = default; MatchRect& operator=(MatchRect&&) noexcept = default; + std::string to_string() const + { + return "{ rect: " + rect.to_string() + ", score: " + std::to_string(score) + " }"; + } + explicit operator std::string() const { return to_string(); } double score = 0.0; Rect rect; diff --git a/src/MeoAssistant/Utils/Logger.hpp b/src/MeoAssistant/Utils/Logger.hpp index ca43bb7e10..23e89f0372 100644 --- a/src/MeoAssistant/Utils/Logger.hpp +++ b/src/MeoAssistant/Utils/Logger.hpp @@ -292,12 +292,12 @@ namespace asst #endif // END _WIN32 s << buff; } - else if constexpr (std::convertible_to) { - s << std::forward(v); - } else if constexpr (has_stream_insertion_operator) { s << std::forward(v); } + else if constexpr (std::constructible_from) { + s << std::string(std::forward(v)); + } else if constexpr (ranges::input_range) { s << "["; std::string_view comma_space {};