From d52ffeed8a806e3f450bf9c707bcd042a81962ef Mon Sep 17 00:00:00 2001 From: Horror Proton <107091537+horror-proton@users.noreply.github.com> Date: Sun, 8 Jan 2023 02:28:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=89=E8=90=BD?= =?UTF-8?q?=E5=92=8C=E4=BB=93=E5=BA=93=E8=AF=86=E5=88=AB=20mask=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF,=20=E7=BC=A9=E5=B0=8F=20roi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/tasks.json | 6 +++--- src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp | 4 +++- .../Vision/Miscellaneous/StageDropsImageAnalyzer.cpp | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/resource/tasks.json b/resource/tasks.json index 8f851a9e4d..97592f7346 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -6598,7 +6598,7 @@ 22 ], "maskRange": [ - 110, + 150, 255 ] }, @@ -6718,8 +6718,8 @@ "DepotQuantity": { "template": "empty.png", "maskRange": [ - 0, - 110 + 110, + 255 ] }, "DepotBegin": { diff --git a/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp b/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp index 8b09a84d70..17d324ca18 100644 --- a/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp +++ b/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp @@ -239,9 +239,11 @@ int asst::DepotImageAnalyzer::match_quantity(const ItemInfo& item) cv::morphologyEx(mask, mask, cv::MORPH_OPEN, cv::getStructuringElement(cv::MORPH_RECT, { 4, 4 })); auto mask_rect = cv::boundingRect(mask); + mask_rect.width -= 1; + mask_rect.height -= 1; if (mask_rect.height < 18) mask_rect.height = 18; // minus 1 to trim white pixels - Rect ocr_roi { item.rect.x + mask_rect.x, item.rect.y + mask_rect.y, mask_rect.width - 1, mask_rect.height - 1 }; + Rect ocr_roi { item.rect.x + mask_rect.x, item.rect.y + mask_rect.y, mask_rect.width, mask_rect.height }; cv::Mat ocr_img = m_image_resized.clone(); cv::subtract(m_image_resized(make_rect(item.rect)), item_templ * 0.41, diff --git a/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp b/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp index 5b256b912f..4857952c1e 100644 --- a/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp +++ b/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp @@ -569,6 +569,8 @@ std::optional asst::StageDropsImageAnalyzer::match_quantity_stri cv::morphologyEx(mask, mask, cv::MORPH_OPEN, cv::getStructuringElement(cv::MORPH_RECT, { 4, 4 })); auto mask_rect = cv::boundingRect(mask); + mask_rect.width -= 1; + mask_rect.height -= 1; if (mask_rect.height < 20) mask_rect.height = 20; cv::Mat ocr_img = m_image.clone(); @@ -578,7 +580,7 @@ std::optional asst::StageDropsImageAnalyzer::match_quantity_stri ocr.set_task_info("StageDrops-NumberOcrReplace"); Rect ocr_roi { new_roi.x + mask_rect.x, new_roi.y + mask_rect.y, mask_rect.width, mask_rect.height }; ocr.set_roi(ocr_roi); - ocr.set_threshold(task_ptr->mask_range.first, task_ptr->mask_range.second); + ocr.set_threshold(110, 255); // TODO: do not hardcode if (!ocr.analyze()) { return std::nullopt;