openCV中的KeyPoints、DMatch、以及drawMatches函数
1. keypoint类
class CV_EXPORTS_W_SIMPLE KeyPoint
{
public:
//! the default constructor 默认构造函数
CV_WRAP KeyPoint();
/**
@param _pt x & y coordinates of the keypoint
@param _size keypoint diameter
@param _angle keypoint orientation
@param _response keypoint detector response on the keypoint (that is, strength of the keypoint)
@param _octave pyramid octave in which the keypoint has been detected
@param _class_id object id
*/
KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1);
/**
@param x x-coordinate of the keypoint
@param y y-coordinate of the keypoint
@param _size keypoint diameter
@param _angle keypoint orientation
@param _response keypoint detector response on the keypoint (that is, strength of the keypoint)
@param _octave pyramid octave in which the keypoint has been detected
@param _class_id object id
*/
CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1);
size_t hash() const;
/**
This method converts vector of keypoints to vector of points or the reverse, where each keypoint is
assigned the same size and the same orientation.
@param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
@param points2f Array of (x,y) coordinates of each keypoint
@param keypointIndexes Array of indexes of keypoints to be converted to points. (Acts like a mask to
convert only specified keypoints)
*/
CV_WRAP static void convert(const std::vector<KeyPoint>& keypoints,
CV_OUT std::vector<Point2f>& points2f,
const std::vector<int>& keypointIndexes=std::vector<int>());
/** @overload
@param points2f Array of (x,y) coordinates of each keypoint
@param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
@param size keypoint diameter
@param response keypoint detector response on the keypoint (that is, strength of the keypoint)
@param octave pyramid octave in which the keypoint has been detected
@param class_id object id
*/
CV_WRAP static void convert(const std::vector<Point2f>& points2f,
CV_OUT std::vector<KeyPoint>& keypoints,
float size=1, float response=1, int octave=0, int class_id=-1);
/**
This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint
regions' intersection and area of keypoint regions' union (considering keypoint region as circle).
If they don't overlap, we get zero. If they coincide at same location with same size, we get 1.
@param kp1 First keypoint
@param kp2 Second keypoint
*/
CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2);
// 关键点坐标
CV_PROP_RW Point2f pt; //!< coordinates of the keypoints
// 关键点邻域直径大小
CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood
// 特征点方向
CV_PROP_RW 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.
CV_PROP_RW float response; //!< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling
// 关键点所在的图像金字塔的组
CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted
// 用于聚类的ID
CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to)
};
2.Dmatch结构
//////////////////////////////// DMatch /////////////////////////////////
/** @brief Class for matching keypoint descriptors
query descriptor index, train descriptor index, train image index, and distance between
descriptors.
*/
class CV_EXPORTS_W_SIMPLE DMatch
{
public:
CV_WRAP DMatch();
CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance);
CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _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;
};
3.drawMatches函数
// Draws matches of keypints from two images on output image.
void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
const Mat& img2, const vector<KeyPoint>& keypoints2,
const vector<DMatch>& matches1to2, Mat& outIm
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
const vector<char>& matchesMask=vector<char>(), int flags=DrawMatchesFlags::DEFAULT );
void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
const Mat& img2, const vector<KeyPoint>& keypoints2,
const vector<vector<DMatch> >& matches1to2, Mat& outImg,
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
const vector<vector<char> >& matchesMask=vector<vector<char> >(), int flags=DrawMatchesFlags::DEFAULT );
/*
/*其中参数如下:
* img1 – 源图像1
* keypoints1 –源图像1的特征点.
* img2 – 源图像2.
* keypoints2 – 源图像2的特征点
* matches1to2 – 源图像1的特征点匹配源图像2的特征点[matches[i]] .
* outImg – 输出图像具体由flags决定.
* matchColor – 匹配的颜色(特征点和连线),若matchColor==Scalar::all(-1),颜色随机.
* singlePointColor – 单个点的颜色,即未配对的特征点,若matchColor==Scalar::all(-1),颜色随机.
matchesMask – Mask决定哪些点将被画出,若为空,则画出所有匹配点.
* flags – Fdefined by DrawMatchesFlags.
*/