概述
OpenCV的Sample分析:real_time_tracking(2)
今天接着向下分析,
RobustMatcher rmatcher; // instantiate RobustMatcher
Ptr<FeatureDetector> orb = ORB::create();
rmatcher.setFeatureDetector(orb); // set feature detector
rmatcher.setDescriptorExtractor(orb); // set descriptor extractor
首先ptr是什么意思,根据大牛在CSDN所言“这里Ptr<>模板类就是一种智能指针,也可以理解成一个指针,或者是一个指针类,可以防止内存泄漏等问题,比普通指针好用。”点击打开链接
那么,orb就是一个指向模板类FeatureDetector的智能指针。根据C++primer(page: 415),智能指针的好处就是在调用结束之后,可以自动销毁指针,及指针指向的对像。
那来看一下类RobustMatcher,
class RobustMatcher {
public:
RobustMatcher() : ratio_(0.8f)
{
// ORB is the default feature
detector_ = cv::ORB::create();
extractor_ = cv::ORB::create();
// BruteFroce matcher with Norm Hamming is the default matcher
matcher_ = cv::makePtr<cv::BFMatcher>((int)cv::NORM_HAMMING, false);
}
virtual ~RobustMatcher();
// Set the feature detector
void setFeatureDetector(const cv::Ptr<cv::FeatureDetector>& detect) { detector_ = detect; }
// Set the descriptor extractor
void setDescriptorExtractor(const cv::Ptr<cv::DescriptorExtractor>& desc) { extractor_ = desc; }
// Set the matcher
void setDescriptorMatcher(const cv::Ptr<cv::DescriptorMatcher>& match) { matcher_ = match; }
// Compute the keypoints of an image
void computeKeyPoints( const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints);
// Compute the descriptors of an image given its keypoints
void computeDescriptors( const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints, cv::Mat& descriptors);
// Set ratio parameter for the ratio test
void setRatio( float rat) { ratio_ = rat; }
// Clear matches for which NN ratio is > than threshold
// return the number of removed points
// (corresponding entries being cleared,
// i.e. size will be 0)
int ratioTest(std::vector<std::vector<cv::DMatch> > &matches);
// Insert symmetrical matches in symMatches vector
void symmetryTest( const std::vector<std::vector<cv::DMatch> >& matches1,
const std::vector<std::vector<cv::DMatch> >& matches2,
std::vector<cv::DMatch>& symMatches );
// Match feature points using ratio and symmetry test
void robustMatch( const cv::Mat& frame, std::vector<cv::DMatch>& good_matches,
std::vector<cv::KeyPoint>& keypoints_frame,
const cv::Mat& descriptors_model );
// Match feature points using ratio test
void fastRobustMatch( const cv::Mat& frame, std::vector<cv::DMatch>& good_matches,
std::vector<cv::KeyPoint>& keypoints_frame,
const cv::Mat& descriptors_model );
private:
// pointer to the feature point detector object
cv::Ptr<cv::FeatureDetector> detector_;
// pointer to the feature descriptor extractor object
cv::Ptr<cv::DescriptorExtractor> extractor_;
// pointer to the matcher object
cv::Ptr<cv::DescriptorMatcher> matcher_;
// max ratio between 1st and 2nd NN
float ratio_;
};
这个类RobustMatcher的核心成员是检测detector,获取extractor,匹配matcher,一半的函数都是维护它们的。mathcer是暴力匹配。那怎体现鲁棒性呢?就是该类提供了鲁棒匹配,例如robustMatcher
在学习一个类的时候,看它头文件的注释是最好的选择
因此,这两条代码
rmatcher.setFeatureDetector(orb); // set feature detector
rmatcher.setDescriptorExtractor(orb); // set descriptor extractor
就是初始化RobustMatcher类变量rmatcher的,下面的几条语句继续初始化变量rmatcher,
Ptr<flann::IndexParams> indexParams = makePtr<flann::LshIndexParams>(6, 12, 1); // instantiate LSH index parameters
Ptr<flann::SearchParams> searchParams = makePtr<flann::SearchParams>(50); // instantiate flann search parameters
// instantiate FlannBased matcher
Ptr<DescriptorMatcher> matcher = makePtr<FlannBasedMatcher>(indexParams, searchParams);
rmatcher.setDescriptorMatcher(matcher); // set matcher
rmatcher.setRatio(ratioTest); // set ratio test parameter
总结:
RobustMatcher类变量rmatcher的初始化操作,设置了四个变量,分别是,
1,FeatureDetector 即特征检测
2,DescriptorExtractor 即获取描述子
3, DescriptorMatcher 即描述子匹配
4,Ratio 即匹配比率
下一次分析这个demo中的kalman初始化
最后
以上就是老实钢笔为你收集整理的OpenCV的Sample分析:real_time_tracking(2)的全部内容,希望文章能够帮你解决OpenCV的Sample分析:real_time_tracking(2)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复