Create Your Own Haar Classifier for Detecting objects in OpenCV


The steps for training a haar classifier and detecting an object can be divided into :

  • Creating the description file of positive samples
  • Creating the description file of negative samples
  • Packing the positive samples into a vec file
  • Training the classifier
  • Converting the trained cascade into a xml file
  • Using the xml file to detect the object

Let us see all these steps in detail. First of all,we need a large number of images of our object. One would end crazy if they resort to shooting   all the positive and negative images, which can run into  thousands. Here ffmpeg comes to rescue. We can shoot a small video (if possible 360 degree) of our object and then use ffmpeg to extract all the frames.  It is very helpful because a 25fps video of 1 minute will yield 1500 pictures….!!!  Thats cool…. isn’t it???.. To do that using ffmpeg, use the following synopsis of ffmpeg:

ffmpeg -i Video.mpg Pictures%d.bmp

For details about that visit this. It is better to use all the images in Bitmap format for improved performance, even though it takes a little more space since it is uncompressed image format.

Once the positive and negative images are prepared,it is better to put them in two different folders named something like positive and negative. The next step is the creation of description files for both positive and negative images.The description file is just a text file, with each line corresponding to each image.The fields in a line of the positive description file are: the image name, followed by the number of objects to be detected in the image, which is followed by the x,y coordinates of the location of the object in the image.Some images may contain more than one objects.

The description file of positive images can be created using the object marker program

The code of objectmarker is given below:

/***************objectmarker.cpp******************

Objectmarker for marking the objects to be detected  from positive samples and then creating the 
description file for positive images.

compile this code and run with two arguments, first one the name of the descriptor file and the second one 
the address of the directory in which the positive images are located

while running this code, each image in the given directory will open up. Now mark the edges of the object using the mouse buttons
  then press then press "SPACE" to save the selected region, or any other key to discard it. Then use "B" to move to next image. the program automatically
  quits at the end. press ESC at anytime to quit.

  *the key B was chosen  to move to the next image because it is closer to SPACE key and nothing else.....

author: achu_wilson@rediffmail.com
*/

#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>

// for filelisting
#include <stdio.h>
#include <sys/io.h>
// for fileoutput
#include <string>
#include <fstream>
#include <sstream>
#include <dirent.h>
#include <sys/types.h>

using namespace std;

IplImage* image=0;
IplImage* image2=0;
//int start_roi=0;
int roi_x0=0;
int roi_y0=0;
int roi_x1=0;
int roi_y1=0;
int numOfRec=0;
int startDraw = 0;
char* window_name="<SPACE>add <B>save and load next <ESC>exit";

string IntToString(int num)
{
    ostringstream myStream; //creates an ostringstream object
    myStream << num << flush;
    /*
    * outputs the number into the string stream and then flushes
    * the buffer (makes sure the output is put into the stream)
    */
    return(myStream.str()); //returns the string form of the stringstream object
};

void on_mouse(int event,int x,int y,int flag, void *param)
{
    if(event==CV_EVENT_LBUTTONDOWN)
    {
        if(!startDraw)
        {
            roi_x0=x;
            roi_y0=y;
            startDraw = 1;
        } else {
            roi_x1=x;
            roi_y1=y;
            startDraw = 0;
        }
    }
    if(event==CV_EVENT_MOUSEMOVE && startDraw)
    {

        //redraw ROI selection
        image2=cvCloneImage(image);
        cvRectangle(image2,cvPoint(roi_x0,roi_y0),cvPoint(x,y),CV_RGB(255,0,255),1);
        cvShowImage(window_name,image2);
        cvReleaseImage(&image2);
    }

}

int main(int argc, char** argv)
{
    char iKey=0;
    string strPrefix;
    string strPostfix;
    string input_directory;
    string output_file;

    if(argc != 3) {
        fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);
        return -1;
    } 

    input_directory = argv[2];
    output_file = argv[1];

    /* Get a file listing of all files with in the input directory */
    DIR    *dir_p = opendir (input_directory.c_str());
    struct dirent *dir_entry_p;

    if(dir_p == NULL) {
        fprintf(stderr, "Failed to open directory %s\n", input_directory.c_str());
        return -1;
    }

    fprintf(stderr, "Object Marker: Input Directory: %s  Output File: %s\n", input_directory.c_str(), output_file.c_str());

    //    init highgui
    cvAddSearchPath(input_directory);
    cvNamedWindow(window_name,1);
    cvSetMouseCallback(window_name,on_mouse, NULL);

    fprintf(stderr, "Opening directory...");
    //    init output of rectangles to the info file
    ofstream output(output_file.c_str());
    fprintf(stderr, "done.\n");

    while((dir_entry_p = readdir(dir_p)) != NULL)
    {
        numOfRec=0;

        if(strcmp(dir_entry_p->d_name, ""))
        fprintf(stderr, "Examining file %s\n", dir_entry_p->d_name);

        /* TODO: Assign postfix/prefix info */
        strPostfix="";
        //strPrefix=input_directory;
        strPrefix=dir_entry_p->d_name;
        //strPrefix+=bmp_file.name;
        fprintf(stderr, "Loading image %s\n", strPrefix.c_str());

        if((image=cvLoadImage(strPrefix.c_str(),1)) != 0)
        {

            //    work on current image
            do

    {
                cvShowImage(window_name,image);

                // used cvWaitKey returns:
                //    <B>=66        save added rectangles and show next image
                //    <ESC>=27        exit program
                //    <Space>=32        add rectangle to current image
                //  any other key clears rectangle drawing only
                iKey=cvWaitKey(0);
                switch(iKey)
                {

                case 27:

                        cvReleaseImage(&image);
                        cvDestroyWindow(window_name);
                        return 0;
                case 32:

                        numOfRec++;
                printf("   %d. rect x=%d\ty=%d\tx2h=%d\ty2=%d\n",numOfRec,roi_x0,roi_y0,roi_x1,roi_y1);
                //printf("   %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x1,roi_y1,roi_x0-roi_x1,roi_y0-roi_y1);
                        // currently two draw directions possible:
                        //        from top left to bottom right or vice versa
                        if(roi_x0<roi_x1 && roi_y0<roi_y1)
                        {

                            printf("   %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x0,roi_y0,roi_x1-roi_x0,roi_y1-roi_y0);
                            // append rectangle coord to previous line content
                            strPostfix+=" "+IntToString(roi_x0)+" "+IntToString(roi_y0)+" "+IntToString(roi_x1-roi_x0)+" "+IntToString(roi_y1-roi_y0);

                        }
                        else
                                                    //(roi_x0>roi_x1 && roi_y0>roi_y1)
                        {
                            printf(" hello line no 154\n");
                            printf("   %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x1,roi_y1,roi_x0-roi_x1,roi_y0-roi_y1);
                            // append rectangle coord to previous line content
                            strPostfix+=" "+IntToString(roi_x1)+" "+IntToString(roi_y1)+" "+IntToString(roi_x0-roi_x1)+" "+IntToString      (roi_y0-roi_y1);
        }

                        break;
                }
            }
            while(iKey!=66);

            {
            // save to info file as later used for HaarTraining:
            //    <rel_path>\bmp_file.name numOfRec x0 y0 width0 height0 x1 y1 width1 height1...
            if(numOfRec>0 && iKey==66)
            {
                //append line
                /* TODO: Store output information. */
                output << strPrefix << " "<< numOfRec << strPostfix <<"\n";

            cvReleaseImage(&image);
            }

         else 
        {
            fprintf(stderr, "Failed to load image, %s\n", strPrefix.c_str());
        }
    }

    }}

    output.close();
    cvDestroyWindow(window_name);
    closedir(dir_p);

    return 0;
}

Now its time to create the description file of negative samples.The description file of negative samples contain only the filenames of the negative images. It can be easily created by listing the contents of the negative samples folder and redirecting the output to a text file, ie, using the command:

ls > negative.txt

Now we can move on to creating the samples for training. All the positive images in the description file are packed into a .vec file. It is created using the createsamples utility provided with opencv  package. Its synopsis is:

opencv-createsamples -info positive.txt -vec vecfile.vec -w 30 -h 32 

my positive image descriptor file was named positive.txt and the name chosen for the vec file was vecfile.vec. Since a bottle was taken as a sample, minimum width of the object was selected as 30 and height as 32. the above command yielded a vec file. The contents of a vec file can be seen using   the following command:

  opencv-createsamples -vec vecfile.vec -show 

it opens the images in the vec file and use SPACEBAR to see the next image

Now everything is ready to start the training of the classifier. For that, we can use the opencv-haartraining utility. Its synopsis is:

opencv-haartraining -data haar -vec vecfile.vec  -bg negative.txt -nstages 30 -mem 2000 -mode all -w 30 -h 32

It creates a directory named haar and puts the training data into it. The arguments given defines the name of vecfile, background descriptor file,number of stages which is given here as 30, memory allocated which is 2 Gb, mode, width, height etc. There are many more options for the haartraining.This step is the most time consuming one. It took me days to get a usable classifier. Actually, I aborted training at 25 th stage because the classifier was found satisfactory at that stage.

Once the training is over, we are left with a folder full of training data (named haar in my case). The next step is to convert the data in that directory to an xml file. it is done using the convert_cascade program given in the opencv samples directory.

convert_cascade --size="30x32"   data  bottle.xml

Here data is the directory containing the trained data and bottle.xml is the xml file created. Now its time to use our xml file. The following code grabs frames from webcam and uses the classifer to detect the object.

/******************detect.c*************************/
/*
opencv implementation of object detection using haar classifier.

author: achu_wilson@rediffmail.com
*/


#include <stdio.h>
#include "cv.h"
#include "highgui.h"

CvHaarClassifierCascade *cascade;
CvMemStorage            *storage;

void detect( IplImage *img );

int main( int argc, char** argv )
{
    CvCapture *capture;
    IplImage  *frame;
    int       key;
    char      *filename = "bottle.xml"; //put the name of your classifier here

    cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
    storage = cvCreateMemStorage(0);
    capture = cvCaptureFromCAM(0);

    assert( cascade && storage && capture );

    cvNamedWindow("video", 1);

    while(1) {
        frame = cvQueryFrame( capture );

        detect(frame);

        key = cvWaitKey(50);
        }

    cvReleaseImage(&frame);
    cvReleaseCapture(&capture);
    cvDestroyWindow("video");
    cvReleaseHaarClassifierCascade(&cascade);
    cvReleaseMemStorage(&storage);

    return 0;
}

void detect(IplImage *img)
{
    int i;

    CvSeq *object = cvHaarDetectObjects(
            img,
            cascade,
            storage,
            1.5, //-------------------SCALE FACTOR
            2,//------------------MIN NEIGHBOURS
            1,//----------------------
                      // CV_HAAR_DO_CANNY_PRUNING,
            cvSize( 30,30), // ------MINSIZE
            cvSize(640,480) );//---------MAXSIZE

    for( i = 0 ; i < ( object ? object->total : 0 ) ; i++ ) 
        {
            CvRect *r = ( CvRect* )cvGetSeqElem( object, i );
            cvRectangle( img,
                     cvPoint( r->x, r->y ),
                     cvPoint( r->x + r->width, r->y + r->height ),
                     CV_RGB( 255, 0, 0 ), 2, 8, 0 );
                    
            //printf("%d,%d\nnumber =%d\n",r->x,r->y,object->total);


        }

    cvShowImage( "video", img );
}





127 thoughts on “Create Your Own Haar Classifier for Detecting objects in OpenCV

  1. when i give command ‘opencv_createsamples -info positives.txt -vec myfile.vec -num 3 -w 24 -h 24’ it shows,

    Info file name: positives.txt
    Img file name: (NULL)
    Vec file name: myfile.vec
    BG file name: (NULL)
    Num: 3
    BG color: 0
    BG threshold: 80
    Invert: FALSE
    Max intensity deviation: 40
    Max x angle: 1.1
    Max y angle: 1.1
    Max z angle: 0.5
    Show samples: FALSE
    Width: 24
    Height: 24
    Create training samples from images collection…
    Unable to open file: positives.txt
    Done. Created 0 samples

    it doesn’t create any samples..why?could anyone help me?thanks in advance…..

      1. At last i create an intermediate xml file for face detection. But using this xmll file i can’t detect any face.why?please give me a solution…

      2. I use only 3 images as +ve samples and 5 images as -ve samples.S when I execute this commmand ‘opencv_haartraining -data facede -vec vecfile.vec -bg negatives.txt -npos 3 -nneg 5 -nstages 30 -mem 2000 -mode ALL -w 24 -h 24’ I got like this.
        Data dir name: facede
        Vec file name: vecfile.vec
        BG file name: negatives.txt, is a vecfile: no
        Num pos: 3
        Num neg: 5
        Num stages: 30
        Num splits: 1 (stump as weak classifier)
        Mem: 2000 MB
        Symmetric: TRUE
        Min hit rate: 0.995000
        Max false alarm rate: 0.500000
        Weight trimming: 0.950000
        Equal weights: FALSE
        Mode: ALL
        Width: 24
        Height: 24
        Applied boosting algorithm: GAB
        Error (valid only for Discrete and Real AdaBoost): misclass
        Max number of splits in tree cascade: 0
        Min number of positive samples per cluster: 500
        Required leaf false alarm rate: 9.31323e-10

        Tree Classifier
        Stage
        +—+
        | 0|
        +—+

        Number of features used : 138694

        Parent node: NULL

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 1
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: NULL
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+
        | 0|
        +—+

        0

        Parent node: 0

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.2
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 0
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+
        | 0| 1|
        +—+—+

        0—1

        Parent node: 1

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.277778
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 1
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+
        | 0| 1| 2|
        +—+—+—+

        0—1—2

        Parent node: 2

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.0657895
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 2
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+—+
        | 0| 1| 2| 3|
        +—+—+—+—+

        0—1—2—3

        Parent node: 3

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.0423729
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 3
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+—+—+
        | 0| 1| 2| 3| 4|
        +—+—+—+—+—+

        0—1—2—3—4

        Parent node: 4

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.0210084
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 4
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+—+—+—+
        | 0| 1| 2| 3| 4| 5|
        +—+—+—+—+—+—+

        0—1—2—3—4—5

        Parent node: 5

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.0241546
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 5
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+—+—+—+—+
        | 0| 1| 2| 3| 4| 5| 6|
        +—+—+—+—+—+—+—+

        0—1—2—3—4—5—6

        Parent node: 6

        *** 1 cluster ***
        POS: 3 3 1.000000
        NEG: 5 0.00190476
        BACKGROUND PROCESSING TIME: 0.00
        Precalculation time: 0.00
        +—-+—-+-+———+———+———+———+
        | N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
        +—-+—-+-+———+———+———+———+
        | 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
        +—-+—-+-+———+———+———+———+
        Stage training time: 0.00
        Number of used features: 1

        Parent node: 6
        Chosen number of splits: 0

        Total number of splits: 0

        Tree Classifier
        Stage
        +—+—+—+—+—+—+—+—+
        | 0| 1| 2| 3| 4| 5| 6| 7|
        +—+—+—+—+—+—+—+—+

        0—1—2—3—4—5—6—7

        Parent node: 7

        *** 1 cluster ***
        POS: 3 3 1.000000

        Here total stages I got is 7. But we give total number of iteration 30.why I only get 7 and also that XML file doesn’t detect the face.Any one help me.

      3. k.But now I am giving around 2500 images are positive and 580 images are negative.Now the problem with creating the samples.I got following errors.
        Info file name: positive.txt
        Img file name: (NULL)
        Vec file name: vefile.vec
        BG file name: (NULL)
        Num: 2676
        BG color: 0
        BG threshold: 80
        Invert: FALSE
        Max intensity deviation: 40
        Max x angle: 1.1
        Max y angle: 1.1
        Max z angle: 0.5
        Show samples: FALSE
        Width: 24
        Height: 24
        Create training samples from images collection…
        OpenCV Error: Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x width && rect.y height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in cvSetImageROI, file /home/arya/stuff/opencv/opencv-2.4.7/modules/core/src/array.cpp, line 3006
        terminate called after throwing an instance of ‘cv::Exception’
        what(): /home/arya/stuff/opencv/opencv-2.4.7/modules/core/src/array.cpp:3006: error: (-215) rect.width >= 0 && rect.height >= 0 && rect.x width && rect.y height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0) in function cvSetImageROI

        Aborted (core dumped)

        ————————————
        The following are the contents of my positive.txt file.But here I mentioned ony few

        /home/arya/myown/Positive/images18413.jpeg 1 0 0 113 33
        /home/arya/myown/Positive/images1392.jpeg 1 113 33 107 133
        /home/arya/myown/Positive/face841.jpeg 1 185 93 35 73
        /home/arya/myown/Positive/images866.jpeg 2 121 26 64 68 121 26 88 123
        /home/arya/myown/Positive/images83.jpeg 1 102 13 107 136
        /home/arya/myown/Positive/images2741.jpeg 3 102 13 87 126 8 44 181 95 8 44 214 -10
        /home/arya/myown/Positive/images1479.jpeg 1 128 166 94 -132
        /home/arya/myown/Positive/Pictures1095.jpeg 1 128 166 662 -63
        /home/arya/myown/Positive/images355.jpeg 2 92 16 224 25 92 16 117 130
        /home/arya/myown/Positive/face369.jpeg 1 209 146 16 -47
        /home/arya/myown/Positive/images888.jpeg 1 108 29 116 71
        /home/arya/myown/Positive/images2535.jpeg 1 108 29 111 129
        /home/arya/myown/Positive/images18221.jpeg 1 110 34 109 124
        /home/arya/myown/Positive/images1127.jpeg 1 110 34 92 104
        /home/arya/myown/Positive/face600.jpeg 2 202 138 18 -34 80 55 63 73
        /home/arya/myown/Positive/images18357.jpeg 1 103 27 142 133
        /home/arya/myown/Positive/images889.jpeg 1 86 25 134 124
        /home/arya/myown/Positive/face583.jpeg 1 225 109 86 83
        /home/arya/myown/Positive/images1239.jpeg 1 84 28 136 125
        /home/arya/myown/Positive/images2506.jpeg 1 93 17 112 111
        /home/arya/myown/Positive/images2526.jpeg 1 102 21 110 117
        /home/arya/myown/Positive/Pictures1281.jpeg 1 670 31 205 258
        /home/arya/myown/Positive/images963.jpeg 1 105 21 106 134
        /home/arya/myown/Positive/Pictures544.jpeg 2 147 276 69 64 263 246 47 67
        /home/arya/myown/Positive/images18289.jpeg 1 82 30 153 124

        What is the problem?I don’t understand..please help me…

      4. Now I removed all the -ve values also.But nw I am getting only 155 samples out of 2621 and shows error like this.

        Info file name: (NULL)
        Img file name: (NULL)
        Vec file name: vefile.vec
        BG file name: (NULL)
        Num: 1000
        BG color: 0
        BG threshold: 80
        Invert: FALSE
        Max intensity deviation: 40
        Max x angle: 1.1
        Max y angle: 1.1
        Max z angle: 0.5
        Show samples: TRUE
        Scale: 4
        Width: 24
        Height: 24
        View samples from vec file (press ESC to exit)…
        init done
        opengl support available
        OpenCV Error: Assertion failed (elements_read == 1) in icvGetHaarTraininDataFromVecCallback, file /home/arya/stuff/opencv/opencv-2.4.7/apps/haartraining/cvhaartraining.cpp, line 1859
        terminate called after throwing an instance of ‘cv::Exception’
        what(): /home/arya/stuff/opencv/opencv-2.4.7/apps/haartraining/cvhaartraining.cpp:1859: error: (-215) elements_read == 1 in function icvGetHaarTraininDataFromVecCallback

        Aborted (core dumped)

        ———————————————–
        What is this error? I don’t understand..

  2. Hello. Can you help me about opencv_createsamples? I have opencv 2.4.2 but it hasn’t createsamples and I I do not know how to compile createsamples.cpp

  3. I’m looking for my comment. it’s disappear. I have question about where i must put that positive and negative image in that project.

  4. I m not really understand where i must put my positive pictures when i want to create object maker. are they must in one folder with object maker.cpp????
    I’m sorry for my stupid question. but it’s make me going to crazy.

    1. WHile the classifier training is still progressing, we can test the detection reliability without interrupting the training process.
      Run the command
      convert_cascade –size=”30×32″ data intermediate.xml
      and test the generated intermediate.xml for goodness

  5. please, have a problem to append bmp image in objectmarker program:

    [stefano@bridgelinux test penna]$ ./om positive.txt ./img/
    Object Marker: Input Directory: ./img/ Output File: positive.txt
    Opening directory…done.
    Examining file .
    Loading image .
    Examining file ..
    Loading image ..
    Examining file Pictures329.bmp
    Loading image Pictures329.bmp
    Examining file Pictures56.bmp
    Loading image Pictures56.bmp
    Examining file Pictures100.bmp
    Loading image Pictures100.bmp
    Examining file Pictures261.bmp
    Loading image Pictures261.bmp
    Examining file Pictures40.bmp
    Loading image Pictures40.bmp
    Examining file Pictures321.bmp
    Loading image Pictures321.bmp
    Examining file Pictures143.bmp
    Loading image Pictures143.bmp
    Examining file Pictures16.bmp
    Loading image Pictures16.bmp
    Examining file Pictures60.bmp
    Loading image Pictures60.bmp
    Examining file Pictures76.bmp
    Loading image Pictures76.bmp
    Examining file Pictures191.bmp
    Loading image Pictures191.bmp
    Examining file Pictures220.bmp
    Loading image Pictures220.bmp
    Examining file Pictures156.bmp
    Loading image Pictures156.bmp
    Examining file Pictures393.bmp
    Loading image Pictures393.bmp
    Examining file Pictures275.bmp
    Loading image Pictures275.bmp
    Examining file Pictures147.bmp
    Loading image Pictures147.bmp
    Examining file Pictures35.bmp
    Loading image Pictures35.bmp
    Examining file Pictures303.bmp
    Loading image Pictures303.bmp
    Examining file Pictures333.bmp
    Loading image Pictures333.bmp
    Examining file Pictures307.bmp
    Loading image Pictures307.bmp
    Examining file Pictures106.bmp
    Loading image Pictures106.bmp
    Examining file Pictures74.bmp
    Loading image Pictures74.bmp
    Examining file Pictures102.bmp
    Loading image Pictures102.bmp
    Examining file Pictures175.bmp
    Loading image Pictures175.bmp
    Examining file Pictures361.bmp
    Loading image Pictures361.bmp
    Examining file Pictures294.bmp
    Loading image Pictures294.bmp
    Examining file Pictures347.bmp
    Loading image Pictures347.bmp
    Examining file Pictures297.bmp
    Loading image Pictures297.bmp
    Examining file Pictures141.bmp
    Loading image Pictures141.bmp
    Examining file Pictures320.bmp
    Loading image Pictures320.bmp
    Examining file Pictures108.bmp
    Loading image Pictures108.bmp
    Examining file Pictures158.bmp
    Loading image Pictures158.bmp
    Examining file Pictures225.bmp
    Loading image Pictures225.bmp
    Examining file Pictures196.bmp
    Loading image Pictures196.bmp
    Examining file Pictures354.bmp
    Loading image Pictures354.bmp
    Examining file Pictures38.bmp
    Loading image Pictures38.bmp
    Examining file Pictures136.bmp
    Loading image Pictures136.bmp
    Examining file Pictures262.bmp
    Loading image Pictures262.bmp
    Examining file Pictures163.bmp
    Loading image Pictures163.bmp
    Examining file Pictures15.bmp
    Loading image Pictures15.bmp
    Examining file Pictures109.bmp
    Loading image Pictures109.bmp
    Examining file Pictures331.bmp
    Loading image Pictures331.bmp
    Examining file Pictures387.bmp
    Loading image Pictures387.bmp
    Examining file Pictures370.bmp
    Loading image Pictures370.bmp
    Examining file Pictures268.bmp
    Loading image Pictures268.bmp
    Examining file Pictures285.bmp
    Loading image Pictures285.bmp
    Examining file Pictures264.bmp
    Loading image Pictures264.bmp
    Examining file Pictures41.bmp
    Loading image Pictures41.bmp
    Examining file Pictures208.bmp
    Loading image Pictures208.bmp
    Examining file Pictures124.bmp
    Loading image Pictures124.bmp
    Examining file Pictures322.bmp
    Loading image Pictures322.bmp
    Examining file Pictures372.bmp
    Loading image Pictures372.bmp
    Examining file Pictures382.bmp
    Loading image Pictures382.bmp
    Examining file Pictures27.bmp
    Loading image Pictures27.bmp
    Examining file Pictures209.bmp
    Loading image Pictures209.bmp
    Examining file Pictures200.bmp
    Loading image Pictures200.bmp
    Examining file Pictures9.bmp
    Loading image Pictures9.bmp
    Examining file Pictures357.bmp
    Loading image Pictures357.bmp
    Examining file Pictures137.bmp
    Loading image Pictures137.bmp
    Examining file Pictures318.bmp
    Loading image Pictures318.bmp
    Examining file Pictures214.bmp
    Loading image Pictures214.bmp
    Examining file Pictures174.bmp
    Loading image Pictures174.bmp
    Examining file Pictures23.bmp
    Loading image Pictures23.bmp
    Examining file Pictures183.bmp
    Loading image Pictures183.bmp
    Examining file Pictures39.bmp
    Loading image Pictures39.bmp
    Examining file Pictures300.bmp
    Loading image Pictures300.bmp
    Examining file Pictures132.bmp
    Loading image Pictures132.bmp
    Examining file Pictures335.bmp
    Loading image Pictures335.bmp
    Examining file Pictures290.bmp
    Loading image Pictures290.bmp
    Examining file Pictures172.bmp
    Loading image Pictures172.bmp
    Examining file Pictures45.bmp
    Loading image Pictures45.bmp
    Examining file Pictures304.bmp
    Loading image Pictures304.bmp
    Examining file Pictures53.bmp
    Loading image Pictures53.bmp
    Examining file Pictures180.bmp
    Loading image Pictures180.bmp
    Examining file Pictures266.bmp
    Loading image Pictures266.bmp
    Examining file Pictures257.bmp
    Loading image Pictures257.bmp
    Examining file Pictures66.bmp
    Loading image Pictures66.bmp
    Examining file Pictures78.bmp
    Loading image Pictures78.bmp
    Examining file Pictures4.bmp
    Loading image Pictures4.bmp
    Examining file Pictures99.bmp
    Loading image Pictures99.bmp
    Examining file Pictures292.bmp
    Loading image Pictures292.bmp
    Examining file Pictures328.bmp
    Loading image Pictures328.bmp
    Examining file Pictures127.bmp
    Loading image Pictures127.bmp
    Examining file Pictures298.bmp
    Loading image Pictures298.bmp
    Examining file Pictures324.bmp
    Loading image Pictures324.bmp
    Examining file Pictures103.bmp
    Loading image Pictures103.bmp
    Examining file Pictures29.bmp
    Loading image Pictures29.bmp
    Examining file Pictures131.bmp
    Loading image Pictures131.bmp
    Examining file Pictures114.bmp
    Loading image Pictures114.bmp
    Examining file Pictures192.bmp
    Loading image Pictures192.bmp
    Examining file Pictures71.bmp
    Loading image Pictures71.bmp
    Examining file Pictures215.bmp
    Loading image Pictures215.bmp
    Examining file Pictures186.bmp
    Loading image Pictures186.bmp
    Examining file Pictures95.bmp
    Loading image Pictures95.bmp
    Examining file Pictures355.bmp
    Loading image Pictures355.bmp
    Examining file Pictures17.bmp
    Loading image Pictures17.bmp
    Examining file Pictures338.bmp
    Loading image Pictures338.bmp
    Examining file Pictures121.bmp
    Loading image Pictures121.bmp
    Examining file Pictures260.bmp
    Loading image Pictures260.bmp
    Examining file Pictures152.bmp
    Loading image Pictures152.bmp
    Examining file Pictures323.bmp
    Loading image Pictures323.bmp
    Examining file Pictures247.bmp
    Loading image Pictures247.bmp
    Examining file Pictures231.bmp
    Loading image Pictures231.bmp
    Examining file Pictures193.bmp
    Loading image Pictures193.bmp
    Examining file Pictures20.bmp
    Loading image Pictures20.bmp
    Examining file Pictures197.bmp
    Loading image Pictures197.bmp
    Examining file Pictures305.bmp
    Loading image Pictures305.bmp
    Examining file Pictures394.bmp
    Loading image Pictures394.bmp
    Examining file Pictures385.bmp
    Loading image Pictures385.bmp
    Examining file Pictures396.bmp
    Loading image Pictures396.bmp
    Examining file Pictures182.bmp
    Loading image Pictures182.bmp
    Examining file Pictures49.bmp
    Loading image Pictures49.bmp
    Examining file Pictures392.bmp
    Loading image Pictures392.bmp
    Examining file Pictures84.bmp
    Loading image Pictures84.bmp
    Examining file Pictures379.bmp
    Loading image Pictures379.bmp
    Examining file Pictures356.bmp
    Loading image Pictures356.bmp
    Examining file Pictures251.bmp
    Loading image Pictures251.bmp
    Examining file Pictures55.bmp
    Loading image Pictures55.bmp
    Examining file Pictures34.bmp
    Loading image Pictures34.bmp
    Examining file Pictures232.bmp
    Loading image Pictures232.bmp
    Examining file Pictures153.bmp
    Loading image Pictures153.bmp
    Examining file Pictures3.bmp
    Loading image Pictures3.bmp
    Examining file Pictures250.bmp
    Loading image Pictures250.bmp
    Examining file Pictures130.bmp
    Loading image Pictures130.bmp
    Examining file Pictures389.bmp
    Loading image Pictures389.bmp
    Examining file Pictures388.bmp
    Loading image Pictures388.bmp
    Examining file Pictures400.bmp
    Loading image Pictures400.bmp
    Examining file Pictures286.bmp
    Loading image Pictures286.bmp
    Examining file Pictures25.bmp
    Loading image Pictures25.bmp
    Examining file Pictures274.bmp
    Loading image Pictures274.bmp
    Examining file Pictures188.bmp
    Loading image Pictures188.bmp
    Examining file Pictures342.bmp
    Loading image Pictures342.bmp
    Examining file Pictures391.bmp
    Loading image Pictures391.bmp
    Examining file Pictures277.bmp
    Loading image Pictures277.bmp
    Examining file Pictures101.bmp
    Loading image Pictures101.bmp
    Examining file Pictures21.bmp
    Loading image Pictures21.bmp
    Examining file Pictures89.bmp
    Loading image Pictures89.bmp
    Examining file Pictures235.bmp
    Loading image Pictures235.bmp
    Examining file Pictures105.bmp
    Loading image Pictures105.bmp
    Examining file Pictures167.bmp
    Loading image Pictures167.bmp
    Examining file Pictures54.bmp
    Loading image Pictures54.bmp
    Examining file Pictures299.bmp
    Loading image Pictures299.bmp
    Examining file Pictures190.bmp
    Loading image Pictures190.bmp
    Examining file Pictures83.bmp
    Loading image Pictures83.bmp
    Examining file Pictures112.bmp
    Loading image Pictures112.bmp
    Examining file Pictures348.bmp
    Loading image Pictures348.bmp
    Examining file Pictures369.bmp
    Loading image Pictures369.bmp
    Examining file Pictures217.bmp
    Loading image Pictures217.bmp
    Examining file Pictures350.bmp
    Loading image Pictures350.bmp
    Examining file Pictures6.bmp
    Loading image Pictures6.bmp
    Examining file Pictures386.bmp
    Loading image Pictures386.bmp
    Examining file Pictures378.bmp
    Loading image Pictures378.bmp
    Examining file Pictures267.bmp
    Loading image Pictures267.bmp
    Examining file Pictures374.bmp
    Loading image Pictures374.bmp
    Examining file Pictures339.bmp
    Loading image Pictures339.bmp
    Examining file Pictures291.bmp
    Loading image Pictures291.bmp
    Examining file Pictures128.bmp
    Loading image Pictures128.bmp
    Examining file Pictures129.bmp
    Loading image Pictures129.bmp
    Examining file Pictures86.bmp
    Loading image Pictures86.bmp
    Examining file Pictures73.bmp
    Loading image Pictures73.bmp
    Examining file Pictures169.bmp
    Loading image Pictures169.bmp
    Examining file Pictures358.bmp
    Loading image Pictures358.bmp
    Examining file Pictures306.bmp
    Loading image Pictures306.bmp
    Examining file Pictures383.bmp
    Loading image Pictures383.bmp
    Examining file Pictures116.bmp
    Loading image Pictures116.bmp
    Examining file Pictures245.bmp
    Loading image Pictures245.bmp
    Examining file Pictures118.bmp
    Loading image Pictures118.bmp
    Examining file Pictures334.bmp
    Loading image Pictures334.bmp
    Examining file Pictures312.bmp
    Loading image Pictures312.bmp
    Examining file Pictures63.bmp
    Loading image Pictures63.bmp
    Examining file Pictures61.bmp
    Loading image Pictures61.bmp
    Examining file Pictures202.bmp
    Loading image Pictures202.bmp
    Examining file Pictures181.bmp
    Loading image Pictures181.bmp
    Examining file Pictures346.bmp
    Loading image Pictures346.bmp
    Examining file Pictures151.bmp
    Loading image Pictures151.bmp
    Examining file Pictures216.bmp
    Loading image Pictures216.bmp
    Examining file Pictures26.bmp
    Loading image Pictures26.bmp
    Examining file Pictures336.bmp
    Loading image Pictures336.bmp
    Examining file Pictures313.bmp
    Loading image Pictures313.bmp
    Examining file Pictures51.bmp
    Loading image Pictures51.bmp
    Examining file Pictures110.bmp
    Loading image Pictures110.bmp
    Examining file Pictures249.bmp
    Loading image Pictures249.bmp
    Examining file Pictures189.bmp
    Loading image Pictures189.bmp
    Examining file Pictures115.bmp
    Loading image Pictures115.bmp
    Examining file Pictures368.bmp
    Loading image Pictures368.bmp
    Examining file Pictures145.bmp
    Loading image Pictures145.bmp
    Examining file Pictures252.bmp
    Loading image Pictures252.bmp
    Examining file Pictures111.bmp
    Loading image Pictures111.bmp
    Examining file Pictures255.bmp
    Loading image Pictures255.bmp
    Examining file Pictures218.bmp
    Loading image Pictures218.bmp
    Examining file Pictures187.bmp
    Loading image Pictures187.bmp
    Examining file Pictures31.bmp
    Loading image Pictures31.bmp
    Examining file Pictures113.bmp
    Loading image Pictures113.bmp
    Examining file Pictures165.bmp
    Loading image Pictures165.bmp
    Examining file Pictures154.bmp
    Loading image Pictures154.bmp
    Examining file Pictures360.bmp
    Loading image Pictures360.bmp
    Examining file Pictures198.bmp
    Loading image Pictures198.bmp
    Examining file Pictures349.bmp
    Loading image Pictures349.bmp
    Examining file Pictures88.bmp
    Loading image Pictures88.bmp
    Examining file Pictures123.bmp
    Loading image Pictures123.bmp
    Examining file Pictures5.bmp
    Loading image Pictures5.bmp
    Examining file Pictures223.bmp
    Loading image Pictures223.bmp
    Examining file Pictures353.bmp
    Loading image Pictures353.bmp
    Examining file Pictures13.bmp
    Loading image Pictures13.bmp
    Examining file Pictures332.bmp
    Loading image Pictures332.bmp
    Examining file Pictures248.bmp
    Loading image Pictures248.bmp
    Examining file Pictures259.bmp
    Loading image Pictures259.bmp
    Examining file Pictures120.bmp
    Loading image Pictures120.bmp
    Examining file Pictures195.bmp
    Loading image Pictures195.bmp
    Examining file Pictures62.bmp
    Loading image Pictures62.bmp
    Examining file Pictures278.bmp
    Loading image Pictures278.bmp
    Examining file Pictures263.bmp
    Loading image Pictures263.bmp
    Examining file Pictures238.bmp
    Loading image Pictures238.bmp
    Examining file Pictures125.bmp
    Loading image Pictures125.bmp
    Examining file Pictures269.bmp
    Loading image Pictures269.bmp
    Examining file Pictures258.bmp
    Loading image Pictures258.bmp
    Examining file Pictures341.bmp
    Loading image Pictures341.bmp
    Examining file Pictures68.bmp
    Loading image Pictures68.bmp
    Examining file Pictures244.bmp
    Loading image Pictures244.bmp
    Examining file Pictures242.bmp
    Loading image Pictures242.bmp
    Examining file Pictures384.bmp
    Loading image Pictures384.bmp
    Examining file Pictures8.bmp
    Loading image Pictures8.bmp
    Examining file Pictures11.bmp
    Loading image Pictures11.bmp
    Examining file Pictures199.bmp
    Loading image Pictures199.bmp
    Examining file Pictures380.bmp
    Loading image Pictures380.bmp
    Examining file Pictures75.bmp
    Loading image Pictures75.bmp
    Examining file Pictures310.bmp
    Loading image Pictures310.bmp
    Examining file Pictures22.bmp
    Loading image Pictures22.bmp
    Examining file Pictures201.bmp
    Loading image Pictures201.bmp
    Examining file Pictures184.bmp
    Loading image Pictures184.bmp
    Examining file Pictures64.bmp
    Loading image Pictures64.bmp
    Examining file Pictures276.bmp
    Loading image Pictures276.bmp
    Examining file Pictures90.bmp
    Loading image Pictures90.bmp
    Examining file Pictures14.bmp
    Loading image Pictures14.bmp
    Examining file Pictures119.bmp
    Loading image Pictures119.bmp
    Examining file Pictures395.bmp
    Loading image Pictures395.bmp
    Examining file Pictures284.bmp
    Loading image Pictures284.bmp
    Examining file Pictures265.bmp
    Loading image Pictures265.bmp
    Examining file Pictures2.bmp
    Loading image Pictures2.bmp
    Examining file Pictures79.bmp
    Loading image Pictures79.bmp
    Examining file Pictures94.bmp
    Loading image Pictures94.bmp
    Examining file Pictures24.bmp
    Loading image Pictures24.bmp
    Examining file Pictures365.bmp
    Loading image Pictures365.bmp
    Examining file Pictures221.bmp
    Loading image Pictures221.bmp
    Examining file Pictures207.bmp
    Loading image Pictures207.bmp
    Examining file Pictures343.bmp
    Loading image Pictures343.bmp
    Examining file Pictures279.bmp
    Loading image Pictures279.bmp
    Examining file Pictures92.bmp
    Loading image Pictures92.bmp
    Examining file Pictures142.bmp
    Loading image Pictures142.bmp
    Examining file Pictures77.bmp
    Loading image Pictures77.bmp
    Examining file Pictures70.bmp
    Loading image Pictures70.bmp
    Examining file Pictures176.bmp
    Loading image Pictures176.bmp
    Examining file Pictures373.bmp
    Loading image Pictures373.bmp
    Examining file Pictures272.bmp
    Loading image Pictures272.bmp
    Examining file Pictures72.bmp
    Loading image Pictures72.bmp
    Examining file Pictures213.bmp
    Loading image Pictures213.bmp
    Examining file Pictures317.bmp
    Loading image Pictures317.bmp
    Examining file Pictures65.bmp
    Loading image Pictures65.bmp
    Examining file Pictures104.bmp
    Loading image Pictures104.bmp
    Examining file Pictures363.bmp
    Loading image Pictures363.bmp
    Examining file Pictures271.bmp
    Loading image Pictures271.bmp
    Examining file Pictures246.bmp
    Loading image Pictures246.bmp
    Examining file Pictures210.bmp
    Loading image Pictures210.bmp
    Examining file Pictures42.bmp
    Loading image Pictures42.bmp
    Examining file Pictures135.bmp
    Loading image Pictures135.bmp
    Examining file Pictures107.bmp
    Loading image Pictures107.bmp
    Examining file Pictures52.bmp
    Loading image Pictures52.bmp
    Examining file Pictures325.bmp
    Loading image Pictures325.bmp
    Examining file Pictures18.bmp
    Loading image Pictures18.bmp
    Examining file Pictures122.bmp
    Loading image Pictures122.bmp
    Examining file Pictures227.bmp
    Loading image Pictures227.bmp
    Examining file Pictures134.bmp
    Loading image Pictures134.bmp
    Examining file Pictures293.bmp
    Loading image Pictures293.bmp
    Examining file Pictures12.bmp
    Loading image Pictures12.bmp
    Examining file Pictures397.bmp
    Loading image Pictures397.bmp
    Examining file Pictures239.bmp
    Loading image Pictures239.bmp
    Examining file Pictures157.bmp
    Loading image Pictures157.bmp
    Examining file Pictures144.bmp
    Loading image Pictures144.bmp
    Examining file Pictures155.bmp
    Loading image Pictures155.bmp
    Examining file Pictures330.bmp
    Loading image Pictures330.bmp
    Examining file Pictures97.bmp
    Loading image Pictures97.bmp
    Examining file Pictures253.bmp
    Loading image Pictures253.bmp
    Examining file Pictures399.bmp
    Loading image Pictures399.bmp
    Examining file Pictures287.bmp
    Loading image Pictures287.bmp
    Examining file Pictures19.bmp
    Loading image Pictures19.bmp
    Examining file Pictures345.bmp
    Loading image Pictures345.bmp
    Examining file Pictures185.bmp
    Loading image Pictures185.bmp
    Examining file Pictures87.bmp
    Loading image Pictures87.bmp
    Examining file Pictures283.bmp
    Loading image Pictures283.bmp
    Examining file Pictures161.bmp
    Loading image Pictures161.bmp
    Examining file Pictures91.bmp
    Loading image Pictures91.bmp
    Examining file Pictures211.bmp
    Loading image Pictures211.bmp
    Examining file Pictures212.bmp
    Loading image Pictures212.bmp
    Examining file Pictures69.bmp
    Loading image Pictures69.bmp
    Examining file Pictures7.bmp
    Loading image Pictures7.bmp
    Examining file Pictures352.bmp
    Loading image Pictures352.bmp
    Examining file Pictures376.bmp
    Loading image Pictures376.bmp
    Examining file Pictures302.bmp
    Loading image Pictures302.bmp
    Examining file Pictures367.bmp
    Loading image Pictures367.bmp
    Examining file Pictures301.bmp
    Loading image Pictures301.bmp
    Examining file Pictures96.bmp
    Loading image Pictures96.bmp
    Examining file Pictures164.bmp
    Loading image Pictures164.bmp
    Examining file Pictures58.bmp
    Loading image Pictures58.bmp
    Examining file Pictures162.bmp
    Loading image Pictures162.bmp
    Examining file Pictures228.bmp
    Loading image Pictures228.bmp
    Examining file Pictures371.bmp
    Loading image Pictures371.bmp
    Examining file Pictures126.bmp
    Loading image Pictures126.bmp
    Examining file Pictures37.bmp
    Loading image Pictures37.bmp
    Examining file Pictures377.bmp
    Loading image Pictures377.bmp
    Examining file Pictures308.bmp
    Loading image Pictures308.bmp
    Examining file Pictures133.bmp
    Loading image Pictures133.bmp
    Examining file Pictures359.bmp
    Loading image Pictures359.bmp
    Examining file Pictures98.bmp
    Loading image Pictures98.bmp
    Examining file Pictures240.bmp
    Loading image Pictures240.bmp
    Examining file Pictures327.bmp
    Loading image Pictures327.bmp
    Examining file Pictures204.bmp
    Loading image Pictures204.bmp
    Examining file Pictures85.bmp
    Loading image Pictures85.bmp
    Examining file Pictures224.bmp
    Loading image Pictures224.bmp
    Examining file Pictures168.bmp
    Loading image Pictures168.bmp
    Examining file Pictures282.bmp
    Loading image Pictures282.bmp
    Examining file Pictures296.bmp
    Loading image Pictures296.bmp
    Examining file Pictures256.bmp
    Loading image Pictures256.bmp
    Examining file Pictures117.bmp
    Loading image Pictures117.bmp
    Examining file Pictures270.bmp
    Loading image Pictures270.bmp
    Examining file Pictures93.bmp
    Loading image Pictures93.bmp
    Examining file Pictures48.bmp
    Loading image Pictures48.bmp
    Examining file Pictures57.bmp
    Loading image Pictures57.bmp
    Examining file Pictures1.bmp
    Loading image Pictures1.bmp
    Examining file Pictures173.bmp
    Loading image Pictures173.bmp
    Examining file Pictures219.bmp
    Loading image Pictures219.bmp
    Examining file Pictures171.bmp
    Loading image Pictures171.bmp
    Examining file Pictures289.bmp
    Loading image Pictures289.bmp
    Examining file Pictures311.bmp
    Loading image Pictures311.bmp
    Examining file Pictures159.bmp
    Loading image Pictures159.bmp
    Examining file Pictures398.bmp
    Loading image Pictures398.bmp
    Examining file Pictures203.bmp
    Loading image Pictures203.bmp
    Examining file Pictures36.bmp
    Loading image Pictures36.bmp
    Examining file Pictures236.bmp
    Loading image Pictures236.bmp
    Examining file Pictures319.bmp
    Loading image Pictures319.bmp
    Examining file Pictures160.bmp
    Loading image Pictures160.bmp
    Examining file Pictures32.bmp
    Loading image Pictures32.bmp
    Examining file Pictures234.bmp
    Loading image Pictures234.bmp
    Examining file Pictures280.bmp
    Loading image Pictures280.bmp
    Examining file Pictures170.bmp
    Loading image Pictures170.bmp
    Examining file Pictures295.bmp
    Loading image Pictures295.bmp
    Examining file Pictures340.bmp
    Loading image Pictures340.bmp
    Examining file Pictures33.bmp
    Loading image Pictures33.bmp
    Examining file Pictures375.bmp
    Loading image Pictures375.bmp
    Examining file Pictures229.bmp
    Loading image Pictures229.bmp
    Examining file Pictures166.bmp
    Loading image Pictures166.bmp
    Examining file Pictures81.bmp
    Loading image Pictures81.bmp
    Examining file Pictures309.bmp
    Loading image Pictures309.bmp
    Examining file Pictures59.bmp
    Loading image Pictures59.bmp
    Examining file Pictures44.bmp
    Loading image Pictures44.bmp
    Examining file Pictures326.bmp
    Loading image Pictures326.bmp
    Examining file Pictures206.bmp
    Loading image Pictures206.bmp
    Examining file Pictures67.bmp
    Loading image Pictures67.bmp
    Examining file Pictures150.bmp
    Loading image Pictures150.bmp
    Examining file Pictures222.bmp
    Loading image Pictures222.bmp
    Examining file Pictures178.bmp
    Loading image Pictures178.bmp
    Examining file Pictures362.bmp
    Loading image Pictures362.bmp
    Examining file Pictures390.bmp
    Loading image Pictures390.bmp
    Examining file Pictures80.bmp
    Loading image Pictures80.bmp
    Examining file Pictures315.bmp
    Loading image Pictures315.bmp
    Examining file Pictures139.bmp
    Loading image Pictures139.bmp
    Examining file Pictures194.bmp
    Loading image Pictures194.bmp
    Examining file Pictures177.bmp
    Loading image Pictures177.bmp
    Examining file Pictures148.bmp
    Loading image Pictures148.bmp
    Examining file Pictures366.bmp
    Loading image Pictures366.bmp
    Examining file Pictures138.bmp
    Loading image Pictures138.bmp
    Examining file Pictures226.bmp
    Loading image Pictures226.bmp
    Examining file Pictures149.bmp
    Loading image Pictures149.bmp
    Examining file Pictures237.bmp
    Loading image Pictures237.bmp
    Examining file Pictures50.bmp
    Loading image Pictures50.bmp
    Examining file Pictures230.bmp
    Loading image Pictures230.bmp
    Examining file Pictures381.bmp
    Loading image Pictures381.bmp
    Examining file Pictures351.bmp
    Loading image Pictures351.bmp
    Examining file Pictures28.bmp
    Loading image Pictures28.bmp
    Examining file Pictures30.bmp
    Loading image Pictures30.bmp
    Examining file Pictures314.bmp
    Loading image Pictures314.bmp
    Examining file Pictures254.bmp
    Loading image Pictures254.bmp
    Examining file Pictures233.bmp
    Loading image Pictures233.bmp
    Examining file Pictures10.bmp
    Loading image Pictures10.bmp
    Examining file Pictures43.bmp
    Loading image Pictures43.bmp
    Examining file Pictures205.bmp
    Loading image Pictures205.bmp
    Examining file Pictures281.bmp
    Loading image Pictures281.bmp
    Examining file Pictures47.bmp
    Loading image Pictures47.bmp
    Examining file Pictures241.bmp
    Loading image Pictures241.bmp
    Examining file Pictures140.bmp
    Loading image Pictures140.bmp
    Examining file Pictures146.bmp
    Loading image Pictures146.bmp
    Examining file Pictures179.bmp
    Loading image Pictures179.bmp
    Examining file Pictures337.bmp
    Loading image Pictures337.bmp
    Examining file Pictures82.bmp
    Loading image Pictures82.bmp
    Examining file Pictures316.bmp
    Loading image Pictures316.bmp
    Examining file Pictures46.bmp
    Loading image Pictures46.bmp
    Examining file Pictures288.bmp
    Loading image Pictures288.bmp
    Examining file Pictures273.bmp
    Loading image Pictures273.bmp
    Examining file Pictures243.bmp
    Loading image Pictures243.bmp
    Examining file Pictures364.bmp
    Loading image Pictures364.bmp
    Examining file Pictures344.bmp
    Loading image Pictures344.bmp

    why?

  6. Hey im getting parse error when executing create samples. it says parse error.creating 99 samples.
    I have 500 bounding boxes in my positive descriptor file of 6 images.But it says 99 samples are created.why this is happening? Does it require a merge vec?

  7. Hi, I have a question about image backgrounds.

    In my positive samples, I have 3 sets of images:
    1. a set of colored images with a white background and with the object displayed at a different angles in each image
    2. another set with the same images in grayscale and with a white background
    3. another set with the same images in grayscale and with a black background

    My question is that in set 1, should the background really be white? Should it not be within an environment that the object is likely to be found in in the testing datset? Or should I have a fourth set where the images are in their natural environments?

  8. I have an important question, if someone knows this please answer me.

    What is happening to the negative images in the algorithm? Are they subsampled to the size of the training window? If so, I couldn’t be using actual background images, and rather ROIs of negative images.

    I am using a lot of background images to train my classifier, but if the program is resizing all the negatives to the size of the training window, it will be completely pointless.

  9. Minecraft works as a sandbox independent game at first developed by
    Mojang in which you construct by using blocks and then embark upon missions.
    Check within the globe of Minecraft, unpleasant
    creatures hide during the dark regarding the evening, you need
    to produce a hideout right before they’ll secure you. Focus on performing immediately by way of downloading
    this free Minecraft Game Client to assist you to launch your current expedition.

    Minecraft is normally a lot of fun to have with the help of guests.
    You’re able get together in order to really erect
    what you may expect and then let your visualization become wild, deal
    with things that go bump across a night. If you are courageous
    enough, move to The Nether, certainly you will a little surprised.

  10. Can I simply say what a relief to find somebody who actually understands what they are talking about
    on the internet. You definitely understand how to bring a problem to light and make it important.
    More and more people should check this out and understand this side of your story.
    I was surprised that you are not more popular since you certainly possess
    the gift.

  11. I believe everything published made a ton of sense.
    But, what about this? what if you added a little information?

    I mean, I don’t want to tell you how to run your blog, but what if you added something to possibly get folk’s attention?

    I mean Create Your Own Haar Classifier for Detecting objects in
    OpenCV | Achu’s TechBlog is kinda vanilla. You
    should look at Yahoo’s home page and see how they create news
    headlines to get people to open the links. You might add a related video or a related picture or two to grab people interested about what you’ve got to say.
    In my opinion, it would make your website a little bit more interesting.

  12. I’m not that much of a online reader to be honest but
    your blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back in the future.
    Cheers

  13. I’m really impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you customize it yourself? Either
    way keep up the nice quality writing, it’s rare to see a great blog like this one these days.

  14. Hey there! I knokw tis is kinda off topic butt I wwas
    wondering which blog platform arre you using for this site?
    I’m getting tired of WordPress because I’ve had problems with
    hackers and I’m looking at alternatives for
    another platform. I would be great if you could
    point me in the direction of a good platform.

  15. while playing with the objectmarker.cpp i made some changes to work properly:
    At first i had to run the program from the directory i had the positive images,
    and in order to move to the next one, i changed the ASCII which is capital B to 98 ( b ) in order to work. Search inside the code for ’66’ and change it with ’98’ .

  16. Hi there!

    I am doing a research project in gesture for music. I am a musician/composer and VERY new to all this. It is quite a steep learning curve. I am going to attempt to use the haar code to create the required files to detect hand movements along a finger board.

    I have Xcode on Mac os 10.8.4

    what do I do/use to compile this code using Xcode? I see c++ compilers are available etc., but I am not sure how to use it. I have compiled and installed OpenCV.

    Kindly let me know – much appreciated.

    1. Hi,
      I feel that instead of using haar classifiers to detect hand movement, it would be better to use a kinect to do skeletal tracking and interface it to do music control

      1. Hi –

        Thank you for the response! Indeed we have investigated the Kinect as a possibility, but it won’t be able to do what we want. We require a system to compare images in real-time to make PureData bang when certain images are detected that relate to specific movements. Do you think that this system would be able to help us with this or something else? I can converse more about the project privately if you wish.

        Thanks and best wishes

  17. 場合あなたすぐにヒットをGoogleの見つけるどこSnookiを得た紛れもなく、カスタムメイドの靴、あなたweren’tです自己にそれ。6のスタイルは、この来るですか?1つのダブルブレストに加えピーク襟こと、グログランリボン襟に直面して。

  18. how i solved many errors while doing training
    1. while creating the negative.txt use ls -d $PWD/* > ~/where/you/want/the/negative.txt (cd /negative/images/are stored)
    2. while creating samples dont just use any number for width and height it should be less than least width and height from the cropped images i.e from positive.txt (last two columns)
    3. use the width and height in the aspect ratio of the negative images (solved many errors for me)
    4. pass the number of images both positive and negative in arguement while training (by default it takes 1000)
    ex opencv_haartraining -data haar -vec vecfile.vec -bg negative.txt -nstages 24 -npos 800 -nneg 1800 -mem 2000 -mode ALL -w 32 -h 24
    5. pass the npos less than the number in vec file like i had some 1000 images i passed 800 as above
    6. if you are using opencv_traincascade instead of opencv_haartraining convert_cascade wont work. dont waste time debugging.

  19. Sais-MacBook-Pro:~ saiprasadsabeson$ opencv_haartraining -data haarcascade -vec vecfile.vec -bg negative.txt -npos 10 -nneg 10 -w 500 -h 500 -nonsym -mem 2048 -mode ALL
    Data dir name: haarcascade
    Vec file name: vecfile.vec
    BG file name: negative.txt, is a vecfile: no
    Num pos: 10
    Num neg: 10
    Num stages: 14
    Num splits: 1 (stump as weak classifier)
    Mem: 2048 MB
    Symmetric: FALSE
    Min hit rate: 0.995000
    Max false alarm rate: 0.500000
    Weight trimming: 0.950000
    Equal weights: FALSE
    Mode: ALL
    Width: 500
    Height: 500
    Applied boosting algorithm: GAB
    Error (valid only for Discrete and Real AdaBoost): misclass
    Max number of splits in tree cascade: 0
    Min number of positive samples per cluster: 500
    Required leaf false alarm rate: 6.10352e-05

    Tree Classifier
    Stage
    +—+
    | 0|
    +—+

  20. there might be a small correction
    opencv_createsamples -vec vecfile.vec -show

    we need to pass the width and height along with if we are not using the default 24×24 while creating the vecfile.

    opencv_createsamples -vec vecfile.vec -show -w 30 -h 32

  21. hi!,I really like your writing very much! share we keep up a correspondence more
    about your post on AOL? I need an expert in this house to solve my problem.

    Maybe that’s you! Looking forward to peer you.

  22. Getting an error for trying to include dirent.h. I have it downloaded and copied into the include folder. Anyone able to shed some light on this problem?

  23. Hi Achu, above object marker program works for only one image . Please help to solve our problem , we’ve followed all the above steps .

  24. Hi Achu , when i try to run my objectmarker.cpp only one image is opening . I’m not able to do for multiple images . Help me

  25. Awesome post…thanks a lot..it really helped me…I am trying to detect car using this method..i have completed all the steps..but its taking more time in haartraining..
    Could any one suggest me on how to reduce the time, also please suggests me on how to collect different positive data and negative data..more information on that is required…

  26. What could be the problem? plz reply

    OpenCV Error: Insufficient memory (Failed to allocate 65408 bytes) in unknown fu
    nction, file ..\..\..\..\ocv\opencv\src\cxcore\cxalloc.cpp, line 52

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application’s support team for more information.

  27. I wrote a program to detect the face using opencv 2.1 in visual studion 2008. I used haarcascade_frontalface_alt xml file to do it. The program run properly in visual studio 2008. But when i run application.exe which made in debug folder it didn’t work. what should i do now. how can i run the applicaion exe file. i think xml file didn’t get when it run from exe.

  28. Hi. I’ve followed you tutorial and i can only say how great it is! And thanks for that.

    Nevertheless, when it comes to convert_cascade, i can seem to be able to run it. When i do:
    (..)convert_cascade -size”24×24″ haar stapler.xml, it keep displaying the “help” ie, telling me

    This sample demonstrates cascade’s convertation
    Usage:
    ./convert_cascade –size=”x”
    input_cascade_path
    output_cascade_filename
    Example:
    ./convert_cascade –size=640×480 ../../opencv/data/haarcascades/haarcascade_eye.xml ../../opencv/data/haarcascades/test_cascade.xml

    This sample demonstrates cascade’s convertation
    Usage:
    ./convert_cascade –size=”x”
    input_cascade_path
    output_cascade_filename
    Example:
    ./convert_cascade –size=640×480 ../../opencv/data/haarcascades/haarcascade_eye.xml ../../opencv/data/haarcascades/test_cascade.xml

    Could anyone help me?
    I have a directory named haar that was generated by opencv_haartraining. Plus, it generated as well a xml file with the same name (haar.xml).

    What am i doing wrong?
    Thanks

  29. Alrighty, I Keep trying this but with every test I made, faces, hands, an arizona can.. I keep getting this little error:
    ‘*** 1 cluster ***
    OpenCV Error: Assertion failed (elements_read == 1) in icvGetHaarTraininDataFromVecCallback, file /home/tj/src/OpenCV-2.4.1/apps/haartraining/cvhaartraining.cpp, line 1858
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/tj/src/OpenCV-2.4.1/apps/haartraining/cvhaartraining.cpp:1858: error: (-215) elements_read == 1 in function icvGetHaarTraininDataFromVecCallback

    Aborted (core dumped)

    Any help would be appreciated.

  30. Hi, I am trying to train for days with 7000 positive and 3019 negative images. I always get this error:

    OpenCV Error: Assertion failed (elements_read == 1) in icvGetHaarTraininDataFromVecCallback, file cvhaartraining.cpp, line 1858
    terminate called after throwing an instance of ‘cv::Exception’
    what(): cvhaartraining.cpp:1858: error: (-215) elements_read == 1 in function icvGetHaarTraininDataFromVecCallback

    It works well when I try to learn with 2000 or 3000 positive images.
    What is wrong?
    thx

    1. Hi!
      I had exactly this problem and I solved it by running haar training with less positive count than created with createsamples, like this:
      createsamples … -npos 1000 …
      haartraining … -npos 900 …

      This is not a very scientific solution, but it worked for me. The difference could probably be less (noticed when I debugged and stepped through the haartraining).

  31. How can I speed up the training process. I have core i7 possessor. but the training process is not increasing the number of parent nodes. Is this a problem???
    actually how much time is consume for this training process?????

  32. Great work its work properly.Thanks lot.Plz tell me after detecting hand how we can use those gestures for handle mouse click events???

  33. I am trying to make objectmarker.cpp for windows …but its not working…can any one share the code for windows

      1. hi, please i want to know how to run this code for windows? where can i put the name of the input_directory in this code?
        Thanks

  34. I have this error, can you help me :
    I have all the pics in the same folder ( and i have the positive.txt, negative.txt and the vecfile.vec)

    >> opencv_haartraining -data haar -vec vecfile.vec -bg negative.txt -nstages 30 -mem 2000 -mode all -w 30 -h 32
    Data dir name: haar
    Vec file name: vecfile.vec
    BG file name: negative.txt, is a vecfile: no
    Num pos: 2000
    Num neg: 2000
    Num stages: 30
    Num splits: 1 (stump as weak classifier)
    Mem: 2000 MB
    Symmetric: TRUE
    Min hit rate: 0.995000
    Max false alarm rate: 0.500000
    Weight trimming: 0.950000
    Equal weights: FALSE
    Mode: BASIC
    Width: 30
    Height: 32
    Applied boosting algorithm: GAB
    Error (valid only for Discrete and Real AdaBoost): misclass
    Max number of splits in tree cascade: 0
    Min number of positive samples per cluster: 500
    Required leaf false alarm rate: 9.31323e-10

    Tree Classifier
    Stage
    +—+
    | 0|
    +—+

    Number of features used : 234720
    OpenCV Error: Unspecified error (Unable to read negative images) in cvCreateTreeCascadeClassifier, file /build/buildd/opencv-2.1.0/apps/haartraining/cvhaartraining.cpp, line 2420
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /build/buildd/opencv-2.1.0/apps/haartraining/cvhaartraining.cpp:2420: error: (-2) Unable to read negative images in function cvCreateTreeCascadeClassifier

    1. the first code is not generating the good result for the positive .txt, i fixed that but now i have a problem with convert_cascade . The function it’s not on Mint’terminal or on Win7’cmd

      1. Hi ..
        I am Also facing the same problem which you have posted. Will you please tell me how you have solved this issue ??

      1. C:\Users\Doree\Desktop\Input\Negative>C:\OpenCV2.1\samples\c\convert_cascade.exe
        –size=”30×32″ haar bottle.xml

    2. try to modify how it runs. and the following parameters. -npos (then type the total number of positive images u used ex -npos 5) add this also -nneg (then type the total number of negative images u used ex -nneg 17) and also add -nonsym
      let me know if it helps

      1. I can verify that this solution works. Just make sure you make -npos equal to the number of samples that create_samples returns (to your vecfile) and make -nneg equal to the number of negative images in your /Negative folder and I believe that -nonsym is also required. Also my negative.txt and /haar folder were in separate locations so I had to include the full path for both to make it work. Also definitely make sure your -h and -w are the same you use for create_samples or it will fail.

        Also thank you Achu, this post has been really helpful.

    3. can u please help me m trying to do dus as ma year pro m stuck while creating vec file vec file is created but its size is 0 kb can any one help me

  35. Hi! Thank you for a great and very helpful post! :>

    I followed the detect.c and used it for eye detection. An debug error is occurring as I debug it. The prompted message suggests to retry. And so that’s what I did. A breakpoint message would then be prompted. When I clicked the “continue” button it would then prompt (through the command prompt) “Assertion failed: cascade && storage && capture, file c:\users\sony vaio\documents\visual studio 2010\project\eyetracker\eyetracker\eyetracker.cpp, line 52”

    Here is my code. I hope you could help me.😐

    #include
    #include
    #include “cv.h”
    #include “highgui.h”
    #include
    #include
    #include
    #include
    #include
    #include

    CvHaarClassifierCascade *cascade;
    CvMemStorage *storage;

    void detecteyes( IplImage *img );

    //int X;

    //IplImage *resframe=0;

    int main( int argc, char** argv ){
    CvCapture *capture;
    IplImage *frame;
    int key;
    char *filename = “haarcascade_eyes.xml”;

    // IplImage *bframe=0;

    /* load the classifier
    note that I put the file in the same directory with
    this code */
    // bframe = cvLoadImage(“PICTURE.jpg”,CV_LOAD_IMAGE_COLOR);
    cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );

    /* setup memory buffer; needed by the face detector */
    storage = cvCreateMemStorage( 0 );

    /* initialize camera */
    capture = cvCaptureFromCAM(0);
    /* always check */
    assert(cascade && storage && capture );

    /* create a window */
    cvNamedWindow( “video”, 1 );

    while( key != ‘q’ ) {
    /* get a frame */
    frame = cvQueryFrame( capture );
    /* always check */
    // if( !frame ) break;
    /* ‘fix’ frame */
    // cvFlip( frame, frame, 1 );
    // frame->origin = 0;
    /* detect faces and display video */
    detecteyes(frame);

    /* quit if user press ‘q’ */
    key = cvWaitKey( 50 );
    }
    /* free memory */
    cvReleaseImage(&frame);
    cvReleaseCapture( &capture );
    cvDestroyWindow( “video” );

    cvReleaseHaarClassifierCascade( &cascade );

    cvReleaseMemStorage( &storage );
    return 0;
    }

    void detecteyes(IplImage* img)
    {
    int i,x;
    x=0;

    CvSeq *eyes = cvHaarDetectObjects(
    img,
    cascade,
    storage,
    1.1,
    3,
    0,
    cvSize(10,10)

    );

    for( i=0; i total : 0) ; i++){

    CvRect *r = ( CvRect* )cvGetSeqElem( eyes, i );

    cvRectangle( img,

    cvPoint( r->x, r->y),
    cvPoint( r->x + r->width, r->y + r->height ),
    CV_RGB(255, 0, 0), 1, 8, 0);

    x=x+1;
    printf(“eyes detected %d”,x);
    }
    cvShowImage( “video”, img );
    }

    1. this is included in the initialization part (I forgot to copy this when I first posted this comment)

      #include “stdafx.h”
      #include
      #include “cv.h”
      #include “highgui.h”
      #include
      #include
      #include
      #include
      #include
      #include

  36. hi Achu, i train the haar for LPD but i not alsway stop with Required leaf
    false alarm rate achieved. Branch training terminated
    temp\opencv_haartraining.exe -data /data/cascade -vec data/vector.vec -bg negative/infofile.txt -npos 305 -nneg 305 -nstages 20 -mem 1500 -mode ALL -w 30 -h 20 -nonsym

    but it ‘s performance is too bad

  37. How to use cascade.xml generated by opencv_traincascade. If we use directly give following error..
    OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /build/buildd/opencv-2.1.0/src/cxcore/cxpersistence.cpp, line 4720
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /build/buildd/opencv-2.1.0/src/cxcore/cxpersistence.cpp:4720: error: (-2) The node does not represent a user object (unknown type?) in function cvRead

    Aborted

  38. Mr. Wilson i have a seminar on this topic can you please give me the point to point explanation of the above program..please its a request..

  39. I thank you for the wonderful post. For my project i have to create xml file for hand detection.

    opencv-createsamples -info positive.txt -vec vecfile.vec -w 64-h 150

    after this step i’m getting the followong error. what is minimum width and height that has to be specified.

    Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x width && rect.y height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in cvSetImageROI, file /home/divyajs/Downloads/OpenCV-2.3.1/modules/core/src/array.cpp, line 3006
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/divyajs/Downloads/OpenCV-2.3.1/modules/core/src/array.cpp:3006: error: (-215) rect.width >= 0 && rect.height >= 0 && rect.x width && rect.y height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0) in function cvSetImageROI

    1. find the minimum height and width in positive.txt file. Use those values in the above command.
      it worked for me hope it does work for you

  40. Hi achu,
    when i am trying to execute final command – convert_cascade –size=”30×32″ data bottle.xml
    it gives following error in linux..

    convert_cascade: command not found
    Please help me….

    1. use ./convert_cascade –size=”30×32″ data bottle.xml and get the convert_cascade code from opencv/samples/c folder….

  41. If i put the name of my classifier,this code (detect.c) can detect the object(in my case it’s a pepsi can)?
    thanks in advance

  42. Amazing work Achu!

    Just wondering, I’m using a c# wrapper for opencv (opencvsharp) – so I’m a little unfamiliar with the commands you are using. If I would want to follow the above post, what complier/software would I execute the commands in?

    Thanks in advance!

    SK

  43. i’m getting the following error . can u please help

    Data dir name: haar
    Vec file name: vecfile.vec
    BG file name: negative.txt, is a vecfile: no
    Num pos: 2000
    Num neg: 2000
    Num stages: 30
    Num splits: 1 (stump as weak classifier)
    Mem: 2000 MB
    Symmetric: TRUE
    Min hit rate: 0.995000
    Max false alarm rate: 0.500000
    Weight trimming: 0.950000
    Equal weights: FALSE
    Mode: BASIC
    Width: 30
    Height: 32
    Applied boosting algorithm: GAB
    Error (valid only for Discrete and Real AdaBoost): misclass
    Max number of splits in tree cascade: 0
    Min number of positive samples per cluster: 500
    Required leaf false alarm rate: 9.31323e-10

    Tree Classifier
    Stage
    +—+
    | 0|
    +—+

    Number of features used : 234720
    OpenCV Error: Unspecified error (Unable to read negative images) in cvCreateTreeCascadeClassifier, file /home/divyajs/Downloads/OpenCV-2.3.1/modules/haartraining/cvhaartraining.cpp, line 2425
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/divyajs/Downloads/OpenCV-2.3.1/modules/haartraining/cvhaartraining.cpp:2425: error: (-2) Unable to read negative images in function cvCreateTreeCascadeClassifier

      1. i am also getting same error……
        is negative and positive image size must be equal??????/
        please help me..
        thnx for this awesome tutotrial.

    1. Hi…even i had the same problem…but later i could resolve it…give npos nneg parameters.. also ur negative desc file name should be proper..jus check with it..

  44. When i try to run this command its getting killed???!!!

    opencv_haartraining -data haar -vec vecfile.vec -bg /home/manoj/Videos/Negative/negative.txt -nstages 30 -mem 2000 -mode all -w 150 -h 80

    Data dir name: haar
    Vec file name: vecfile.vec
    BG file name: /home/manoj/Videos/Negative/negative.txt, is a vecfile: no
    Num pos: 2000
    Num neg: 2000
    Num stages: 30
    Num splits: 1 (stump as weak classifier)
    Mem: 2000 MB
    Symmetric: TRUE
    Min hit rate: 0.995000
    Max false alarm rate: 0.500000
    Weight trimming: 0.950000
    Equal weights: FALSE
    Mode: BASIC
    Width: 150
    Height: 80
    Applied boosting algorithm: GAB
    Error (valid only for Discrete and Real AdaBoost): misclass
    Max number of splits in tree cascade: 0
    Min number of positive samples per cluster: 500
    Required leaf false alarm rate: 9.31323e-10

    Tree Classifier
    Stage
    +—+
    | 0|
    +—+

    Killed

    1. same here!!!
      invalid background description file
      tell me exactly what to include in background file
      and whether it should be .txt or .dat file
      plz reply
      thanks in advance

  45. Object Marker: Input Directory: raw/data/directory Output File: devin1.txt
    Opening directory…done.
    Examining file .
    Loading image raw/data/directory.
    Failed to load image, raw/data/directory.
    Examining file ..
    Loading image raw/data/directory…
    Failed to load image, raw/data/directory…
    Examining file image0.bmp
    Loading image raw/data/directory…image0.bmp
    Failed to load image, raw/data/directory…image0.bmp
    Examining file output_info.txt
    Loading image raw/data/directory…image0.bmpoutput_info.txt
    Failed to load image, raw/data/directory…image0.bmpoutput_info.txt
    Examining file Thumbs.db
    Loading image raw/data/directory…image0.bmpoutput_info.txtThumbs.db
    Failed to load image, raw/data/directory…image0.bmpoutput_info.txtThumbs.db

    the object marker fails and cannot load the image
    how to fix it?
    thanks for your help

  46. This is really help, just what i was looking for. A question though, do i put any information in the description file when i run objectmarker or something? i ran everything but when i open the output file it is empty.

  47. Nice tutorial …. but what about “B” key it is not working in the objectmarker ,,and so the data is not saved in the output file !!!!

      1. It is using the key capital ‘B’ not lowercase ‘b’. If you change all references to the key number ’66’ to another number (e.g. 98 for lowercase ‘b’) then it will change the key used for that function.

    1. It is called just in an OpenCV way – see the initial lines:

      cvNamedWindow(window_name,1);
      cvSetMouseCallback(window_name,on_mouse, NULL);

      This creates the window, and sets the mouse callback function to on_mouse

  48. You should take a look at opencv_traincascade.exe which has better support for multi-core processing, and runs much much faster than opencv-haartraining.exe

  49. Hello

    When i run the above code of detect.c, then debug was successful but then error occur in command prompt “Assertion failed: cascade && storage && capture, file: , line 22
    The Application has requested the run time to terminate it in an unusual way. Please contact the applications support team for more information”

    Please help me to resolve this error.

    Thanks in advance

    1. It looks like you are not loading your cascade XML file:

      char *filename = “bottle.xml”; //put the name of your classifier here

      cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );

      Have you loaded up your xml file instead of the default ‘bottle.xml’ which will not exist with the project?

  50. Thanks for shairing this document.

    How ever I can’t use “object marker”. I compile it and try to use it from cmd on win7. Just I see such a things and finishes.

    Examining file img (6).jpeg
    Loading image img (6).jpeg
    Examining file img (6).JPG
    Loading image img (6).JPG
    Examining file img (7).jpeg
    Loading image img (7).jpeg
    Examining file img (7).jpg
    Loading image img (7).jpg
    Examining file img (8).jpeg
    Loading image img (8).jpeg
    Examining file img (8).jpg
    Loading image img (8).jpg
    Examining file img (9).jpeg
    Loading image img (9).jpeg
    Examining file img (9).jpg
    Loading image img (9).jpg
    Examining file img 1.jpeg
    Loading image img 1.jpeg

    How can I use ObjectMarker effectively?
    Thanks for your help.

    1. The ObjectMarker is trying to load those images from the relative directory of the project. You can try modifying the following to load the absolute path of the images:

      Change:

      strPrefix=dir_entry_p->d_name;

      To:

      strPrefix=input_directory.append(dir_entry_p->d_name);

      Assuming you have set the input_directory to be the correct location of your images, it will load the images from the absolute path instead of the relative path to the project.

      1. I am also having the same problem as Sadik above when I compile the code through terminal in Linux, this is what i get:

        Loading image simon9.jpg
        Examining file mmanson9.jpg
        Loading image mmanson9.jpg
        Examining file mmanson4.jpg
        Loading image mmanson4.jpg
        Examining file lisa10.jpg
        Loading image lisa10.jpg
        Examining file marie6.jpg
        Loading image marie6.jpg
        Examining file chris1.jpg
        Loading image chris1.jpg
        Examining file mmanson2.jpg
        Loading image mmanson2.jpg
        Examining file iroy10.jpg

        I then made the change that was mentioned above by replacing a line of code with strPrefix=input_directory.append(dir_entry_p->d_name);

        When I done this, i got:

        peter9.jpgamellanby3.jpgamellanby13.jpgolive2.jpgmartin13.jpgian1.jpgdhawley1.jpglisa4.jpgamellanby17.jpgpeter8.jpgandrew!22.jpggfindley2.jpgdavid6.jpggraeme17a.jpgmichael18.jpghin1.jpgmartin5.jpgpeter6.jpgirene2.jpgmartin8.jpgdavid2.jpgdhands11.jpggraeme4.jpgdpearson1.jpgiroy14.jpgpeter1.jpgdave_faquhar1.jpgjohn_thom1.jpglisa9.jpgpaul11.jpggordon4.jpgkirsty11.jpgcatherine18.jpghack.jpgpat18.jpgtock12.jpgian10.jpgtock11.jpgmartin1.jpgmarie12.jpgdlow17.jpgdlow18.jpgian9.jpgdhands8.jpgtock7.jpgpat10.jpgjim14.jpgneilg.jpgkim18a.jpgdpearson2.jpgmmanson6.jpgamellanby8.jpgpeter10.jpgdpearson14.jpgandrew5.jpgpaul4.jpgandrew13.jpgdavid13.jpgcatherine6.jpgandrew7.jpgtracy14.jpggeorge1.jpgkieran2.jpgstephen5.jpgkirsty3.jpgmichael1.jpgkim3.jpgamellanby12.jpgmnicholson2.jpgalister1.jpgcatherine5.jpgsimon11.jpgkieran4.jpgpat6.jpgdavid_imray1.jpgmarie13.jpgkay8.jpgkay1.jpgstephen7.jpgiroy11.jpgmilly4.jpglisa5.jpgbfegan16a.jpgstephen13.jpgkirsty9.jpgkay15.jpgbarry8.jpgjenni12.jpgchris3.jpgdlow7.jpgsimon5.jpg

        How can I get this to work?
        Any help would be greatly appreciated

    2. You have to change:

      strPrefix=dir_entry_p->d_name;

      to:
      strPrefix=input_directory+dir_entry_p->d_name;

      For me it works. Good luck

      1. After this, I m unable to load the Image. It shows…

        Opening directory…done.
        Examining file .
        Loading image /home/shree/positive/.
        Examining file ..
        Loading image /home/shree/positive/..
        Examining file image9.jpeg
        Loading image /home/shree/positive/image9.jpeg
        Failed to load image, /home/shree/positive/image9.jpeg
        Examining file image11.jpeg
        Loading image /home/shree/positive/image11.jpeg
        Failed to load image, /home/shree/positive/image11.jpeg
        Examining file image8.jpeg
        Loading image /home/shree/positive/image8.jpeg
        Failed to load image, /home/shree/positive/image8.jpeg
        Examining file image7.jpeg
        Loading image /home/shree/positive/image7.jpeg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s