fix.修复图片模板越界时的崩溃问题;并添加一些日志

fix #610
This commit is contained in:
MistEO
2022-05-29 17:15:44 +08:00
parent bf50a61dd1
commit fe74e84161
2 changed files with 28 additions and 0 deletions

View File

@@ -100,6 +100,25 @@ bool asst::MatchImageAnalyzer::match_templ(const cv::Mat templ)
{
cv::Mat matched;
Log.trace(__FUNCTION__, "raw_roi", m_roi.to_string());
if (m_roi.x < 0) {
Log.info(__FUNCTION__, "roi is out of range");
m_roi.x = 0;
}
if (m_roi.y < 0) {
Log.info(__FUNCTION__, "roi is out of range");
m_roi.y = 0;
}
if (m_roi.x + m_roi.width >= m_image.cols) {
Log.info(__FUNCTION__, "roi is out of range");
m_roi.width = m_image.cols - m_roi.x;
}
if (m_roi.y + m_roi.height >= m_image.rows) {
Log.info(__FUNCTION__, "roi is out of range");
m_roi.height = m_image.rows - m_roi.y;
}
cv::Mat image_roi = m_image(utils::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,

View File

@@ -60,6 +60,8 @@ bool asst::StageDropsImageAnalyzer::analyze_stage_code()
}
m_stage_code = analyzer.get_result().front().text;
Log.info(__FUNCTION__, "stage_code", m_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);
@@ -104,6 +106,8 @@ bool asst::StageDropsImageAnalyzer::analyze_stars()
}
m_stars = matched_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::putText(m_image_draw, std::to_string(m_stars) + " stars", cv::Point(matched_rect.x, matched_rect.y + matched_rect.height + 20),
@@ -150,6 +154,7 @@ bool asst::StageDropsImageAnalyzer::analyze_difficulty()
}
}
m_difficulty = matched;
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);
@@ -285,6 +290,10 @@ bool asst::StageDropsImageAnalyzer::analyze_baseline()
m_baseline.emplace_back(baseline, match_droptype(baseline));
}
}
Log.trace(__FUNCTION__, "baseline size", m_baseline.size());
for (const auto& baseline : m_baseline) {
Log.trace(__FUNCTION__, "baseline", baseline.first.to_string());
}
return !m_baseline.empty();
}