mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
feat: 更新部分 string() 和 Logger
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,8 @@ 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.to_string() + ", score: " + std::to_string(score) + " ]"; }
|
||||
explicit operator std::string() const { return to_string(); }
|
||||
|
||||
double score = 0.0;
|
||||
Rect rect;
|
||||
|
||||
@@ -292,12 +292,12 @@ namespace asst
|
||||
#endif // END _WIN32
|
||||
s << buff;
|
||||
}
|
||||
else if constexpr (std::convertible_to<T, std::string_view>) {
|
||||
s << std::forward<T>(v);
|
||||
}
|
||||
else if constexpr (has_stream_insertion_operator<Stream, T>) {
|
||||
s << std::forward<T>(v);
|
||||
}
|
||||
else if constexpr (std::constructible_from<std::string, T>) {
|
||||
s << std::string(std::forward<T>(v));
|
||||
}
|
||||
else if constexpr (ranges::input_range<T>) {
|
||||
s << "[";
|
||||
std::string_view comma_space {};
|
||||
|
||||
Reference in New Issue
Block a user