12/16/2016

Gpu Mat, Cpu Mat example 2

unsigned long AAtime = 0, BBtime = 0;


 cuda::GpuMat gpuImg, gpuImg_out;


 Mat img, img_out, img_out2;
 img = imread("2mb.jpg");


 gpuImg.upload(img);
 AAtime = getTickCount();
 cuda::bitwise_not(gpuImg, gpuImg_out);

 Ptr< cv::cuda::filter > filter = cuda::createSobelFilter(img.type(), img.type(), 1, 0);
 filter->apply(gpuImg_out, gpuImg_out);
 BBtime = getTickCount();
 gpuImg_out.download(img_out);

 printf("gpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency());


 AAtime = getTickCount();
 bitwise_not(img, img_out2);
 Sobel(img_out2, img_out2, img_out2.depth(), 1, 0);
 BBtime = getTickCount();
 printf("cpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency());




 imshow("cpu_img", img_out);
 imshow("cpu_img", img_out2);
 waitKey(0);

No comments:

Post a Comment