fix: 修复仓库识别结果中材料位置错误的问题

This commit is contained in:
MistEO
2022-06-21 23:53:44 +08:00
parent 82a6e7e6cc
commit d9fb8fa6bc
2 changed files with 27 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ bool asst::DepotImageAnalyzer::analyze()
m_all_items_roi.clear();
m_result.clear();
// 因为模板素材的尺寸与实际截图中素材尺寸不符,所以这里先对原图进行一下缩放
resize();
bool ret = analyze_base_rect();
if (!ret) {
@@ -119,19 +120,21 @@ bool asst::DepotImageAnalyzer::analyze_all_items()
if (cur_pos == NPos) {
break;
}
std::string item_id = info.item_id;
m_match_begin_pos = cur_pos + 1;
info.quantity = match_quantity(info.rect);
info.item_name = res_item.get_item_name(info.item_id);
info.item_name = res_item.get_item_name(item_id);
#ifdef ASST_DEBUG
cv::putText(m_image_draw_resized, info.item_id, cv::Point(roi.x, roi.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2);
cv::putText(m_image_draw_resized, item_id, cv::Point(roi.x, roi.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2);
cv::putText(m_image_draw_resized, std::to_string(info.quantity), cv::Point(roi.x, roi.y + 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2);
#endif
if (info.item_id.empty() || info.quantity == 0) {
Log.error(__FUNCTION__, info.item_id, info.item_name, " quantity is zero");
if (item_id.empty() || info.quantity == 0) {
Log.error(__FUNCTION__, item_id, info.item_name, " quantity is zero");
continue;
}
m_result.emplace(info.item_id, info);
info.rect = resize_rect_to_raw_size(info.rect);
m_result.emplace(std::move(item_id), std::move(info));
}
return !m_result.empty();
}
@@ -286,3 +289,21 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
Log.info("Quantity:", quantity);
return quantity;
}
asst::Rect asst::DepotImageAnalyzer::resize_rect_to_raw_size(const asst::Rect& rect)
{
LogTraceFunction;
m_resized_rect = Task.get("DeoptMatchData")->roi;
double kx = static_cast<double>(m_image.cols) / m_resized_rect.width;
double ky = static_cast<double>(m_image.rows) / m_resized_rect.height;
Rect raw_rect;
raw_rect.x = static_cast<int>(kx * rect.x);
raw_rect.y = static_cast<int>(ky * rect.y);
raw_rect.width = static_cast<int>(kx * rect.width);
raw_rect.height = static_cast<int>(ky * rect.height);
return raw_rect;
}

View File

@@ -35,6 +35,7 @@ namespace asst
bool check_roi_empty(const Rect& roi);
size_t match_item(const Rect& roi, /* out */ ItemInfo& item_info, size_t begin_index = 0ULL, bool with_enlarge = true);
int match_quantity(const Rect& roi);
Rect resize_rect_to_raw_size(const Rect& rect);
size_t m_match_begin_pos = 0ULL;
Rect m_resized_rect;