From d9fb8fa6bc1be4a11214db0a92f74eefa4e92154 Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 21 Jun 2022 23:53:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E7=BB=93=E6=9E=9C=E4=B8=AD=E6=9D=90=E6=96=99?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/DepotImageAnalyzer.cpp | 31 +++++++++++++++++++++---- src/MeoAssistant/DepotImageAnalyzer.h | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/MeoAssistant/DepotImageAnalyzer.cpp b/src/MeoAssistant/DepotImageAnalyzer.cpp index c63618477f..e311958a3d 100644 --- a/src/MeoAssistant/DepotImageAnalyzer.cpp +++ b/src/MeoAssistant/DepotImageAnalyzer.cpp @@ -14,6 +14,7 @@ bool asst::DepotImageAnalyzer::analyze() m_all_items_roi.clear(); m_result.clear(); + // 因为模板素材的尺寸与实际截图中素材尺寸不符,所以这里先对原图进行一下缩放 resize(); bool ret = analyze_base_rect(); if (!ret) { @@ -119,19 +120,21 @@ bool asst::DepotImageAnalyzer::analyze_all_items() if (cur_pos == NPos) { break; } + std::string item_id = info.item_id; m_match_begin_pos = cur_pos + 1; info.quantity = match_quantity(info.rect); - info.item_name = res_item.get_item_name(info.item_id); + info.item_name = res_item.get_item_name(item_id); #ifdef ASST_DEBUG - cv::putText(m_image_draw_resized, info.item_id, cv::Point(roi.x, roi.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2); + cv::putText(m_image_draw_resized, item_id, cv::Point(roi.x, roi.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2); cv::putText(m_image_draw_resized, std::to_string(info.quantity), cv::Point(roi.x, roi.y + 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2); #endif - if (info.item_id.empty() || info.quantity == 0) { - Log.error(__FUNCTION__, info.item_id, info.item_name, " quantity is zero"); + if (item_id.empty() || info.quantity == 0) { + Log.error(__FUNCTION__, item_id, info.item_name, " quantity is zero"); continue; } - m_result.emplace(info.item_id, info); + info.rect = resize_rect_to_raw_size(info.rect); + m_result.emplace(std::move(item_id), std::move(info)); } return !m_result.empty(); } @@ -286,3 +289,21 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi) Log.info("Quantity:", quantity); return quantity; } + +asst::Rect asst::DepotImageAnalyzer::resize_rect_to_raw_size(const asst::Rect& rect) +{ + LogTraceFunction; + + m_resized_rect = Task.get("DeoptMatchData")->roi; + + double kx = static_cast(m_image.cols) / m_resized_rect.width; + double ky = static_cast(m_image.rows) / m_resized_rect.height; + + Rect raw_rect; + raw_rect.x = static_cast(kx * rect.x); + raw_rect.y = static_cast(ky * rect.y); + raw_rect.width = static_cast(kx * rect.width); + raw_rect.height = static_cast(ky * rect.height); + + return raw_rect; +} diff --git a/src/MeoAssistant/DepotImageAnalyzer.h b/src/MeoAssistant/DepotImageAnalyzer.h index 7dc797d205..a9a9cf3aa2 100644 --- a/src/MeoAssistant/DepotImageAnalyzer.h +++ b/src/MeoAssistant/DepotImageAnalyzer.h @@ -35,6 +35,7 @@ namespace asst bool check_roi_empty(const Rect& roi); size_t match_item(const Rect& roi, /* out */ ItemInfo& item_info, size_t begin_index = 0ULL, bool with_enlarge = true); int match_quantity(const Rect& roi); + Rect resize_rect_to_raw_size(const Rect& rect); size_t m_match_begin_pos = 0ULL; Rect m_resized_rect;