mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 10:00:44 +08:00
feat: 特征匹配 (#10966)
* feat: 特征匹配 * chore: 测试内容 * refactor: 根据最新版本重新迁移, 移除多模板 * chore: Auto update by pre-commit hooks [skip changelog] * chore: 测试移除 * fix: platform * chore: docs --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -80,6 +80,23 @@ Rect VisionHelper::correct_rect(const Rect& rect, const cv::Mat& image)
|
||||
return res;
|
||||
}
|
||||
|
||||
cv::Mat asst::VisionHelper::create_mask(const cv::Mat& image, bool green_mask)
|
||||
{
|
||||
cv::Mat mask = cv::Mat::ones(image.size(), CV_8UC1);
|
||||
if (green_mask) {
|
||||
cv::inRange(image, cv::Scalar(0, 255, 0), cv::Scalar(0, 255, 0), mask);
|
||||
mask = ~mask;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
cv::Mat asst::VisionHelper::create_mask(const cv::Mat& image, const cv::Rect& roi)
|
||||
{
|
||||
cv::Mat mask = cv::Mat::zeros(image.size(), CV_8UC1);
|
||||
mask(roi) = 255;
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool VisionHelper::save_img(const std::filesystem::path& relative_dir)
|
||||
{
|
||||
std::string stem = utils::get_time_filestem();
|
||||
@@ -93,3 +110,33 @@ bool VisionHelper::save_img(const std::filesystem::path& relative_dir)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
cv::Mat VisionHelper::draw_roi(const cv::Rect& roi, const cv::Mat& base) const
|
||||
{
|
||||
cv::Mat image_draw = base.empty() ? m_image.clone() : base;
|
||||
const cv::Scalar color(0, 255, 0);
|
||||
|
||||
// cv::putText(image_draw, name_, cv::Point(5, m_image.rows - 5), cv::FONT_HERSHEY_SIMPLEX, 1, color, 2);
|
||||
|
||||
cv::rectangle(image_draw, roi, color, 1);
|
||||
// std::string flag = MAA_FMT::format("ROI: [{}, {}, {}, {}]", roi.x, roi.y, roi.width, roi.height);
|
||||
std::string flag = "ROI: [" + std::to_string(roi.x) + ", " + std::to_string(roi.y) + ", " +
|
||||
std::to_string(roi.width) + ", " + std::to_string(roi.height) + "]";
|
||||
cv::putText(image_draw, flag, cv::Point(roi.x, roi.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
|
||||
|
||||
return image_draw;
|
||||
}
|
||||
|
||||
/*
|
||||
void VisionHelper::handle_draw(const cv::Mat& draw) const
|
||||
{
|
||||
|
||||
if (show_draw_) {
|
||||
const std::string kWinName = "Draw";
|
||||
cv::imshow(kWinName, draw);
|
||||
cv::waitKey(0);
|
||||
cv::destroyWindow(kWinName);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user