Opencv中的KeyPoints和DMatche類
阿新 • • 發佈:2018-12-13
/***好記性不如爛筆頭,便於後續複習***/
最近用到OpenCV中KeyPoints和DMatch類,有些記憶模糊,特此記下!
一、DMatche類:
/******* DMatch ******/ /* Struct for matching: query descriptor index, train descriptor index, train image index, distance between descriptors. */ struct DMatch { //有三個建構函式 DMatch() : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {} DMatch( int _queryIdx, int _trainIdx, float _distance ) : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {} DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance ) : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {} //有四個成員變數 CV_PROP_RW int queryIdx; //此匹配對應的查詢影象的特徵描述子索引 query descriptor index CV_PROP_RW int trainIdx; //此匹配對應的訓練(模板)影象的特徵描述子索引 train descriptor index CV_PROP_RW int imgIdx; //訓練影象的索引(若有多個) train image index CV_PROP_RW float distance;//兩個特徵向量之間的歐氏距離,越小表明匹配度越高 // less is better bool operator<( const DMatch &m ) const { return distance < m.distance; } };
二、KeyPoint類:
/******** The Keypoint Class The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint detectors, such as Harris corner detector, cv::FAST, cv::StarDetector, cv::SURF, cv::SIFT, cv::LDetector etc. ********/ class KeyPoint { public: // the default constructor預設建構函式 KeyPoint() : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {} // the full constructor KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1) :pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} // another form of the full constructor KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1) :pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} size_t hash() const; // converts vector of keypoints to vector of points static void convert(const vector<KeyPoint>& keypoints, CV_OUT vector<Point2f>& points2f, const vector<int>& keypointIndexes=vector<int>()); // converts vector of points to the vector of keypoints, where each keypoint is assigned the same size and the same orientation static void convert(const vector<Point2f>& points2f, CV_OUT vector<KeyPoint>& keypoints, float size=1, float response=1, int octave=0, int class_id=-1); // computes overlap for pair of keypoints; // overlap is a ratio between area of keypoint regions intersection and // area of keypoint regions union (now keypoint region is circle) static float overlap(const KeyPoint& kp1, const KeyPoint& kp2); Point2f pt; //<關鍵點座標coordinates of the keypoints> float size; //<關鍵點鄰域直徑大小diameter of the meaningful keypoint neighborhood float angle; //<特徵點方向computed orientation of the keypoint (-1 if not applicable); //< it's in [0,360) degrees and measured relative to //< image coordinate system, ie in clockwise. float response; //< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling int octave; //<關鍵點所在的影象金字塔的組octave (pyramid layer) from which the keypoint has been extracted int class_id; //<用於聚類的ID object class (if the keypoints need to be clustered by an object they belong to) };