Ask Your Question

Revision history [back]

I do cannot recall the TBB version, all I know is I compile OpenCV with BUILD_TBB and WITH_TBB flag on, in console I see it download a tbb archive which I cannot recall the version. This is my C++ implementation:

Detector class

class faceDetector {
    ...
    cv::CascadeClassifier cascade;
    ...
};

Initialization

int initDetector(faceDetector* detect) {
    detect->cascade.load( CASCADE_XML_PATH );
    detect->flags = CV_HAAR_DO_CANNY_PRUNING;
    detect->maxR = 23;
    detect->minNeighbours = 3;
    detect->minSize = cvSize(10, 10);
    detect->maxSize = cvSize(100, 100);
    detect->scaleFactor = 1.1;
    cout << "initDetection finished " << endl;
    return 1;
}

Detection, called in a while loop

int adaboostDetect::detectObject(Mat img, Rect* regions) {
    int nHeads = 0;

    cv::Mat gray( img.size(), CV_8UC1, cv::Scalar::all(0) );
    cv::Mat smallImg( cv::Size( cvRound (img.cols/scaleFactor),
                            cvRound (img.rows/scaleFactor)), CV_8UC1, cv::Scalar::all(0) );

    cvtColor(img, gray, CV_BGR2GRAY);
    cv::resize(gray, smallImg, smallImg.size(), CV_INTER_LINEAR);
    equalizeHist(smallImg, smallImg);
    int nx1, nx2, ny1, ny2;
    std::vector<cv::Rect> faces;
    cascade.detectMultiScale( smallImg, faces, scaleFactor, minNeighbours, flags, minSize, maxSize );
    std::vector<cv::Rect>::const_iterator i;

    for (i=faces.begin(); i!=faces.end() ; ++i) {
        if ((i->width <= maxSize.width) && (i->height <= maxSize.height) && (i->width >= minSize.width) && (i->height >= minSize.height) ) {
            nx1 = cvRound( i->x * scaleFactor);
            ny1 = cvRound( i->y * scaleFactor);
            nx2 = cvRound( (i->x + i->width) * scaleFactor);
            ny2 = cvRound( (i->y + i->height) * scaleFactor);
            *regions = Rect(nx1, ny1, nx2-nx1, ny2-ny1);
            regions++;
            nHeads++;
        }
    }
    return nHeads;
}