Ask Your Question

bonchenko's profile - activity

2019-12-18 06:13:37 -0600 received badge  Popular Question (source)
2014-12-03 18:59:29 -0600 received badge  Student (source)
2013-08-12 15:22:09 -0600 received badge  Teacher (source)
2013-07-30 05:50:02 -0600 answered a question OpenCV CascadeClassifier Segmentation Fault

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;
}
2013-07-30 01:55:28 -0600 commented question OpenCV CascadeClassifier Segmentation Fault

Thanks Steve. I tried your suggestion, changing the all of the code to C++, and still the same problem happened. I get segmentation fault in cascade.detectMultiScale. The gdb and the backtrace is same. Interestingly, I recompile OpenCV without tbb, and the problem vanished... Unfortunately, this cause my application to run 2-3 x slower

2013-07-29 01:16:48 -0600 commented question OpenCV CascadeClassifier Segmentation Fault

Today I tried recompile OpenCV without TBB library, and application runs smoothly. I am thinking this is related to parallelization by TBB. I still looking forward to the solution because without TBB, the application runs 2-3x slower :(

2013-07-27 08:27:16 -0600 asked a question OpenCV CascadeClassifier Segmentation Fault

This is same question I asked in StackOverflow

I am using OpenCV to detect faces in video. Currently I am using CascadeClassifier class, Haar classifier. When I run cascade.detectmultiscale, my program will run normally and suddenly crash with segmentation fault. I debug using gdb and found out thatProgram received signal SIGSEGV, Segmentation fault.

[Switching to Thread 0xb1841460 (LWP 995)]
0x00099280 in cvRunHaarClassifierCascadeSum(CvHaarClassifierCascade const*, CvPoint, double&, int) () there is problem in cvRunHaarClassifierCascadeSum

Running backtrace, seems like gdb cannot finish the process

#0  0x00099470 in cvRunHaarClassifierCascadeSum(CvHaarClassifierCascade const*, CvPoint, double&, int) ()
#1  0x0009a8be in cvRunHaarClassifierCascade ()
#2  0x0009b28e in cv::HaarDetectObjects_ScaleCascade_Invoker::operator()(cv::Range const&) const ()
#3  0x00175928 in tbb::interface6::internal::start_for<tbb::blocked_range<int>, (anonymous namespace)::ProxyLoopBody, tbb::auto_partitioner con)
()
#4  0x00502f5e in tbb::internal::custom_scheduler<tbb::internal::IntelSchedulerTraits>::local_wait_for_all(tbb::task&, tbb::task*) ()
#5  0x005037d0 in tbb::internal::arena::process(tbb::internal::generic_scheduler&) ()
#6  0x00506c60 in tbb::internal::market::process(rml::job&) ()
#7  0x005078fe in tbb::internal::rml::private_worker::run() ()
#8  0x00507c3a in tbb::internal::rml::private_worker::thread_routine(void*) ()
#9  0xb6fb1cb0 in start_thread () from /usr/lib/libpthread.so.0
#10 0xb6dd6828 in ?? () from /usr/lib/libc.so.6
#11 0xb6dd6828 in ?? () from /usr/lib/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

I tried using the C version of cascade classifier ( the CvHaarClassifierCascade class ), same problem also happens when I run it and debug it. This is the code in case you want to see my 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 faceDetector::detectFaces(IplImage* img, CvRect** regions) {
    int nFaces = 0; // number of detection considered as face
    IplImage* gray = cvCreateImage( cvSize(img->width, img->height), 8, 1 );
    IplImage* smallImg = cvCreateImage( cvSize( cvRound (img->width/scaleFactor),
                                            cvRound (img->height/scaleFactor)), 8, 1 );
    cvCvtColor(img, gray, CV_BGR2GRAY);
    cvResize(gray, smallImg, CV_INTER_LINEAR);
    cvEqualizeHist(smallImg, smallImg);
    cvClearMemStorage(storage);
    int nx1, nx2, ny1, ny2; // coordinate of detection rectangles

    std::vector<cv::Rect> faces; // list of detection
    cv::Mat msmallimg(smallImg);
    cascade.detectMultiScale( msmallimg, faces, scaleFactor, minNeighbours, flags, minSize, maxSize );

    CvRect* nRects;
    nRects = (CvRect*) malloc(faces.size() * sizeof(CvRect));

    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);           
            nRects[nFaces] = cvRect(nx1, ny1, nx2-nx1, ny2-ny1);
            nFaces++;
        }
    }

    *regions = nRects;
    cvReleaseImage(&gray);
    cvReleaseImage(&smallImg);
    return nFaces;
}

The error always happened after I call

cascade.detectMultiScale( msmallimg, faces, scaleFactor, minNeighbours, flags, minSize, maxSize );

Is this known bugs in OpenCV cascade classifier or I have a bad code? I am confused how to debug further on this problem because it ... (more)

2013-04-24 23:15:44 -0600 received badge  Editor (source)
2013-04-21 21:59:35 -0600 commented question Are there any new algorithm about pedestrian detection,people counting?

sorry for double posting, but if you want alternatives to HOG, Latent SVM is based on HOG, and seems to be better at detecting objects. But I cannot find how to create training data for Latent SVM. Anyone know?

2013-04-21 21:58:18 -0600 commented question Are there any new algorithm about pedestrian detection,people counting?

Hello flammxy, I do the same approach as you do in people counting. My first attempt, using MIT car and people dataset, result in lot of false positives (both test on separate people and car test images). Then I retrain the model using false positives from negative test set. This result in zero detection - please see my post here. After trying on different dataset and modifying parameters (hit threshold, scale, group thereshold), my conclusion is although HOG is so far the most popular people/object descriptor, the result is not perfect (100% hit rate, no false positives). We have to deal with miss and false positives (in my case, 50% hit rate, 50% false positives.

2013-04-17 22:45:56 -0600 received badge  Supporter (source)
2013-04-17 22:45:26 -0600 answered a question How to training HOG and use my HOGDescriptor?

You need to get the HOG features from all of your positive and negative sample images using HOGDescriptor:compute functions, then feed the result to SVM library such as SVMlight. This page will help you to compute the feature and get the resulting model from SVM Light. The model will be available in genfiles/descriptorVector