Ask Your Question

Revision history [back]

OpenCL Haar : Invalid classifier cascade

Hello I have a Problem with my implementation of haar face detection with the use of OpenCL. I tried the exact same Code with the use of a CPU based Approach and it worked but a bit slow in realtime, so I want to make it faster with OCL. when I call the cascade.detectMultiScale function the program crashes with the following error: OpenCV Error: Null pointer (Invalid classifier cascade) in cv::ocl::OclCascadeClassifier::oclHaarDetectObjects, file C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\ocl\src\haar.cpp, line 686

Code:

int main(int argc, const char** argv)

{ string cascadeName = "haarcascade_frontalface_alt.xml";

VideoCapture cap(0);
Mat frame, frameCopy, image;
ocl::oclMat gpu_mat;


ocl::OclCascadeClassifier cascade;
cv::CascadeClassifier cpu_cascade;

if (!cascade.load(cascadeName) || !cpu_cascade.load(cascadeName))
{
    cout << "ERROR: Could not load classifier cascade: " << cascadeName << endl;
    return EXIT_FAILURE;
}

if (!cap.isOpened())
    cout << "Capture from CAM 0 didn't work" << endl;

namedWindow("result", WINDOW_AUTOSIZE);


while (1)
{
    cap.read(frame);
    vector<Rect> faces;

    if (frame.empty())
            break;

    cvtColor(frame,frame, CV_BGR2GRAY);
    equalizeHist(frame, frame);

    gpu_mat.upload(frame);


    cascade.detectMultiScale(gpu_mat, faces, 1.1,
        3, 0
        | CV_HAAR_SCALE_IMAGE
        , Size(30, 30), Size(0, 0));

        /*cpu_cascade.detectMultiScale(frame, faces, 1.15,
            3, 0
            | CV_HAAR_SCALE_IMAGE
            , Size(30, 30), Size(0, 0));*/

    gpu_mat.download(frame);

    for (int i = 0; i < faces.size(); i++)
    {

        Rect face = faces[i];
        rectangle(frame, Point(face.x, face.y), Point(face.x + face.width, face.y + face.height),
            Scalar(255, 0, 0), 1, 4);
    }
        imshow("result", frame);

        if (cv::waitKey(1) >= 0)
            break;
    }
cap.release();
cvDestroyWindow("result");

return 0;

}

Maybe someone can help me. Thanks