OpenCV의 특징점 감지, 설명자 계산 및 특징 일치의 일부 클래스

OpenCV의 일부 기능 추출 클래스 소개

    1. FeatureDetetor(특징점 추출)

FeatureDetetor는 opencv의 가상 클래스이며, opencv의 클래스 정의는 다음과 같습니다.

class CV_EXPORTS FeatureDetector  
{  
public:  
    virtual ~FeatureDetector();  
    void detect( const Mat& image, vector<KeyPoint>& keypoints,  
        const Mat& mask=Mat() ) const;  
    void detect( const vector<Mat>& images,  
        vector<vector<KeyPoint> >& keypoints,  
        const vector<Mat>& masks=vector<Mat>() ) const;  
    virtual void read(const FileNode&);  
    virtual void write(FileStorage&) const;  
    static Ptr<FeatureDetector> create( const string& detectorType );  
protected:  
    ...  
}; 
通过定义FeatureDetector的对象可以使用多种特征检测方法。通过create()函数调用:
Ptr<detector> FeatureDetector::create(const string& detectorType);
/*
其中特征点类型有以下几种。"FAST""STAR""SIFT""SURF""ORB""BRISK""MSER""GFTT""HARRIS""Dense""SimpleBlob"
*/
 也可以直接用单独的类名定义:
Ptr<FeatureDetector> detector = 单独的类名::create();
/*
单独的类名有:FastFeatureDetector、StarFeatureDetector、SIFT (nonfree module)、SURF (nonfree module)、ORB、BRISK、MSER、GoodFeaturesToTrackDetector、GoodFeaturesToTrackDetector with Harris detector enabled、DenseFeatureDetector、SimpleBlobDetector
*/

생성된 키포인트 데이터 구조
각도: angle은 키포인트의 방향을 나타내며 Lowe의 이론에 따르면 방향이 변형되지 않도록 하기 위해 SIFT 알고리즘은 키포인트 주변의 기울기 계산을 수행하여 포인트의 방향을 구합니다. 핵심. -1은 초기값입니다.
class_id: 사진을 분류할 때 class_id를 사용하여 각 특징점을 구분할 수 있으며, 설정하지 않은 경우 -1입니다. 옥타브를 직접 설정해야 합니다. 피라미드의 어느 레이어에서 추출된 데이터를 나타냅니다
.
pt: 핵심 포인트의 좌표
response: 포인트의 강도와 크기를 나타내는 응답 정도. 처음에는 이해할 수 없었습니다 . , http://stackoverflow.com/questions/24699495/opencv-keypoints-response-greater-or-less?lq=1 ) - 응답은 키 포인트가 얼마나 좋은지, 더 정확하게는 모서리의 정도를 나타냅니다. 가리키다. 즉시 이해되었습니다.
size: 점의 직경 크기 문제 참고: keypoint는 위에서 언급한 opencv의 sift 라이브러리에서 감지한 특징점의 일부 기본 정보만 저장하지만 sift에서 추출한 특징 벡터는 실제로 이 안에 없습니다. 특징 벡터는 SiftDescriptorExtractor에 의해 추출되고 결과는 Mat 데이터 구조에 배치됩니다. 이 데이터 구조는 실제로 특징점에 해당하는 특징 벡터를 저장합니다. 자세한 내용은 나중에 SiftDescriptorExtractor가 생성하는 객체에 대한 자세한 설명을 참조하세요.



  1. 설명자추출기

    이전 클래스와 마찬가지로 정의 방법은 다음과 같습니다.

 Ptr<extractor>=DescriptorExtractor::create("ExtractorType"); 
 /*
 ExtractorType有"SIFT""SURF""BRIEF""BRISK""ORB""FREAK"
 */
同上一个类一样,它也可直接调用每种类型的类名。方法如下:
Ptr<DescriptorExtractor> descriptor = 类名::create();
/*
类名有:FREAK、ORB、BRISK、SURF、BriefDescriptorExtractor、SIFT
*/
    1. 설명자 일치자

    DescriptorMatcher는 특징 벡터 일치를 위한 추상 클래스이며 OpenCV2의 특징 일치 방법은 모두 이 클래스에서 상속됩니다(예: BFmatcher, FlannBasedMatcher). 이 클래스에는 주로 이미지 쌍 간의 매칭과 이미지와 이미지 세트 간의 매칭이라는 두 가지 매칭 방법 세트가 포함되어 있습니다.

    (1) 이미지 쌍 간의 매칭에 사용되는 방법 선언

// Find one best match for each query descriptor (if mask is empty).
    CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
    CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
// Find k best matches for each query descriptor (in increasing order of distances).
// compactResult is used when mask is not empty. If compactResult is false matches
// vector will have the same size as queryDescriptors rows. If compactResult is true
// matches vector will not contain matches for fully masked out query descriptors.
    CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
    CV_OUT vector<vector<DMatch> >& matches, int k,const Mat& mask=Mat(), bool compactResult=false ) const;
// Find best matches for each query descriptor which have distance less than
// maxDistance (in increasing order of distances).
    void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
    vector<vector<DMatch> >& matches, float maxDistance,const Mat& mask=Mat(), bool compactResult=false ) const;
 (2)  方法重载,用于图像和图像集匹配的方法声明
CV_WRAP void match( const Mat& queryDescriptors, CV_OUT vector<DMatch>& matches,const vector<Mat>& masks=vector<Mat>() );
CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, int k,const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
void radiusMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, float maxDistance,const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
定义方式如下:
Ptr matcher = DescriptorMatcher::create("matchType");
/*
BruteForce (it uses L2 )
BruteForce-L1
BruteForce-Hamming
BruteForce-Hamming(2)
FlannBased
*/
    1. Dmatch
      Dmatch는 opencv에서 매칭 정보를 저장하는 데 사용되는 구조체로, opencv의 Dmatch 클래스 정의는 다음과 같습니다.
struct CV_EXPORTS_W_SIMPLE DMatch  
{  
//默认构造函数,FLT_MAX是无穷大  
//#define FLT_MAX         3.402823466e+38F        
/* max value */  
    CV_WRAP DMatch() : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {}  
//DMatch构造函数  
    CV_WRAP DMatch( int _queryIdx, int _trainIdx, float _distance ) : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {}  
//DMatch构造函数  
    CV_WRAP DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance ) :queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {}  
//queryIdx为query描述子的索引,match函数中前面的那个描述子  
    CV_PROP_RW int queryIdx;  
//trainIdx为train描述子的索引,match函数中后面的那个描述子  
    CV_PROP_RW int trainIdx;   
//imgIdx为进行匹配图像的索引  
//例如已知一幅图像的sift描述子,与其他十幅图像的描述子进行匹配,找最相似的图像,则imgIdx此时就有用了。  
    CV_PROP_RW int imgIdx; 
//distance为两个描述子之间的距离  
    CV_PROP_RW float distance;  
//DMatch比较运算符重载,比较的是DMatch中的distance,小于为true,否则为false   
    bool operator<( const DMatch &m ) const  
    {  
        return distance < m.distance;  
    }  
};  
    1. drawKeypoints 특징점 감지(feature2d)
      의 drawKeypoints() 함수는 다음과 같습니다.
void drawKeypoints(const Mat& image, const vector<KeyPoint>& keypoints, Mat& outImg, const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT )
//例如:drawKeypoints( img_1, keypoints_1, outimg1, Scalar::all(-1), DrawMatchesFlags::DEFAULT )
其中有 :    image – 原图像、keypoints – 原图像的关键点、outImg – 输出图像、color – 关键点的颜色、flags – 设置绘图功能
    1. drawMatches
void drawMatches(const Mat& img1, const vector<KeyPoint>& keypoints1, const Mat& img2, const vector<KeyPoint>& keypoints2, const vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), const vector<char>& matchesMask=vector<char>(), int flags=DrawMatchesFlags::DEFAULT )

//例如:drawMatches ( img_1, keypoints_1, img_2, keypoints_2, matches, img_match );
其中参数如下:img1 –第一幅图
keypoints1 – 第一幅图的关键点
img2 – 第二幅图
keypoints2 – 第二幅图的关键点
matches – 正确匹配
outImg – 输出图
matchColor – 匹配的颜色(连接线)
如果 matchColor==Scalar::all(-1) , 颜色随机
singlePointColor – 无匹配的点的颜色(圆圈)
如果 singlePointColor==Scalar::all(-1) ,颜色随机
matchesMask – 决定哪些匹配要画出来,若空,则全画
flags – 标志位

추천

출처blog.csdn.net/Lolita_han/article/details/70169702