chore. Remove useless files

This commit is contained in:
MistEO
2022-03-27 21:42:04 +08:00
parent 1e73e6fc00
commit fad74cd09d
5 changed files with 1 additions and 125 deletions

View File

@@ -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<Rect> 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::Rect>& 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<Point> placed_centers;
for (int i = 1; i != number; ++i) { // 第 0 个是整张图,所以从 1 开始
int area = stats.at<int>(i, cv::CC_STAT_AREA);
if (area < 300) {
continue;
}
int x = stats.at<int>(i, cv::CC_STAT_LEFT);
int y = stats.at<int>(i, cv::CC_STAT_TOP);
int w = stats.at<int>(i, cv::CC_STAT_WIDTH);
int h = stats.at<int>(i, cv::CC_STAT_HEIGHT);
m_available_placed.emplace_back(Rect(x, y, w, h));
int center_x = static_cast<int>(centroids.at<double>(i, 0));
int center_y = static_cast<int>(centroids.at<double>(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;
}

View File

@@ -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<Rect>& get_homes() const noexcept override;
// 设置非透视状态下蓝色家门的位置
void set_src_homes(std::vector<Rect> src_homes);
Point get_nearest_point() const noexcept;
protected:
bool placed_analyze(); // 识别可放置干员的位置
std::vector<Rect> m_src_homes;
std::vector<Rect> m_available_placed;
Point m_nearest_point;
};
}

View File

@@ -25,7 +25,6 @@
<ClInclude Include="AsstMsg.h" />
<ClInclude Include="AutoRecruitTask.h" />
<ClInclude Include="BattleImageAnalyzer.h" />
<ClInclude Include="BattlePerspectiveImageAnalyzer.h" />
<ClInclude Include="RoguelikeBattleTaskPlugin.h" />
<ClInclude Include="CreditShopImageAnalyzer.h" />
<ClInclude Include="DronesForShamareTaskPlugin.h" />
@@ -81,7 +80,6 @@
<ClCompile Include="AbstractTaskPlugin.cpp" />
<ClCompile Include="AutoRecruitTask.cpp" />
<ClCompile Include="BattleImageAnalyzer.cpp" />
<ClCompile Include="BattlePerspectiveImageAnalyzer.cpp" />
<ClCompile Include="RoguelikeBattleTaskPlugin.cpp" />
<ClCompile Include="CreditShopImageAnalyzer.cpp" />
<ClCompile Include="CreditShoppingTask.cpp" />

View File

@@ -240,9 +240,6 @@
<ClInclude Include="HashImageAnalyzer.h">
<Filter>头文件\ImageAnalyzer\General</Filter>
</ClInclude>
<ClInclude Include="BattlePerspectiveImageAnalyzer.h">
<Filter>头文件\ImageAnalyzer\General</Filter>
</ClInclude>
<ClInclude Include="RoguelikeFormationImageAnalyzer.h">
<Filter>头文件\ImageAnalyzer</Filter>
</ClInclude>
@@ -404,9 +401,6 @@
<ClCompile Include="HashImageAnalyzer.cpp">
<Filter>源文件\ImageAnalyzer\General</Filter>
</ClCompile>
<ClCompile Include="BattlePerspectiveImageAnalyzer.cpp">
<Filter>源文件\ImageAnalyzer</Filter>
</ClCompile>
<ClCompile Include="RoguelikeFormationImageAnalyzer.cpp">
<Filter>源文件\ImageAnalyzer</Filter>
</ClCompile>

View File

@@ -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"