int main( int argc, char** argv )
{
cl_int error = 0 ;
//Load image using OpenCV
/*
string imageName("/home/akash/Desktop/Bird.jpg"); // by default
if( argc > 1)
{
imageName = argv[1];
}
Mat image;
image = cv::imread(imageName.c_str(), IMREAD_COLOR); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
*/
IplImage *src = cvLoadImage("/home/akash/Desktop/Bird.jpg",CV_LOAD_IMAGE_COLOR );
IplImage *result_image = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
const int width = src->width;
const int height =src->height;
unsigned char *vec_h;
// long count = width*height;
// std::vector<float> size(width*height,1);
vec_h = (unsigned char )malloc((widthheight)*sizeof(unsigned char));
std::vector<cl::Platform> plat;
std::vector<cl::Device>dev;
try
{
//Find OCL platform
cl::Platform::get(&plat);
string value;
if(plat[0].getInfo(CL_PLATFORM_NAME,&value)!=CL_SUCCESS)
{
std::cout<<"No platform found"<<std::endl;
}
else
cout<<"Platform found : "<<value<<endl;
//Find device
if(plat[0].getDevices(CL_DEVICE_TYPE_GPU,&dev)!=CL_SUCCESS)
{
std::cout<<"No device found"<<std::endl;
}
// Context Properties
cl_context_properties props[3] = {CL_CONTEXT_PLATFORM,(cl_context_properties)(plat[0]()), 0};
//Create Context
cl::Context ctxt(dev,props,0,0,&error);
//Create CommandQueue
cl::CommandQueue cque(ctxt,dev[0],0,&error);
//Create Program
std::ifstream sourceFileName("Test1.cl");
std::string sourceFile(std::istreambuf_iterator<char>(sourceFileName),(std::istreambuf_iterator<char>()));
cl::Program::Sources graysrce(1,std::make_pair(sourceFile.c_str(),sourceFile.length()+1));
cl::Program prog(ctxt,graysrce);
//BuildProgram
prog.build(dev);
//Create Kernels
cl::Kernel kernel(prog,"Grayscale",&error);
//Memory Objects
cl::Buffer input, output;
input = cl::Buffer(ctxt,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,width*height,NULL,&error);
output =cl::Buffer(ctxt,CL_MEM_WRITE_ONLY,width*height,0,&error);
//Setting Kernel Arguments
if(kernel.setArg(0, input)!=CL_SUCCESS)
{
std::cout<<"Error on input arg"<<std::endl;
}
if(kernel.setArg(1, output)!=CL_SUCCESS)
{
std::cout<<"Error on output arg"<<std::endl;
}
// Event
// cl::Event e1;
int globalsize[1] = {width*height};
size_t localsize[1] = {512};
//Enqueue Task
// cque.enqueueTask(kernel,NULL,&e1);
//Write to target device
cque.enqueueWriteBuffer(input,CL_TRUE,0,(width*height)*sizeof(int),vec_h,NULL,NULL);
cque.enqueueNDRangeKernel(kernel,0,globalsize[1],localsize[1],NULL,NULL);
cque.enqueueReadBuffer(output,CL_TRUE,0,(width*height)*sizeof(int),vec_h,NULL,NULL);
//show and save the output
std::memcpy(result_image->imageData,vec_h,sizeof(unsigned char)*(width*height));
cvShowImage("GrayBird",result_image);
cvSaveImage( "/home/akash/Documents/gray_bird.jpg",result_image);
}
catch (Exception e)
{
cout<<e.what()<<"Exception error"<<e.err;
}
return 0;
}
Error: -
Building target: Grayscale
Invoking: GCC C++ Linker 4.9.3 [armeb-linux-gnueabihf]
armeb-linux-gnueabihf-g++ -L/usr/local/lib -L/opt/AMDAPPSDK-3.0-0-Beta/lib/x86_64 -o “Grayscale” ./Test1.o -lopencv_highgui -lopencv_core
/usr/local/lib/libopencv_highgui.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [Grayscale] Error 1