12/16/2016

Gpu Mat, Cpu Mat example code 1

cuda::GpuMat gpuImg;
 Mat img = imread("ss.jpg");

 unsigned long AAtime = 0, BBtime = 0;
 AAtime = getTickCount();
 gpuImg.upload(img); //upload
 vector< cuda::GpuMat > rgbGpuMat(3);
 cuda::split(gpuImg, rgbGpuMat); //cuda processing

 Mat r, g, b;
 rgbGpuMat[0].download(b); //download
 rgbGpuMat[1].download(g);
 rgbGpuMat[2].download(r);
 BBtime = getTickCount();
 printf("gpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency());


 vector< mat > rgbMat(3);
 split(img, rgbMat); //cuda processing
 //Mat r, g, b;
 b = rgbMat[0]; //download
 g = rgbMat[1];
 r = rgbMat[2];
 BBtime = getTickCount();
 printf("cpu : %.2lf second \n", (BBtime - AAtime) / getTickFrequency());



 namedWindow("r", 0); //make window
 imshow("r", r); //show
 namedWindow("g", 0); //make window
 imshow("g", g); //show
 namedWindow("b", 0); //make window
 imshow("b", b); //show
 waitKey(0);

No comments:

Post a Comment