我是靠谱客的博主 鳗鱼草莓,最近开发中收集的这篇文章主要介绍OpenCV中特征提取描述匹配接口1. 关键点类cv::KeyPoint2. 关键点搜索描述抽象类cv::Feature2D3. 关键点匹配类4. 核心关键点检测算法4. 结果显示,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

目录

  • 1. 关键点类cv::KeyPoint
  • 2. 关键点搜索描述抽象类cv::Feature2D
  • 3. 关键点匹配类
    • 3.1 使用cv::BFMatcher进行暴力匹配
    • 3.2 快速近似最近邻和cv::FlannBasedMatcher
  • 4. 核心关键点检测算法
    • 4.1 Harris-Shi-Tomas特征检测器
    • 4.2 SIFT特征检测器
    • 4.3 SURF特征检测器
    • 4.3 ORB特征检测器
  • 4. 结果显示
    • 4.1 使用cv::drawKeypoints来显示关键点
    • 4.2 使用cv::drawMatches来显示匹配

1. 关键点类cv::KeyPoint

class cv::KeyPoint {
public:
cv::Point2f pt;
float size;
float angle;
float response;
int octave;
int class_id;
cv::KeyPoint(
cv::Point2f _pt,
float _size,
float _angle=-1,
float _response=0,
int _octave=0,
int class_id=-1
);
cv::KeyPoint(
float x,
float y,
float _size,
float _angle=-1,
float _response=0,
int _octave=0,
int class_id=-1
);
...
}

2. 关键点搜索描述抽象类cv::Feature2D

class cv::Feature2D : public cv::Algorithm {
public:
virtual void detect(
cv::InputArray
image,
vector<cv::KeyPoint>& keypoints,
cv::InputArray
mask=cv::noArray()
) const;
virtual void detect(
cv::InputArrayofArrays
images,
vector<vector<cv::KeyPoint>>& keypoints,
cv::InputArrayofArrays
masks=cv::noArray()
) const;
virtual void compute(
cv::InputArray
image,
vector<cv::KeyPoint>& keypoints,
cv::OutputArray
descriptors
//计算得到的关键点列表数据类型为cv::Mat
);
virtual void compute(
cv::InputArrayofArrays
images,
vector<vector<cv::KeyPoint>>& keypoints,
cv::OutputArrayofArrays
descriptors
//描述符参数需要一个包含可用于存储所有生成的描述符的数组的向量
);
virtual void detectAndCompute(
cv::InputArray
image,
cv::InputArray
mask,
vector<cv::KeyPoint>& keypoints,
cv::OutputArray
descriptors,
bool useProvidedKeypoints=false
);
virtual int descriptorSize() const;
virtual int descriptorType() const;
virtual int defaultNorm() const;
virtual int read(const cv::FileNode& );
virtual int write(cv::FileStorage& ) const;
}

3. 关键点匹配类

class cv::DMatch {
public:
DMatch();
DMatch( int _queryIdx, int _trainIdx, float _distance );
DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance );
int queryIdx;
int trainIdx;
int imgIdx;
float distance;
bool operator<( const DMatch &m ) const
}
class cv::DescriptorMatcher {
public:
virtual void add( InputArrayOfArrays descriptors );
virtual void clear();
virtual bool empty() const;
void train();
virtual bool isMaskSupported() const = 0;
const vector<cv::Mat>& getTrainDescriptors() const;
// methods to match descriptors from one list vs. "train" set (recognition)
//
void match(
cv::InputArray queryDescriptors,
vector<cv::DMatch>& matches,
cv::InputArrayOfArrays masks = cv::noArray()
);
void knnMatch(
cv::InputArray queryDescriptors,
vector<vector<cv::DMatch>>& matches,
int k,
cv::InputArrayOfArrays masks = cv::noArray(),
bool compactResult = false
);
void radiusMatch(
cv::InputArray queryDescriptors,
vector<vector<cv::DMatch>>& matches,
float maxDistance,
cv::InputArrayOfArrays masks = cv::noArray(),
bool compactResult = false
);
// methods to match descriptors from two lists (tracking)
//
void match(
cv::InputArray queryDescriptors,
cv::InputArray trainDescriptors,
vector<cv::DMatch>& matches,
cv::InputArrayOfArrays masks = cv::noArray()
);
void knnMatch(
cv::InputArray queryDescriptors,
cv::InputArray trainDescriptors,
vector<vector<cv::DMatch>>& matches,
int k,
cv::InputArrayOfArrays masks = cv::noArray(),
bool compactResult = false
);
void radiusMatch(
cv::InputArray queryDescriptors,
cv::InputArray trainDescriptors,
vector<vector<cv::DMatch>>& matches,
float maxDistance,
cv::InputArrayOfArrays masks = cv::noArray(),
bool compactResult = false
);
virtual void read( const FileNode& );
virtual void write( FileStorge& ) const;
virtual cv::Ptr<cv::DescriptorMatcher> clone(
bool emptyTrainData = false
) const = 0;
static cv::Ptr<cv::DescriptorMatcher> create(
const string& descriptorMatcherType
);
...
}

3.1 使用cv::BFMatcher进行暴力匹配

class cv::BFMatcher : public cv::DescriptorMatcher {
public:
cv::BFMatcher( int normType, bool crossCheck=false );
virtual ~cv::BFMatcher() {}
virtual bool isMaskSupported() const { return true; }
virtual cv::Ptr<cv::DescriptorMatcher> clone(
bool emptyTrainData=false
) const;
...
};

  其中,cv::normType的取值为下表:

度量函数
cv::NORM_L2 d i s t ( a ⃗ , b ⃗ ) = [ ∑ i ( a i − b i ) 2 ] 1 / 2 dist(vec a, vec b)=Big[sum_i (a_i-b_i)^2Big]^{1/2} dist(a ,b )=[i(aibi)2]1/2
cv::NORM_L2SQR d i s t ( a ⃗ , b ⃗ ) = ∑ i ( a i − b i ) 2 dist(vec a, vec b)=sum_i (a_i-b_i)^2 dist(a ,b )=i(aibi)2
cv::NORM_L1 d i s t ( a ⃗ , b ⃗ ) = ∑ i a b s ( a i − b i ) dist(vec a, vec b)=sum_i abs(a_i-b_i) dist(a ,b )=iabs(aibi)
cv::NORM_HAMMING d i s t ( a ⃗ , b ⃗ ) = ∑ i ( a i ! = b i ) ? 1 : 0 dist(vec a, vec b)=sum_i (a_i != b_i)?1:0 dist(a ,b )=i(ai!=bi)?1:0
cv::NORM_HAMMING2 d i s t ( a ⃗ , b ⃗ ) = ∑ i ( e v e n ) [ ( a i = = b i ) & & ( ( a i + 1 = = b i + 1 ) ] ? 1 : 0 dist(vec a, vec b)=sum_{i(bf {even})} Big[(a_i==b_i)&&((a_{i+1}==b_{i+1})Big]?1:0 dist(a ,b )=i(even)[(ai==bi)&&((ai+1==bi+1)]?1:0

3.2 快速近似最近邻和cv::FlannBasedMatcher

class cv::FlannBasedMatcher : public cv::DescriptorMatcher {
public:
cv::FlannBasedMatcher(
const cv::Ptr< cv::flann::IndexParams >& indexParams = new cv::flann::KDTreeIndexParams(),
const cv::Ptr< cv::flann::SearchParams >& searchParams = new cv::flann::SearchParams()
);
virtual void add( const vector<Mat>& descriptors );
virtual void clear();
virtual void train();
virtual bool isMaskSupported() const;
virtual void read();
virtual void write() const;
virtual cv::Ptr<cv::DescriptorMatcher> clone(
bool emptyTrainData = false
)	const;
...
}

4. 核心关键点检测算法

4.1 Harris-Shi-Tomas特征检测器

class cv::GFTTDetector : public cv::Feature2D {
public:
static cv::Ptr<GFTTDetector> create(
int maxCorners
= 1000,
double qualityLevel
= 0.01,
double minDistance
= 1,
int blockSize
= 3,
bool useHarrisDetector = false,
double k
= 0.04
);
...
}

4.2 SIFT特征检测器

class SIFT : public cv::Feature2D {
public:
static cv::Ptr<SIFT> create(
int nfeatures
= 0,
int nOctaveLayers
= 3,
double contrastThreshold = 0.04,
double edgeThreshold
= 10,
double sigma
= 1.6
)
int descriptorSize() const;
int descriptorType() const;
...
};

4.3 SURF特征检测器

class cv::xfeatures2d::SURF : public cv::Feature2D {
public:
static cv::Ptr<SURF> create(
double hessianThreshold
= 100,
int nOctaves
= 4,
int nOctaveLayers
= 3,
bool extended
= false,
bool upright
= false
)
int descriptorSize() const;
int descriptorType() const;
...
};
type SURF SurfFeatureDetector;

4.3 ORB特征检测器

class ORB : public cv::Feature2D {
public:
enum { kBytes = 32, HARRIS_SCORE = 0, FAST_SCORE = 1 };
static cv::Ptr<ORB> create(
int nfeatures = 500,
float scaleFactor = 1.2f,
int nlevels = 8,
int edgeThreshold = 31,
int firstLevel = 0,
int WTA_K = 2,
int scoreType = 0,
int patchSize = 31,
int fastThreshold = 20
);
int descriptorSize() const;
int descriptorType() const;
...
}

4. 结果显示

4.1 使用cv::drawKeypoints来显示关键点

void cv::drawKeypoints(
const cv::Mat& image,
const vector< cv::KeyPoint >& keypoints,
cv::Mat& outImg,
const cv::Scalar& color = cv::Scalar::all(-1),
int flags = cv::DrawMatchesFlags::DEFAULT
);

4.2 使用cv::drawMatches来显示匹配

void cv::drawMatches(
const cv::Mat&
img1,
const vector< cv::KeyPoint >& keypoints1,
const cv::Mat&
img2,
const vector< cv::KeyPoint >& keypoints2,
const vector< cv::DMatch >&
matches1to2,
cv::Mat&
outImg,
const cv::Scalar&
matchColor = cv::Scalar::all(-1),
const cv::Scalar&
singlePointColor = cv::Scalar::all(-1),
const vector< char >&
matchesMask = vector<char>(),
int
flags = cv::DrawMatchesFlags::DEFAULT
);
void cv::drawMatches(
const cv::Mat&
img1,
const vector< cv::KeyPoint >&
keypoints1,
const cv::Mat&
img2,
const vector< cv::KeyPoint >&
keypoints2,
const vector< vector< cv::DMatch > >&
matches1to2,
cv::Mat&
outImg,
const cv::Scalar&
matchColor = cv::Scalar::all(-1),
const cv::Scalar&
singlePointColor = cv::Scalar::all(-1),
const vector< vector< char > >&
matchesMask = vector< vector<char> >(),
int
flags = cv::DrawMatchesFlags::DEFAULT
);

最后

以上就是鳗鱼草莓为你收集整理的OpenCV中特征提取描述匹配接口1. 关键点类cv::KeyPoint2. 关键点搜索描述抽象类cv::Feature2D3. 关键点匹配类4. 核心关键点检测算法4. 结果显示的全部内容,希望文章能够帮你解决OpenCV中特征提取描述匹配接口1. 关键点类cv::KeyPoint2. 关键点搜索描述抽象类cv::Feature2D3. 关键点匹配类4. 核心关键点检测算法4. 结果显示所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部