From 1fdde9a89f6e8872ba4428b3d654db24ca2d8989 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 5 Sep 2021 02:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=BF=9B=E5=85=A5=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=BA=8F=E5=8F=B7=E5=AE=BF=E8=88=8D=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MeoAssistance/Identify.cpp | 29 +++++++++++++++++++++---- MeoAssistance/Identify.h | 6 ++--- MeoAssistance/InfrastDormTask.cpp | 19 ++++++++-------- MeoAssistance/InfrastDormTask.h | 3 ++- MeoAssistance/InfrastStationTask.cpp | 12 +++++----- MeoAssistance/ProcessTask.cpp | 8 +++---- resource/template/special/Dorm.png | Bin 32527 -> 3760 bytes resource/template/special/DormMini.png | Bin 21505 -> 2549 bytes 8 files changed, 50 insertions(+), 27 deletions(-) diff --git a/MeoAssistance/Identify.cpp b/MeoAssistance/Identify.cpp index 69385f1a40..f7ebb0b160 100644 --- a/MeoAssistance/Identify.cpp +++ b/MeoAssistance/Identify.cpp @@ -304,7 +304,8 @@ asst::Identify::FindImageResult asst::Identify::find_image( } } -std::vector asst::Identify::find_all_images(const cv::Mat& image, const std::string& templ_name, double threshold) +std::vector asst::Identify::find_all_images( + const cv::Mat& image, const std::string& templ_name, double threshold) const { if (m_mat_map.find(templ_name) == m_mat_map.cend()) { return std::vector(); @@ -319,17 +320,37 @@ std::vector asst::Identify::find_all_images(con Mat matched; matchTemplate(image_hsv, templ_hsv, matched, cv::TM_CCOEFF_NORMED); - std::vector result; + std::vector results; for (int i = 0; i != matched.rows; ++i) { for (int j = 0; j != matched.cols; ++j) { auto value = matched.at(i, j); if (value >= threshold) { Rect rect = Rect(j, i, templ_mat.cols, templ_mat.rows).center_zoom(0.8); - result.emplace_back(AlgorithmType::MatchTemplate, value, std::move(rect)); + + bool need_push = true; + // 如果有两个点离得太近,只取里面得分高的那个 + // 一般相邻的都是刚刚push进去的,这里倒序快一点 + for (auto iter = results.rbegin(); iter != results.rend(); ++ iter) { + if (std::abs(j - iter->rect.x) < 5 + || std::abs(i - iter->rect.y) < 5) { + if (iter->score < value) { + iter->rect = rect; + iter->score = value; + need_push = false; + } // else 这个点就放弃了 + break; + } + } + if (need_push) { + results.emplace_back(AlgorithmType::MatchTemplate, value, std::move(rect)); + } } } } - return result; + std::sort(results.begin(), results.end(), [](const auto& lhs, const auto& rhs) -> bool { + return lhs.score > rhs.score; + }); + return results; } std::optional