Showing posts with label GpuMat. Show all posts
Showing posts with label GpuMat. Show all posts

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);

Gpu Mat, Cpu Mat example code 1


...
#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"

#include <iostream>


#ifdef _DEBUG               
#pragma comment(lib, "opencv_core331d.lib")       
#pragma comment(lib, "opencv_highgui331d.lib")    
#pragma comment(lib, "opencv_imgcodecs331d.lib")  
#pragma comment(lib, "opencv_objdetect331d.lib")  
#pragma comment(lib, "opencv_imgproc331d.lib")  
#pragma comment(lib, "opencv_videoio331d.lib")    

#pragma comment(lib, "opencv_cudaarithm331d.lib")  
#else       
#pragma comment(lib, "opencv_core331.lib")       
#pragma comment(lib, "opencv_highgui331.lib")    
#pragma comment(lib, "opencv_imgcodecs331.lib")    
#pragma comment(lib, "opencv_objdetect331.lib")  
#pragma comment(lib, "opencv_imgproc331.lib")  
#pragma comment(lib, "opencv_videoio331.lib")    

#pragma comment(lib, "opencv_cudaarithm331d.lib")  
#endif        


using namespace std;
using namespace cv;

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

    
    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);


    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);
    

    return 0;
}
...