Files
MaaAssistantArknights/src/MaaCore/Vision/FeatureMatcher.h
status102 263b16ac8b 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>
2025-05-13 18:24:16 +08:00

59 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "Vision/Config/FeatureMatcherConfig.h"
#include "VisionHelper.h"
#include <meojson/json.hpp>
#include <ostream>
#include <vector>
// MAA_SUPPRESS_CV_WARNINGS_BEGIN
#include <opencv2/features2d.hpp>
// MAA_SUPPRESS_CV_WARNINGS_END
namespace asst
{
class FeatureMatcher : public VisionHelper, public FeatureMatcherConfig
{
public:
using Result = FeatureMatchRect;
using ResultsVec = std::vector<Result>;
using ResultsVecOpt = std::optional<ResultsVec>;
public:
using VisionHelper::VisionHelper;
virtual ~FeatureMatcher() override = default;
// analyze函数用于分析图像返回匹配结果
ResultsVecOpt analyze() const;
// FIXME: 老接口太难重构了,先弄个这玩意兼容下,后续慢慢全删掉
const auto& get_result() const noexcept { return m_result; }
protected:
virtual void _set_roi(const Rect& roi) override { set_roi(roi); }
private:
// FIXME: 老接口太难重构了,先弄个这玩意兼容下,后续慢慢全删掉
mutable ResultsVec m_result;
private:
std::pair<std::vector<cv::KeyPoint>, cv::Mat> detect(const cv::Mat& image, const cv::Mat& mask) const;
asst::FeatureMatcher::ResultsVec feature_match(
const cv::Mat& templ,
const std::vector<cv::KeyPoint>& keypoints_1,
const cv::Mat& descriptors_1) const;
std::vector<std::vector<cv::DMatch>> match(const cv::Mat& descriptors_1, const cv::Mat& descriptors_2) const;
asst::FeatureMatcher::ResultsVec feature_postproc(
const std::vector<std::vector<cv::DMatch>>& match_points,
const std::vector<cv::KeyPoint>& keypoints_1,
const std::vector<cv::KeyPoint>& keypoints_2,
int templ_cols,
int templ_rows,
std::vector<cv::DMatch>& good_matches) const;
cv::Ptr<cv::Feature2D> create_detector() const;
cv::Ptr<cv::DescriptorMatcher> create_matcher() const;
};
} // namespace asst