mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
refactor: move make_rect
This commit is contained in:
@@ -144,17 +144,17 @@ bool asst::BattleImageAnalyzer::opers_analyze()
|
||||
if (oper.rect.x + oper.rect.width >= m_image.cols) {
|
||||
oper.rect.width = m_image.cols - oper.rect.x;
|
||||
}
|
||||
oper.avatar = m_image(utils::make_rect<cv::Rect>(oper.rect));
|
||||
oper.avatar = m_image(make_rect<cv::Rect>(oper.rect));
|
||||
|
||||
Rect available_rect = flag_mrect.rect.move(avlb_move);
|
||||
oper.available = oper_available_analyze(available_rect);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
if (oper.available) {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 255, 0), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 255, 0), 2);
|
||||
}
|
||||
else {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -223,7 +223,7 @@ bool asst::BattleImageAnalyzer::oper_cooling_analyze(const Rect& roi)
|
||||
{
|
||||
const auto cooling_task_ptr = Task.get<MatchTaskInfo>("BattleOperCooling");
|
||||
|
||||
auto img_roi = m_image(utils::make_rect<cv::Rect>(roi));
|
||||
auto img_roi = m_image(make_rect<cv::Rect>(roi));
|
||||
cv::Mat hsv;
|
||||
cv::cvtColor(img_roi, hsv, cv::COLOR_BGR2HSV);
|
||||
int h_low = cooling_task_ptr->mask_range.first;
|
||||
@@ -276,7 +276,7 @@ int asst::BattleImageAnalyzer::oper_cost_analyze(const Rect& roi)
|
||||
}
|
||||
|
||||
cv::Mat hsv;
|
||||
cv::cvtColor(m_image(utils::make_rect<cv::Rect>(roi)), hsv, cv::COLOR_BGR2HSV);
|
||||
cv::cvtColor(m_image(make_rect<cv::Rect>(roi)), hsv, cv::COLOR_BGR2HSV);
|
||||
cv::Mat bin;
|
||||
cv::inRange(hsv, range_lower, range_upper, bin);
|
||||
hash_analyzer.set_image(bin);
|
||||
@@ -302,7 +302,7 @@ int asst::BattleImageAnalyzer::oper_cost_analyze(const Rect& roi)
|
||||
bool asst::BattleImageAnalyzer::oper_available_analyze(const Rect& roi)
|
||||
{
|
||||
cv::Mat hsv;
|
||||
cv::cvtColor(m_image(utils::make_rect<cv::Rect>(roi)), hsv, cv::COLOR_BGR2HSV);
|
||||
cv::cvtColor(m_image(make_rect<cv::Rect>(roi)), hsv, cv::COLOR_BGR2HSV);
|
||||
cv::Scalar avg = cv::mean(hsv);
|
||||
Log.trace("oper available, mean", avg[2]);
|
||||
|
||||
@@ -349,7 +349,7 @@ bool asst::BattleImageAnalyzer::home_analyze()
|
||||
m_homes.emplace_back(home_rect);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(home_rect), cv::Scalar(0, 255, 0), 5);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(home_rect), cv::Scalar(0, 255, 0), 5);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -386,7 +386,7 @@ bool asst::BattleImageAnalyzer::hp_analyze()
|
||||
}
|
||||
}
|
||||
Rect roi_rect = flag_analyzer.get_result().rect.move(flag_task_ptr->rect_move);
|
||||
cv::Mat roi = m_image(utils::make_rect<cv::Rect>(roi_rect));
|
||||
cv::Mat roi = m_image(make_rect<cv::Rect>(roi_rect));
|
||||
|
||||
static const std::array<std::string, 10> NumName = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
static bool inited = false;
|
||||
|
||||
@@ -85,7 +85,7 @@ bool asst::CreditShopImageAnalyzer::whether_to_buy_analyze()
|
||||
}
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(commodity), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(commodity), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
m_need_to_buy.emplace_back(
|
||||
commodity, ocr_analyzer.get_result().empty() ? std::string() : ocr_analyzer.get_result().front().text);
|
||||
@@ -109,7 +109,7 @@ bool asst::CreditShopImageAnalyzer::sold_out_analyze()
|
||||
sold_out_analyzer.set_roi(commodity);
|
||||
if (sold_out_analyzer.analyze()) {
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(commodity), cv::Scalar(0, 0, 255));
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(commodity), cv::Scalar(0, 0, 255));
|
||||
cv::putText(m_image_draw, "Sold Out", cv::Point(commodity.x, commodity.y), 1, 2, cv::Scalar(255, 0, 0));
|
||||
#endif // ASST_DEBUG
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ bool asst::DepotImageAnalyzer::analyze_base_rect()
|
||||
const auto& base_rect = base_item_info.rect;
|
||||
const auto& [base_x, base_y, base_w, base_h] = base_rect;
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw_resized, utils::make_rect<cv::Rect>(base_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw_resized, make_rect<cv::Rect>(base_rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
|
||||
// 每个材料之间有间隔,这里 高度 * 2 的 roi, 一定有一个完整的材料 + 一个不完整的材料。
|
||||
@@ -77,7 +77,7 @@ bool asst::DepotImageAnalyzer::analyze_base_rect()
|
||||
pos = match_item(vertical_rect, vertical_item_info, pos + 1);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw_resized, utils::make_rect<cv::Rect>(vertical_item_info.rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw_resized, make_rect<cv::Rect>(vertical_item_info.rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
|
||||
// 宽度 * 2,同上
|
||||
@@ -86,8 +86,7 @@ bool asst::DepotImageAnalyzer::analyze_base_rect()
|
||||
pos = match_item(horizontal_roi, horizontal_item_info, pos + 1);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw_resized, utils::make_rect<cv::Rect>(horizontal_item_info.rect), cv::Scalar(0, 0, 255),
|
||||
2);
|
||||
cv::rectangle(m_image_draw_resized, make_rect<cv::Rect>(horizontal_item_info.rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
|
||||
const int horizontal_spacing = horizontal_item_info.rect.x - (base_x + base_w);
|
||||
@@ -101,7 +100,7 @@ bool asst::DepotImageAnalyzer::analyze_base_rect()
|
||||
}
|
||||
m_all_items_roi.emplace_back(item_roi);
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw_resized, utils::make_rect<cv::Rect>(item_roi), cv::Scalar(0, 255, 0), 2);
|
||||
cv::rectangle(m_image_draw_resized, make_rect<cv::Rect>(item_roi), cv::Scalar(0, 255, 0), 2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -206,7 +205,7 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
|
||||
auto task_ptr = Task.get<MatchTaskInfo>("DepotQuantity");
|
||||
|
||||
Rect quantity_roi = roi.move(task_ptr->roi);
|
||||
cv::Mat quantity_img = m_image_resized(utils::make_rect<cv::Rect>(quantity_roi));
|
||||
cv::Mat quantity_img = m_image_resized(make_rect<cv::Rect>(quantity_roi));
|
||||
cv::Mat hsv;
|
||||
cv::cvtColor(quantity_img, hsv, cv::COLOR_BGR2HSV);
|
||||
|
||||
@@ -298,7 +297,7 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
|
||||
const auto& result = analyzer.get_result().front();
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw_resized, utils::make_rect<cv::Rect>(result.rect), cv::Scalar(0, 0, 255));
|
||||
cv::rectangle(m_image_draw_resized, make_rect<cv::Rect>(result.rect), cv::Scalar(0, 0, 255));
|
||||
cv::putText(m_image_draw_resized, result.text, cv::Point(result.rect.x, result.rect.y - 5),
|
||||
cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0), 2);
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@ bool asst::HashImageAnalyzer::analyze()
|
||||
m_hash_result.clear();
|
||||
m_min_dist_name.clear();
|
||||
|
||||
cv::Mat roi = m_image(utils::make_rect<cv::Rect>(m_roi));
|
||||
cv::Mat roi = m_image(make_rect<cv::Rect>(m_roi));
|
||||
|
||||
if (m_mask_range.first != 0 || m_mask_range.second != 0) {
|
||||
cv::Mat bin;
|
||||
|
||||
@@ -118,7 +118,7 @@ bool asst::MatchImageAnalyzer::match_templ(const cv::Mat templ)
|
||||
m_roi.height = m_image.rows - m_roi.y;
|
||||
}
|
||||
|
||||
cv::Mat image_roi = m_image(utils::make_rect<cv::Rect>(m_roi));
|
||||
cv::Mat image_roi = m_image(make_rect<cv::Rect>(m_roi));
|
||||
if (templ.cols > image_roi.cols || templ.rows > image_roi.rows) {
|
||||
Log.error("templ size is too large", m_templ_name, "image_roi size:", image_roi.cols, image_roi.rows,
|
||||
"templ size:", templ.cols, templ.rows);
|
||||
|
||||
@@ -103,7 +103,7 @@ const std::vector<asst::MatchRect>& asst::MultiMatchImageAnalyzer::get_result()
|
||||
bool asst::MultiMatchImageAnalyzer::multi_match_templ(const cv::Mat templ)
|
||||
{
|
||||
cv::Mat matched;
|
||||
cv::Mat image_roi = m_image(utils::make_rect<cv::Rect>(m_roi));
|
||||
cv::Mat image_roi = m_image(make_rect<cv::Rect>(m_roi));
|
||||
|
||||
if (templ.cols > image_roi.cols || templ.rows > image_roi.rows) {
|
||||
Log.error("templ size is too large", m_templ_name, "image_roi size:", image_roi.cols, image_roi.rows,
|
||||
@@ -151,7 +151,7 @@ bool asst::MultiMatchImageAnalyzer::multi_match_templ(const cv::Mat templ)
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
for (const auto& rect : m_result) {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(rect.rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(rect.rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, std::to_string(rect.score), cv::Point(rect.rect.x, rect.rect.y), 1, 1,
|
||||
cv::Scalar(0, 0, 255));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ bool asst::OcrWithPreprocessImageAnalyzer::analyze()
|
||||
m_without_det = true;
|
||||
|
||||
m_roi = empty_rect_to_full(m_roi, m_image);
|
||||
cv::Mat img_roi = m_image(utils::make_rect<cv::Rect>(m_roi));
|
||||
cv::Mat img_roi = m_image(make_rect<cv::Rect>(m_roi));
|
||||
cv::Mat img_roi_gray;
|
||||
cv::cvtColor(img_roi, img_roi_gray, cv::COLOR_BGR2GRAY);
|
||||
cv::Mat bin;
|
||||
@@ -17,7 +17,7 @@ bool asst::OcrWithPreprocessImageAnalyzer::analyze()
|
||||
cv::Rect bounding_rect = cv::boundingRect(bin);
|
||||
bounding_rect.x += m_roi.x;
|
||||
bounding_rect.y += m_roi.y;
|
||||
auto new_roi = utils::make_rect<Rect>(bounding_rect);
|
||||
auto new_roi = make_rect<Rect>(bounding_rect);
|
||||
|
||||
if (new_roi.empty()) {
|
||||
return false;
|
||||
@@ -32,7 +32,7 @@ bool asst::OcrWithPreprocessImageAnalyzer::analyze()
|
||||
}
|
||||
OcrImageAnalyzer::set_roi(new_roi);
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(new_roi), cv::Scalar(0, 0, 255), 1);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(new_roi), cv::Scalar(0, 0, 255), 1);
|
||||
#endif // ASST_DEBUG
|
||||
|
||||
return OcrImageAnalyzer::analyze();
|
||||
|
||||
@@ -21,7 +21,7 @@ bool asst::InfrastClueVacancyImageAnalyzer::analyze()
|
||||
Rect rect = analyzer.get_result().rect;
|
||||
Log.trace("has", clue_vacancy, suffix);
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, suffix, cv::Point(rect.x, rect.y + 1), 0, 1, cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
m_clue_vacancy.emplace(suffix, rect);
|
||||
|
||||
@@ -73,7 +73,7 @@ bool asst::InfrastFacilityImageAnalyzer::analyze()
|
||||
cv::Scalar rand_color(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
|
||||
int index = 0;
|
||||
for (const MatchRect& mr : cur_facility_result) {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(mr.rect), rand_color, 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(mr.rect), rand_color, 2);
|
||||
cv::Point text_point(mr.rect.x + 2, mr.rect.y + mr.rect.height / 2);
|
||||
cv::putText(m_image_draw, task_name + std::to_string(index++), text_point, 1, 1, cv::Scalar(0, 0, 255), 1);
|
||||
}
|
||||
|
||||
@@ -115,13 +115,13 @@ void asst::InfrastOperImageAnalyzer::oper_detect()
|
||||
}
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(smiley_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(smiley_rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif // ASST_DEBUG
|
||||
|
||||
infrast::Oper oper;
|
||||
oper.smiley = smiley;
|
||||
oper.name_img = m_image(utils::make_rect<cv::Rect>(smiley_rect.move(name_rect_move)));
|
||||
oper.facility_img = m_image(utils::make_rect<cv::Rect>(smiley_rect.move(facility_rect_move)));
|
||||
oper.name_img = m_image(make_rect<cv::Rect>(smiley_rect.move(name_rect_move)));
|
||||
oper.facility_img = m_image(make_rect<cv::Rect>(smiley_rect.move(facility_rect_move)));
|
||||
m_result.emplace_back(std::move(oper));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ void asst::InfrastOperImageAnalyzer::mood_analyze()
|
||||
Rect roi = rect_move;
|
||||
roi.x += oper.smiley.rect.x;
|
||||
roi.y += oper.smiley.rect.y;
|
||||
cv::Mat prg_image = m_image(utils::make_rect<cv::Rect>(roi));
|
||||
cv::Mat prg_image = m_image(make_rect<cv::Rect>(roi));
|
||||
cv::Mat prg_gray;
|
||||
cv::cvtColor(prg_image, prg_gray, cv::COLOR_BGR2GRAY);
|
||||
|
||||
@@ -246,12 +246,12 @@ void asst::InfrastOperImageAnalyzer::skill_analyze()
|
||||
cv::circle(mask, cv::Point(radius, radius), radius, cv::Scalar(255, 255, 255), -1);
|
||||
}
|
||||
|
||||
cv::Mat all_skills_img = m_image(utils::make_rect<cv::Rect>(roi));
|
||||
cv::Mat all_skills_img = m_image(make_rect<cv::Rect>(roi));
|
||||
std::string log_str = "[ ";
|
||||
for (int i = 0; i != MaxNumOfSkills; ++i) {
|
||||
int x = i * skill_width + spacing * i;
|
||||
Rect skill_rect_in_roi(x, 0, skill_width, roi.height);
|
||||
cv::Mat skill_image = all_skills_img(utils::make_rect<cv::Rect>(skill_rect_in_roi));
|
||||
cv::Mat skill_image = all_skills_img(make_rect<cv::Rect>(skill_rect_in_roi));
|
||||
|
||||
// 过滤掉亮度阈值不够的,说明是暗的技能(不是当前设施的技能)
|
||||
cv::Mat skill_gray;
|
||||
@@ -265,7 +265,7 @@ void asst::InfrastOperImageAnalyzer::skill_analyze()
|
||||
skill_rect.y += roi.y;
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(skill_rect), cv::Scalar(0, 255, 0), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(skill_rect), cv::Scalar(0, 255, 0), 2);
|
||||
#endif
|
||||
|
||||
// 针对裁剪出来的每个技能进行识别
|
||||
@@ -329,7 +329,7 @@ void asst::InfrastOperImageAnalyzer::skill_analyze()
|
||||
std::string skill_id = most_confident_skills.id;
|
||||
log_str += skill_id + " - " + most_confident_skills.names.front() + "; ";
|
||||
#ifdef ASST_DEBUG
|
||||
cv::Mat skill_mat = m_image(utils::make_rect<cv::Rect>(skill_rect));
|
||||
cv::Mat skill_mat = m_image(make_rect<cv::Rect>(skill_rect));
|
||||
#endif
|
||||
oper.skills.emplace(std::move(most_confident_skills));
|
||||
}
|
||||
@@ -352,7 +352,7 @@ void asst::InfrastOperImageAnalyzer::selected_analyze()
|
||||
selected_rect.x += oper.smiley.rect.x;
|
||||
selected_rect.y += oper.smiley.rect.y;
|
||||
|
||||
cv::Mat roi = m_image(utils::make_rect<cv::Rect>(selected_rect));
|
||||
cv::Mat roi = m_image(make_rect<cv::Rect>(selected_rect));
|
||||
cv::Mat hsv, bin;
|
||||
cv::cvtColor(roi, hsv, cv::COLOR_BGR2HSV);
|
||||
std::vector<cv::Mat> channels;
|
||||
|
||||
@@ -28,7 +28,7 @@ bool asst::InfrastSmileyImageAnalyzer::analyze()
|
||||
for (const MatchRect& mr : res) {
|
||||
temp_result.emplace_back(infrast::Smiley { type, mr.rect });
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(mr.rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(mr.rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ bool asst::RoguelikeFormationImageAnalyzer::analyze()
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
if (oper.selected) {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 0, 255), 3);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 0, 255), 3);
|
||||
}
|
||||
else {
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 255, 0), 3);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(oper.rect), cv::Scalar(0, 255, 0), 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ const std::vector<asst::RoguelikeFormationImageAnalyzer::FormationOper>& asst::R
|
||||
|
||||
bool asst::RoguelikeFormationImageAnalyzer::selected_analyze(const Rect& roi)
|
||||
{
|
||||
cv::Mat img_roi = m_image(utils::make_rect<cv::Rect>(roi));
|
||||
cv::Mat img_roi = m_image(make_rect<cv::Rect>(roi));
|
||||
cv::Mat hsv;
|
||||
cv::cvtColor(img_roi, hsv, cv::COLOR_BGR2HSV);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ bool asst::StageDropsImageAnalyzer::analyze_stage_code()
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
const Rect& text_rect = analyzer.get_result().front().rect;
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(text_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(text_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, m_stage_code, cv::Point(text_rect.x, text_rect.y - 10), cv::FONT_HERSHEY_SIMPLEX, 1,
|
||||
cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
@@ -103,7 +103,7 @@ bool asst::StageDropsImageAnalyzer::analyze_stars()
|
||||
Log.info(__FUNCTION__, "stars", m_stars);
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(matched_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(matched_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, std::to_string(m_stars) + " stars",
|
||||
cv::Point(matched_rect.x, matched_rect.y + matched_rect.height + 20), cv::FONT_HERSHEY_SIMPLEX, 0.5,
|
||||
cv::Scalar(0, 0, 255), 2);
|
||||
@@ -152,7 +152,7 @@ bool asst::StageDropsImageAnalyzer::analyze_difficulty()
|
||||
Log.info(__FUNCTION__, "difficulty", static_cast<int>(m_difficulty));
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(matched_rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(matched_rect), cv::Scalar(0, 0, 255), 2);
|
||||
matched_name = matched_name.substr(matched_name.find_last_of('-') + 1, matched_name.size());
|
||||
cv::putText(m_image_draw, matched_name, cv::Point(matched_rect.x, matched_rect.y + matched_rect.height + 20),
|
||||
cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2);
|
||||
@@ -194,7 +194,7 @@ bool asst::StageDropsImageAnalyzer::analyze_drops()
|
||||
int quantity = match_quantity(item_roi);
|
||||
Log.info("Item id:", item, ", quantity:", quantity);
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(item_roi), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(item_roi), cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, item, cv::Point(item_roi.x, item_roi.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5,
|
||||
cv::Scalar(0, 0, 255), 2);
|
||||
cv::putText(m_image_draw, std::to_string(quantity), cv::Point(item_roi.x, item_roi.y + 10),
|
||||
@@ -256,7 +256,7 @@ bool asst::StageDropsImageAnalyzer::analyze_baseline()
|
||||
cv::erode(preprocessed_roi, preprocessed_roi, cv::getStructuringElement(cv::MORPH_RECT, { 3, 2 }));
|
||||
|
||||
// cropping after derivatives, dilation, and erosion
|
||||
cv::cvtColor(preprocessed_roi(utils::make_rect<cv::Rect>(task_ptr->roi)), preprocessed_roi, cv::COLOR_BGR2GRAY);
|
||||
cv::cvtColor(preprocessed_roi(make_rect<cv::Rect>(task_ptr->roi)), preprocessed_roi, cv::COLOR_BGR2GRAY);
|
||||
}
|
||||
|
||||
cv::Mat preprocessed_bin;
|
||||
@@ -377,7 +377,7 @@ asst::StageDropType asst::StageDropsImageAnalyzer::match_droptype(const Rect& ro
|
||||
}
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(matched_roi), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(matched_roi), cv::Scalar(0, 0, 255), 2);
|
||||
matched_name = matched_name.substr(matched_name.find_last_of('-') + 1, matched_name.size());
|
||||
cv::putText(m_image_draw, matched_name, cv::Point(matched_roi.x, matched_roi.y + matched_roi.height + 20),
|
||||
cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 1);
|
||||
@@ -463,7 +463,7 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
|
||||
auto task_ptr = Task.get<MatchTaskInfo>("StageDrops-Quantity");
|
||||
|
||||
Rect quantity_roi = roi.move(task_ptr->roi);
|
||||
cv::Mat quantity_img = m_image(utils::make_rect<cv::Rect>(quantity_roi));
|
||||
cv::Mat quantity_img = m_image(make_rect<cv::Rect>(quantity_roi));
|
||||
|
||||
cv::Mat gray;
|
||||
cv::cvtColor(quantity_img, gray, cv::COLOR_BGR2GRAY);
|
||||
@@ -526,7 +526,7 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
|
||||
const auto& result = analyzer.get_result().front();
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(result.rect), cv::Scalar(0, 0, 255));
|
||||
cv::rectangle(m_image_draw, make_rect<cv::Rect>(result.rect), cv::Scalar(0, 0, 255));
|
||||
cv::putText(m_image_draw, result.text, cv::Point(result.rect.x, result.rect.y - 5), cv::FONT_HERSHEY_SIMPLEX, 0.5,
|
||||
cv::Scalar(0, 255, 0), 2);
|
||||
#endif
|
||||
|
||||
@@ -132,7 +132,7 @@ std::vector<asst::TextRect> asst::OcrPack::recognize(const cv::Mat& image, const
|
||||
|
||||
TextRect tr { score, rect, text };
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(draw, utils::make_rect<cv::Rect>(rect), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(draw, make_rect<cv::Rect>(rect), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
raw_result.emplace_back(tr);
|
||||
if (trim) {
|
||||
@@ -162,7 +162,7 @@ std::vector<asst::TextRect> asst::OcrPack::recognize(const cv::Mat& image, const
|
||||
return pred(tr);
|
||||
};
|
||||
Log.trace("OcrPack::recognize | roi:", roi);
|
||||
cv::Mat roi_img = image(utils::make_rect<cv::Rect>(roi));
|
||||
cv::Mat roi_img = image(make_rect<cv::Rect>(roi));
|
||||
return recognize(roi_img, rect_cor, without_det, trim);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +144,12 @@ namespace asst
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
template <typename To, typename From>
|
||||
inline constexpr To make_rect(const From& rect)
|
||||
{
|
||||
return To { rect.x, rect.y, rect.width, rect.height };
|
||||
}
|
||||
|
||||
struct TextRect
|
||||
{
|
||||
TextRect() = default;
|
||||
|
||||
@@ -280,12 +280,6 @@ namespace asst::utils
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename RetTy, typename ArgType>
|
||||
constexpr inline RetTy make_rect(const ArgType& rect)
|
||||
{
|
||||
return RetTy { rect.x, rect.y, rect.width, rect.height };
|
||||
}
|
||||
|
||||
inline std::string load_file_without_bom(const std::filesystem::path& path)
|
||||
{
|
||||
std::ifstream ifs(path, std::ios::in);
|
||||
|
||||
Reference in New Issue
Block a user