12/13/2013

SURF_GPU example source code (feature finder using GPU )

This is example source code about SURF_GPU.
The time of processing is taken 0.99 sec on the 1787x1510 image size.
My environment is
Intel(r) core(TM) i5-3570 cpu@3.4ghz 3.80 Ghz
NVIDA Geforce GTX 650






Example source code



//////
#include < stdio.h >  
#include < opencv2\opencv.hpp >  
#include < opencv2\nonfree\gpu.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()  
{
 //processign tiem measurement
 unsigned long AAtime=0, BBtime=0;

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

 gpu::GpuMat inImg_g;
 gpu::GpuMat src_keypoints_gpu, src_descriptors_gpu;

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

 //FeatureFinder 
 gpu::SURF_GPU FeatureFinder_gpu(400);

 //processing time measure
 AAtime = getTickCount();
 inImg_g.upload(inImg);

 //Feature Extraction
 FeatureFinder_gpu(inImg_g, gpu::GpuMat(), src_keypoints_gpu, src_descriptors_gpu, false);

 //Processing time measurement
 BBtime = getTickCount(); 
 
 //descriptor down
 FeatureFinder_gpu.downloadKeypoints(src_keypoints_gpu, src_keypoints); 
 FeatureFinder_gpu.downloadDescriptors(src_descriptors_gpu, src_descriptors);
 
 //Features Draw
 //νŠΉμ§•μ  뿌리기 1
 drawKeypoints(inImg, src_keypoints, inImg, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
 
 imshow("Show", inImg); 

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

 waitKey(0);

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

///

No comments:

Post a Comment