opencv2.4.9 的函数怎么调用

 我来答
匿名用户
2016-08-17
展开全部

opencv2.4.9 调用sift特征,注意头文件,其他头文件可能造成sift检测器创建失败!!!!!!!!!!!

LIB:

opencv_core249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_nonfree249d.lib
opencv_features2d249d.lib
opencv_photo249d.lib
opencv_calib3d249.lib
opencv_calib3d249d.lib
opencv_contrib249.lib
opencv_contrib249d.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_flann249d.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
opencv_gpu249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_stitching249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib


// opencv_empty_proj.cpp : 定义控制台应用程序的入口点。

// 


#include "stdafx.h" 
#include <opencv2/core/core.hpp>   
#include <opencv2/highgui/highgui.hpp>   
#include <opencv2/features2d/features2d.hpp>   
#include <opencv2/nonfree/features2d.hpp>   
#include <opencv2/nonfree/nonfree.hpp> 
#include <iostream> 


using namespace std; 
using namespace cv; 


int _tmain(int argc, _TCHAR* argv[]) 

initModule_nonfree();//初始化模块,使用SIFT或SURF时用到   
Ptr<FeatureDetector> detector = FeatureDetector::create( "SIFT" );//创建SIFT特征检测器   
Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );//创建特征向量生成器   
Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );//创建特征匹配器   
if( detector.empty() || descriptor_extractor.empty() )   
cout<<"fail to create detector!";   


//读入图像   
Mat img1 = imread("image1.jpg");   
Mat img2 = imread("image2.jpg");   


//特征点检测   
double t = getTickCount();//当前滴答数   
vector<KeyPoint> keypoints1,keypoints2;   
detector->detect( img1, keypoints1 );//检测img1中的SIFT特征点,存储到keypoints1中   
detector->detect( img2, keypoints2 );   
cout<<"图像1特征点个数:"<<keypoints1.size()<<endl;   
cout<<"图像2特征点个数:"<<keypoints2.size()<<endl;   


//根据特征点计算特征描述子矩阵,即特征向量矩阵   
Mat descriptors1,descriptors2;   
descriptor_extractor->compute( img1, keypoints1, descriptors1 );   
descriptor_extractor->compute( img2, keypoints2, descriptors2 );   
t = ((double)getTickCount() - t)/getTickFrequency();   
cout<<"SIFT算法用时:"<<t<<"秒"<<endl;   




cout<<"图像1特征描述矩阵大小:"<<descriptors1.size()   
<<",特征向量个数:"<<descriptors1.rows<<",维数:"<<descriptors1.cols<<endl;   
cout<<"图像2特征描述矩阵大小:"<<descriptors2.size()   
<<",特征向量个数:"<<descriptors2.rows<<",维数:"<<descriptors2.cols<<endl;   


opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_nonfree249d.lib
opencv_features2d249d.lib
opencv_photo249d.lib
opencv_calib3d249.lib
opencv_calib3d249d.lib
opencv_contrib249.lib
opencv_contrib249d.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_flann249d.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
opencv_gpu249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_stitching249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib


// opencv_empty_proj.cpp : 定义控制台应用程序的入口点。

// 


#include "stdafx.h" 
#include <opencv2/core/core.hpp>   
#include <opencv2/highgui/highgui.hpp>   
#include <opencv2/features2d/features2d.hpp>   
#include <opencv2/nonfree/features2d.hpp>   
#include <opencv2/nonfree/nonfree.hpp> 
#include <iostream> 


using namespace std; 
using namespace cv; 


int _tmain(int argc, _TCHAR* argv[]) 

initModule_nonfree();//初始化模块,使用SIFT或SURF时用到   
Ptr<FeatureDetector> detector = FeatureDetector::create( "SIFT" );//创建SIFT特征检测器   
Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );//创建特征向量生成器   
Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );//创建特征匹配器   
if( detector.empty() || descriptor_extractor.empty() )   
cout<<"fail to create detector!";   


//读入图像   
Mat img1 = imread("image1.jpg");   
Mat img2 = imread("image2.jpg");   


//特征点检测   
double t = getTickCount();//当前滴答数   
vector<KeyPoint> keypoints1,keypoints2;   
detector->detect( img1, keypoints1 );//检测img1中的SIFT特征点,存储到keypoints1中   
detector->detect( img2, keypoints2 );   
cout<<"图像1特征点个数:"<<keypoints1.size()<<endl;   
cout<<"图像2特征点个数:"<<keypoints2.size()<<endl;   


//根据特征点计算特征描述子矩阵,即特征向量矩阵   
Mat descriptors1,descriptors2;   
descriptor_extractor->compute( img1, keypoints1, descriptors1 );   
descriptor_extractor->compute( img2, keypoints2, descriptors2 );   
t = ((double)getTickCount() - t)/getTickFrequency();   
cout<<"SIFT算法用时:"<<t<<"秒"<<endl;   




cout<<"图像1特征描述矩阵大小:"<<descriptors1.size()   
<<",特征向量个数:"<<descriptors1.rows<<",维数:"<<descriptors1.cols<<endl;   
cout<<"图像2特征描述矩阵大小:"<<descriptors2.size()   
<<",特征向量个数:"<<descriptors2.rows<<",维数:"<<descriptors2.cols<<endl;   

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式