diff --git a/src/MeoAssistant/BattlePerspectiveImageAnalyzer.cpp b/src/MeoAssistant/BattlePerspectiveImageAnalyzer.cpp deleted file mode 100644 index 5dd8d7c190..0000000000 --- a/src/MeoAssistant/BattlePerspectiveImageAnalyzer.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "BattlePerspectiveImageAnalyzer.h" - -#include "Logger.hpp" - -bool asst::BattlePerspectiveImageAnalyzer::analyze() -{ - home_analyze(); - return placed_analyze(); -} - -void asst::BattlePerspectiveImageAnalyzer::set_src_homes(std::vector src_homes) -{ - m_src_homes = std::move(src_homes); -} - -asst::Point asst::BattlePerspectiveImageAnalyzer::get_nearest_point() const noexcept -{ - return m_nearest_point; -} - -const std::vector& asst::BattlePerspectiveImageAnalyzer::get_homes() const noexcept -{ - return m_homes.empty() ? m_src_homes : m_homes; -} - -bool asst::BattlePerspectiveImageAnalyzer::placed_analyze() -{ - // 颜色转换 - cv::Mat hsv; - cv::cvtColor(m_image, hsv, cv::COLOR_BGR2HSV); - cv::Mat bin; - cv::inRange(hsv, cv::Scalar(55, 90, 70), cv::Scalar(80, 150, 150), bin); - - // 形态学降噪 - cv::Mat morph_dst = bin; - cv::Mat morph_open_kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(9, 9)); - cv::morphologyEx(morph_dst, morph_dst, cv::MORPH_OPEN, morph_open_kernel); - //cv::Mat morph_close_kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - //cv::morphologyEx(morph_dst, morph_dst, cv::MORPH_CLOSE, morph_close_kernel); - - // 计算可放干员格子的连通域,圈出每个单独的格子 - cv::Mat out, stats, centroids; - int number = cv::connectedComponentsWithStats(morph_dst, out, stats, centroids); - if (number < 2) { - return false; - } - std::vector placed_centers; - for (int i = 1; i != number; ++i) { // 第 0 个是整张图,所以从 1 开始 - int area = stats.at(i, cv::CC_STAT_AREA); - if (area < 300) { - continue; - } - int x = stats.at(i, cv::CC_STAT_LEFT); - int y = stats.at(i, cv::CC_STAT_TOP); - int w = stats.at(i, cv::CC_STAT_WIDTH); - int h = stats.at(i, cv::CC_STAT_HEIGHT); - m_available_placed.emplace_back(Rect(x, y, w, h)); - - int center_x = static_cast(centroids.at(i, 0)); - int center_y = static_cast(centroids.at(i, 1)); - placed_centers.emplace_back(Point(center_x, center_y)); - -#ifdef ASST_DEBUG - cv::circle(m_image_draw, cv::Point(center_x, center_y), 3, cv::Scalar(0, 0, 255), -1); - cv::rectangle(m_image_draw, cv::Rect(x, y, w, h), cv::Scalar(255, 0, 0), 3); -#endif - } - if (m_available_placed.empty()) { - return false; - } - - const auto& all_homes = get_homes(); - if (all_homes.empty()) { - return false; - } - Rect home = all_homes.front(); - - auto nearest_iter = std::min_element(placed_centers.cbegin(), placed_centers.cend(), - [&home](const Point& lhs, const Point& rhs) -> bool { - double lhs_dist = std::pow((home.x - lhs.x), 2) + std::pow((home.y - lhs.y), 2); - double rhs_dist = std::pow((home.x - rhs.x), 2) + std::pow((home.y - rhs.y), 2); - return lhs_dist < rhs_dist; - }); - if (nearest_iter == placed_centers.cend()) { - return false; - } - m_nearest_point = *nearest_iter; - - return true; -} diff --git a/src/MeoAssistant/BattlePerspectiveImageAnalyzer.h b/src/MeoAssistant/BattlePerspectiveImageAnalyzer.h deleted file mode 100644 index f582303717..0000000000 --- a/src/MeoAssistant/BattlePerspectiveImageAnalyzer.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "BattleImageAnalyzer.h" - -namespace asst -{ - // 战斗透视图片,一般是点击干员后的画面 - class BattlePerspectiveImageAnalyzer : public BattleImageAnalyzer - { - public: - using BattleImageAnalyzer::BattleImageAnalyzer; - virtual ~BattlePerspectiveImageAnalyzer() = default; - - virtual bool analyze() override; - virtual const std::vector& get_homes() const noexcept override; - - // 设置非透视状态下蓝色家门的位置 - void set_src_homes(std::vector src_homes); - Point get_nearest_point() const noexcept; - protected: - bool placed_analyze(); // 识别可放置干员的位置 - - std::vector m_src_homes; - std::vector m_available_placed; - Point m_nearest_point; - }; -} diff --git a/src/MeoAssistant/MeoAssistant.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj index a0dfbc5cbe..3ca20fbea1 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -25,7 +25,6 @@ - @@ -81,7 +80,6 @@ - diff --git a/src/MeoAssistant/MeoAssistant.vcxproj.filters b/src/MeoAssistant/MeoAssistant.vcxproj.filters index 397c7be3a8..ce678a9f07 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj.filters +++ b/src/MeoAssistant/MeoAssistant.vcxproj.filters @@ -240,9 +240,6 @@ 头文件\ImageAnalyzer\General - - 头文件\ImageAnalyzer\General - 头文件\ImageAnalyzer @@ -404,9 +401,6 @@ 源文件\ImageAnalyzer\General - - 源文件\ImageAnalyzer - 源文件\ImageAnalyzer diff --git a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp index 0f5165cc83..9d45ace460 100644 --- a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp +++ b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp @@ -1,7 +1,7 @@ #include "RoguelikeBattleTaskPlugin.h" #include "BattleImageAnalyzer.h" -#include "BattlePerspectiveImageAnalyzer.h" +//#include "BattlePerspectiveImageAnalyzer.h" #include "Controller.h" #include "TaskData.h" #include "ProcessTask.h"