1

I have created a haar cascade classifier for detecting a hand with 1000 positive images and 2000 negative images. The xml file was created using convert_cascade.c from opencv samples. Now I am using the following code for detection, but the assert statement is giving an error as shown below "assertion failed= cascade && storage && capture, line 21", which is the assertion call itself. I know that assertion fails when the expression evaluates to zero. so, any idea what could be wrong with classifier, because storage and capture should be working fine anyways,

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

CvHaarClassifierCascade *cascade;
CvMemStorage            *storage;

void detect( IplImage *img );

int main(  )
{
    CvCapture *capture;
    IplImage  *frame;
    int       key;
    char      *filename = "haar3.xml"; // name of my classifier 

    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( 24,24), // ------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 );

}

ria15
  • 55
  • 1
  • 5
  • make sure the file path is correct. also there may be a pointer-wise problem about assertion, as you are creating pointers but checking for their datas. – baci Jul 12 '13 at 06:48
  • I have placed the file in the debug folder itself, so no path error. Can you please elaborate on pointer wise problem? – ria15 Jul 12 '13 at 07:31
  • On the second thought, I might be wrong. Pointers point an address, like DF3A, FF12, ... You are using logical OR operator (&&) so if those are not NULL, then assertion shouldn't fail. Are you sure one them is not NULL ? Debug and see? – baci Jul 12 '13 at 07:57
  • some related stuff: http://stackoverflow.com/questions/5635887/unable-to-load-the-haarcascadeshaarcascade-xml-in-opencv, http://stackoverflow.com/questions/7158039/opencv-cvhaarclassifiercascade-cvload-doesnt-load-unable-to-load-xml-file – baci Jul 12 '13 at 08:00
  • None of them are null. But the code is working now, I removed the assertion statement and the memory release statements. Thanks. – ria15 Jul 18 '13 at 11:35

0 Answers0