Ask Your Question

Jason_Wang's profile - activity

2016-03-31 02:04:00 -0600 received badge  Enthusiast
2016-03-25 03:44:45 -0600 asked a question OpenCV ocl function with POCL and Raspberry Pi2

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.

2016-03-16 02:24:55 -0600 asked a question OpenCV Error: Null pointer...Invalid classifier cascade in function oclHaarDetectObjects

Hi everyone! I have search this problem on this site. But the answer is not correct to solve my situation...

I did actually add the *.xml file, so I test the version which didn't use the ocl library.

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;

vector<Rect> detectFaces(Mat gray){

vector<Rect> faces;
CascadeClassifier face_detector;

bool r;
r = face_detector.load("/home/swpc/haarcascade_frontalface_default.xml");
if(!r)cout<<"Can not load the xml!!"<<endl;

face_detector.detectMultiScale(gray, faces,  1.1, 3, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30), Size(0, 0));
return faces;
}

int main(){

    vector<Rect> f;
    Mat Image;

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

    resize(Image,Image,Size(640,480),0,0,1);
    Mat gray(Image);
    cvtColor(gray,gray,CV_BGR2GRAY);
   equalizeHist(gray,gray);

    f = detectFaces(gray);

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

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

    imshow("face",Image);

    waitKey(0);
    return(0);
}

It is work correctly for me.. But this version got a error !!

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/ocl/ocl.hpp>
#include <iostream>
using namespace std;
using namespace cv;

vector<Rect> detectFaces(Mat gray){

    ocl::oclMat oclGray;
    vector<Rect> faces;
    ocl::OclCascadeClassifier face_detector;
    oclGray.upload(gray);

    bool r;
    r = face_detector.load("/home/swpc/haarcascade_frontalface_default.xml");
    if(!r)cout<<"Can not load the xml!!"<<endl;

    face_detector.detectMultiScale(oclGray, faces,  1.1, 3, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30), Size(0, 0));
    return faces;
}


int main(){

    vector<Rect> f;
    Mat Image;

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

    resize(Image,Image,Size(640,480),0,0,1);
    Mat gray(Image);
    cvtColor(gray,gray,CV_BGR2GRAY);
    equalizeHist(gray,gray);

    f = detectFaces(gray);

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

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

    imshow("face",Image);

    waitKey(0);
    return(0);
}

The error is >>>

OpenCV Error: Null pointer (Invalid classifier cascade) in oclHaarDetectObjects, file /home/swpc/opencv-2.4.11/modules/ocl/src/haar.cpp, line 686 terminate called after throwing an instance of 'cv::Exception' what(): /home/swpc/opencv-2.4.11/modules/ocl/src/haar.cpp:686: error: (-27) Invalid classifier cascade in function oclHaarDetectObjects

Aborted (core dumped)

sorry for my poor English. Does anyone know this problem??