canny_ocl1.cpp

cpp file - Mithun Hosangadi, 2015-06-03 11:02 am

Download (1.6 kB)

 
1
#include "opencv2/core/core.hpp"
2
#include "opencv2/highgui/highgui.hpp"
3
#include "opencv2/imgproc/imgproc.hpp"
4
#include "opencv2/ocl/ocl.hpp"
5
#include "iostream"
6
#include <sys/time.h>
7
#include "time-calculation.hpp"
8
9
10
 
11
using namespace cv;
12
13
 
14
int main( )
15
{
16
    //Timer time;
17
    //time.start();
18
    ocl::DevicesInfo devInfo;
19
    int res = ocl::getOpenCLDevices(devInfo);
20
    if(res == 0)
21
    {
22
        std::cerr << "There is no OPENCL Here !" << std::endl;
23
        return -1;
24
    }
25
    else
26
    {
27
        for(unsigned int i = 0 ; i < devInfo.size() ; ++i)
28
        {
29
          std::cout << "Device : " << devInfo[i]->deviceName << " is present" << std::endl;
30
        }
31
    }
32
33
    ocl::setDevice(devInfo[0]);        // select device to use
34
    std::cout << CV_VERSION_EPOCH << "." << CV_VERSION_MAJOR << "." << CV_VERSION_MINOR << std::endl;
35
36
    Mat src1;
37
    src1 = imread("lena.jpg", CV_LOAD_IMAGE_COLOR);
38
    namedWindow( "Original image", CV_WINDOW_AUTOSIZE );
39
    imshow( "Original image", src1 );
40
 
41
    //Mat edge, draw;
42
    Mat edge;
43
    ocl::oclMat conv, src_gray;
44
    
45
    ocl::oclMat oclmat_src(src1);
46
      
47
    //ocl::cvtColor(src1, gray, COLOR_RGB2GRAY);
48
    ocl::cvtColor( oclmat_src, src_gray, COLOR_RGB2GRAY );
49
    
50
    //ocl::oclMat dst(gray);
51
    ocl::Canny(src_gray, conv, 50, 150, 3);
52
    edge = conv;
53
    //ocl::finish();
54
    //edge.convertTo(draw, CV_8U);
55
    //time.stop;
56
    //std::cout<< "Time taken by Canny:" << time.getElapsedTimeInMilliSec() << "msecs" << std::endl;
57
    namedWindow("image", CV_WINDOW_AUTOSIZE);
58
    //imshow("image", draw);
59
    imshow("image", edge);
60
 
61
    waitKey(0);                                       
62
    return 0;
63
}