您的位置:首页 > 运维架构

【opencv练习38 - SURF描述子】

2016-09-14 22:34 232 查看
SURF特征(speed up robust feature) 加速鲁棒特征

一种尺度不变特征检测器,其是SIFT(scale invariant feature transform 尺度不变特征变换)的高效变种算法。

特点:

1)运算速度快,实时性

2)尺度不变,稳定性

3)方向无关,稳定性

具体实现:

1.对每个像素计算Hessian矩阵

2….

3….

/*******************************************************************
测试程序 SURF描述子
时间:2016年9月5日
*******************************************************************/

void readme();

int main( void )
{

Mat img_1 = imread( "1.jpg" , CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( "2.jpg" , CV_LOAD_IMAGE_GRAYSCALE );

if( !img_1.data || !img_2.data )
{
cout<<"Step 000 OK"<<endl;
return -1;
}

//Step 1: 使用SURF【检测子】,检测关键点 **************************************
int minHessian = 400;

SurfFeatureDetector detector( minHessian );

std::vector<KeyPoint> keypoints_1, keypoints_2;

//检测(图像 --> 点向量)
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
cout<<"Step 1 detect OK!!!"<<endl;

//-- Step 2: 计算【描述子】(特征向量)**************************************
SurfDescriptorExtractor extractor;

Mat descriptors_1, descriptors_2;

//检测(图像 + 点向量 --> 描述子)
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
cout<<"Step 2 compute OK!!!"<<endl;

//-- Step 3: 匹配描述子向量 with a brute force matcher **************************************
BFMatcher matcher(NORM_L2);
std::vector< DMatch > matches;

//检测(描述子1 + 描述子2 --> matches)
matcher.match( descriptors_1, descriptors_2, matches );

cout<<"Step 3 match OK!!!"<<endl;
//绘制匹配 -- Draw matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
//-- 图像1+关键点1 + 图像2+关键点2 + matches向量 ——> 合成输出图像
imshow("Matches", img_matches );

waitKey(0);

return 0;
}

void readme()
{
std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencv sift SURF 特征点