fix: 修复掉落和仓库识别 mask 错误, 缩小 roi

This commit is contained in:
Horror Proton
2023-01-08 02:28:51 +08:00
parent 5932413729
commit d52ffeed8a
3 changed files with 9 additions and 5 deletions

View File

@@ -6598,7 +6598,7 @@
22
],
"maskRange": [
110,
150,
255
]
},
@@ -6718,8 +6718,8 @@
"DepotQuantity": {
"template": "empty.png",
"maskRange": [
0,
110
110,
255
]
},
"DepotBegin": {

View File

@@ -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<cv::Rect>(item.rect)), item_templ * 0.41,

View File

@@ -569,6 +569,8 @@ std::optional<asst::TextRect> 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::TextRect> 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;