OpenCV ocl function with POCL and Raspberry Pi2

asked 2016-03-25 03:44:45 -0600

Jason_Wang gravatar image

Hi everyone.

I try to install OpenCL on the Raspberry Pi2. The operating system is Ubuntu Mate. Because Pi2's CPU is ARMv7a.

So that I find the POCL-0.12 as the solution for being the OpenCL platform. After build and install POCL, it works fine!!(The test of example all pass) And I can find the platform and device as the figure shows. image description

Then I try to install OpenCV 2.4.11 on the Ubuntu Mate. It also works fine!! (The test of example all pass)

Now I try to use the ocl::xxx() function in OpenCV. When compile and run time, it doesn't show any error or wrong. And I can use ocl::oclMat to create the image. But when I use the function like ocl::cvtColor() or ocl::equlizeHist(). It just like pass the code and didn't do anythings ?? here is my code..

void OpenCL_info() {

ocl::PlatformsInfo platform;                                                             
ocl::getOpenCLPlatforms(platform);
//const ocl::PlatformInfo *pInfo = platform.at(0);
bool deviceFound = false;
ocl::DevicesInfo device;
ocl::DeviceType type = ocl::CVCL_DEVICE_TYPE_CPU;
deviceFound = ocl::getOpenCLDevices(device,type);
ocl::setDevice(device.at(0));

cout<<endl;
cout<<"======== Platforms ========"<<endl;
for(int i=0;i<(int)platform.size();i++)
{
    cout<<"Platforms  "<<i+1<<" :"<<platform.at(i)->platformName<<endl;
}
cout<<endl;
/*
   for(int i=0;i<(int)device.size();i++)
   {
   cout<<"Device  "<<i+1<<" :"<<device.at(i)->deviceName<<endl;
   }
 */


if(deviceFound)
{
    cout<<"Found device!"<<endl;
    cout<<"Now set the device to "<<device.at(0)->deviceName<<endl;
}
else
{
    cout<<"Not found!"<<endl;
}

}

int main(){

vector<Rect> f;
Mat Image;

Image = imread("wang.png");
if (Image.cols == 0) {
    cout << "Error reading file " << endl;
    return -1;
}

resize(Image,Image,Size(640,480),0,0,1);
ocl::oclMat gray(Image);
struct timespec t1,t2;
cout<<endl;
cout<<"====Start gray===="<<endl;
clock_gettime(CLOCK_REALTIME, &t1);
ocl::cvtColor(gray,gray,CV_BGR2GRAY);
clock_gettime(CLOCK_REALTIME, &t2);
cout<<"====End gary===="<<endl;
diff(t1,t2);

//ocl::equalizeHist(gray,gray);

OpenCL_info();

gray.download(Image);

/*
for(unsigned int i=0;i<f.size();i++){
    Rect f_rect = f[i];
    rectangle(Image,f_rect,CV_RGB(255,0,0),1,8,0);
}
*/
cout<<"OK"<<endl;

namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.

imshow("face",Image);

waitKey(0);
return(0);

}

And the result shows--> image description

No error. the screen shows nothing. But I can detect the platform and device by ocl::getOpenCLPlatforms, ocl::getOpenCLDevices. And I use the original OpenCV function cvtColor(), it works and shows the gray image.

Dose anyone have the experience on OpenCV, OepnCL with raspberry Pi2?

Sorry for my poor English. THX.

edit retag flag offensive close merge delete