OpenCV Cuda Example source code

#include < stdio.h >  
#include < opencv2\opencv.hpp >
#include < opencv2\gpu\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")  
#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")  
#endif  

using namespace cv;  


void main()  
{  
 unsigned long AAtime=0, BBtime=0;
 
 Mat img;
 Mat outimg, outimg2;
 img = imread("Tulips.jpg",0); 
 gpu::GpuMat d_src, d_dst;
 
 d_src.upload(img);
 AAtime = getTickCount(); 
 gpu::Canny(d_src, d_dst, 35, 200, 3); 
 BBtime = getTickCount();

 printf("cuda %.5lf \n",  (BBtime - AAtime)/getTickFrequency() );
 d_dst.download(outimg);


 AAtime = getTickCount();
 Canny(img, outimg2, 35, 200, 3);
 BBtime = getTickCount();
 printf("cpu %.5lf \n",  (BBtime - AAtime)/getTickFrequency() );


 

 namedWindow("t");  
 imshow("t",outimg2); 
 namedWindow("t2");  
 imshow("t2",outimg);  
 
 cvWaitKey(0);  
 

} 


////

cuda processing takes 0.00578 sec.
and non-cuda processing takes 0.01707 sec.

In this case, cuda is faster 2times than non-cuda, but cuda will be seen higher speed.

Comments

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)