Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

LBP based getMultiScale object detection.

I trained my system using opencv's traincascade using LBP features for faster training. The result of training is shown below. I used 14 stages.

    cascadeDirName: data_cascade/
    vecFileName: opencv_createsamples/positive_samples.vec
    bgFileName: Doors/negatives.txt
    numPos: 4350
    numNeg: 2400
    numStages: 14
    precalcValBufSize[Mb] : 4000
    precalcIdxBufSize[Mb] : 5000
    stageType: BOOST
    featureType: LBP
    sampleWidth: 30
    sampleHeight: 50
    boostType: GAB
    minHitRate: 0.999
    maxFalseAlarmRate: 0.5
    weightTrimRate: 0.95
    maxDepth: 1
    maxWeakCount: 100

    ===== TRAINING 13-stage =====
    <BEGIN
    POS count : consumed   4350 : 4370
    NEG count : acceptanceRatio    2400 : 0.000223963
    Precalculation time: 72
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3|  0.99977| 0.559583|
   +----+---------+---------+
    |   4|  0.99931| 0.240417|
   +----+---------+---------+
   END>
   Training until now has taken 0 days 1 hours 57 minutes 53 seconds.

I have just showed the output of the final stage to show the acceptance ratio. Now, in order to detect using this classifier, I modified an existing opencv example using detectMultiScale(). The code is shown below

    #include "opencv2/objdetect/objdetect.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"

    #include <cctype>
    #include <iostream>
    #include <iterator>
    #include <stdio.h>

    using namespace cv;
    using namespace std;

   void detectAndDraw(Mat &img, CascadeClassifier& cascade,double scale)
   {
             vector<Rect> double_doors;
             Mat gray;
             Mat smallImg( cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );

            Scalar color = Scalar(0,0,255);

            cvtColor( img, gray, CV_BGR2GRAY );
            resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
            equalizeHist( smallImg, smallImg );
            cout<<"equalization done"<<endl;
            cascade.detectMultiScale( smallImg, double_doors,scale,1,0,Size(10,10),Size(100,140));

            cout<<"multiscale detect complete"<<endl;
            for(int i=0;i<double_doors.size();i++)
            {
                      rectangle(img,double_doors[i],color,1,8,0);
            }

           cout<<"rectangles drawn"<<endl;
           imwrite("/home/tonystark/Project_awesome/Dataset/Training_set/Results/Double_Doors/Door_Detect1.jpg",img);

           imshow("Output Image",img);

    }

    int main(int argc, char **argv)
    {
            CascadeClassifier cascade, nestedCascade;
            cascade.load(argv[1]);
            double scale = atof(argv[2]);
            Mat img = imread(argv[3],1);

            cout<<"inputs read"<<endl;

            namedWindow("Input Image",WINDOW_NORMAL);
            namedWindow("Output Image",WINDOW_NORMAL);
            detectAndDraw(img,cascade,scale);

            cout<<"detection complete"<<endl;
            imwrite("/home/tonystark/Project_awesome/Dataset/Training_set/Results/Double_Doors/Door_Detect1.jpg",img);
            imshow("Input Image",img);
            waitKey(0);
            return 0;
    }

The input image for detection is 3000X2250 and I started the detection. Its been about 1:30 hours since and I am not sure what is exactly happening. From reading the documentation here, it tells me more or less like it supports only Haar. But from this here, I get that it can be used for both. I can see a parameter from the code, for Haar, in that link, for the function,

    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

In my code, this is how I call the function

    cascade.detectMultiScale( smallImg, double_doors,scale,1,0,Size(10,10),Size(100,140));

Am I missing something here? Could you please point me in the right direction?