From 16002f41bb2528ca67bcbcca7b7eb0c8e9914d6b Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 20 Feb 2024 01:09:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/MaaFramework/Vision/OCRer.cpp | 2 +- source/MaaFramework/Vision/VisionUtils.hpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/MaaFramework/Vision/OCRer.cpp b/source/MaaFramework/Vision/OCRer.cpp index 6e9e4204b..8c52b2a58 100644 --- a/source/MaaFramework/Vision/OCRer.cpp +++ b/source/MaaFramework/Vision/OCRer.cpp @@ -217,7 +217,7 @@ void OCRer::sort(ResultsVec& results) const break; case ResultOrderBy::Length: std::ranges::sort(results, - [](const auto& lhs, const auto& rhs) -> bool { return lhs.box.area() < rhs.box.area(); }); + [](const auto& lhs, const auto& rhs) -> bool { return lhs.text.size() > rhs.text.size(); }); break; default: diff --git a/source/MaaFramework/Vision/VisionUtils.hpp b/source/MaaFramework/Vision/VisionUtils.hpp index 410ac78fb..a283a84ef 100644 --- a/source/MaaFramework/Vision/VisionUtils.hpp +++ b/source/MaaFramework/Vision/VisionUtils.hpp @@ -9,25 +9,23 @@ MAA_VISION_NS_BEGIN -// | 1 2 3 4 | -// | 5 6 7 8 | +// | 1 3 5 7 | +// | 2 4 6 8 | template inline static void sort_by_horizontal_(ResultsVec& results) { std::ranges::sort(results, [](const auto& lhs, const auto& rhs) -> bool { - // y 差距较小则理解为是同一排的,按x排序 - return std::abs(lhs.box.y - rhs.box.y) < 5 ? lhs.box.x < rhs.box.x : lhs.box.y < rhs.box.y; + return lhs.box.x == rhs.box.x ? lhs.box.y < rhs.box.y : lhs.box.x < rhs.box.x; }); } -// | 1 3 5 7 | -// | 2 4 6 8 | +// | 1 2 3 4 | +// | 5 6 7 8 | template inline static void sort_by_vertical_(ResultsVec& results) { std::ranges::sort(results, [](const auto& lhs, const auto& rhs) -> bool { - // x 差距较小则理解为是同一排的,按y排序 - return std::abs(lhs.box.x - rhs.box.x) < 5 ? lhs.box.y < rhs.box.y : lhs.box.x < rhs.box.x; + return lhs.box.y == rhs.box.y ? lhs.box.x < rhs.box.x : lhs.box.y < rhs.box.y; }); } @@ -47,7 +45,7 @@ template inline static void sort_by_area_(ResultsVec& results) { std::ranges::sort(results, - [](const auto& lhs, const auto& rhs) -> bool { return lhs.box.area() < rhs.box.area(); }); + [](const auto& lhs, const auto& rhs) -> bool { return lhs.box.area() > rhs.box.area(); }); } template