12/13/2013

SurfFeatureDetector exmaple source code (OpenCV)

This is 'SurfFeatureDetector' example source code.
On this page(http://feelmare.blogspot.kr/2013/12/surfgpu-example-source-code-feature.html), I introduced SURF_GPU.
In my case, The processing time difference is small.
GPU-> 0.99 sec, CPU-> 1.04 sec.


 



 

////
#include < stdio.h >  
#include < opencv2\opencv.hpp >
#include < opencv2\features2d\features2d.hpp >
#include < opencv2\nonfree\features2d.hpp >

#ifdef _DEBUG  
#pragma comment(lib, "opencv_core246d.lib")   
//#pragma comment(lib, "opencv_imgproc246d.lib")   //MAT processing  
//#pragma comment(lib, "opencv_objdetect246d.lib")   
//#pragma comment(lib, "opencv_gpu246d.lib")  
#pragma comment(lib, "opencv_features2d246d.lib")  
#pragma comment(lib, "opencv_highgui246d.lib")  
//#pragma comment(lib, "opencv_ml246d.lib")
//#pragma comment(lib, "opencv_stitching246d.lib");
#pragma comment(lib, "opencv_nonfree246d.lib");

#else  
#pragma comment(lib, "opencv_core246.lib")  
//#pragma comment(lib, "opencv_imgproc246.lib")  
//#pragma comment(lib, "opencv_objdetect246.lib")  
//#pragma comment(lib, "opencv_gpu246.lib")  
#pragma comment(lib, "opencv_features2d246.lib")  
#pragma comment(lib, "opencv_highgui246.lib")  
//#pragma comment(lib, "opencv_ml246.lib")  
//#pragma comment(lib, "opencv_stitching246.lib");
#pragma comment(lib, "opencv_nonfree246.lib");
#endif  

using namespace cv;  
using namespace std;


void main()  
{
/////CPU mode


//processign tiem measurement
unsigned long AAtime=0, BBtime=0;

//SURF_GPU example source code
Mat inImg,outImg;
vector src_keypoints;
vector src_descriptors;


//image load
inImg = imread("ship.png",0);

//FeatureFinder 
SurfFeatureDetector FeatureFinder(400);

//processing time measure
AAtime = getTickCount();

//Feature Extraction
FeatureFinder.detect( inImg, src_keypoints );

//Processing time measurement
BBtime = getTickCount(); 

//Features Draw
drawKeypoints( inImg, src_keypoints, outImg, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

imshow("Show", outImg); 
printf("Processing time = %.2lf(sec) \n",  (BBtime - AAtime)/getTickFrequency() );
printf("Features %d\n", src_keypoints.size() );

waitKey(0);

//save to file
imwrite("output.jpg", outImg);

}
////





No comments:

Post a Comment