1

我创建了一个 haar 级联分类器,用于检测具有 1000 个正图像和 2000 个负图像的手。xml 文件是使用 opencv 示例中的 convert_cascade.c 创建的。现在我使用以下代码进行检测,但是断言语句给出了如下所示的错误“断言失败=级联&&存储&&捕获,第21行”,这是断言调用本身。我知道当表达式计算为零时断言失败。所以,知道分类器可能出了什么问题,因为无论如何存储和捕获都应该可以正常工作,

#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)

{诠释我;

   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 );

}

4

0 回答 0