mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
fix: RegionOcr阈值过滤膨胀后超出原roi
This commit is contained in:
@@ -38,6 +38,7 @@ RegionOCRer::ResultOpt RegionOCRer::analyze() const
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(new_roi), cv::Scalar(0, 0, 255), 1);
|
||||
#endif // ASST_DEBUG
|
||||
new_roi = correct_rect(new_roi, m_roi);
|
||||
|
||||
OCRer ocr_analyzer;
|
||||
if (m_use_raw) {
|
||||
|
||||
@@ -41,6 +41,38 @@ void VisionHelper::set_log_tracing(bool enable)
|
||||
m_log_tracing = enable;
|
||||
}
|
||||
|
||||
Rect asst::VisionHelper::correct_rect(const Rect& rect, const Rect& main_roi)
|
||||
{
|
||||
if (main_roi.empty()) {
|
||||
return { 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
Rect res = rect;
|
||||
if (res.x < 0) {
|
||||
res.x = 0;
|
||||
res.width = rect.width + rect.x;
|
||||
}
|
||||
if (res.y < 0) {
|
||||
res.y = 0;
|
||||
res.height = rect.height + rect.y;
|
||||
}
|
||||
if (res.x < main_roi.x) {
|
||||
res.x = main_roi.x;
|
||||
res.width = res.width - (main_roi.x - res.x);
|
||||
}
|
||||
if (res.y < main_roi.y) {
|
||||
res.y = main_roi.y;
|
||||
res.height = res.height - (main_roi.y - res.y);
|
||||
}
|
||||
if (res.x + res.width > main_roi.x + main_roi.width) {
|
||||
res.width = main_roi.x + main_roi.width - res.x;
|
||||
}
|
||||
if (res.y + res.height > main_roi.y + main_roi.height) {
|
||||
res.height = main_roi.y + main_roi.height - res.y;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Rect VisionHelper::correct_rect(const Rect& rect, const cv::Mat& image)
|
||||
{
|
||||
if (image.empty()) {
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
virtual void set_log_tracing(bool enable);
|
||||
|
||||
bool save_img(const std::filesystem::path& relative_dir = utils::path("debug"));
|
||||
static Rect correct_rect(const Rect& rect, const Rect& main_roi);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
const cv::Mat& get_draw() const { return m_image_draw; }
|
||||
|
||||
Reference in New Issue
Block a user