none
VideoMFC.exe 中的 0x5728a333 处最可能的异常: 0xC00000FD: Stack overflow RRS feed

  • 问题

  • int PeopleDetect(IplImage *src)
    {
    Mat img(src,0); 


    HOGDescriptor hog;

    //这一行出现了错误

    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

    vector<Rect> found, found_filtered;

    hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

    size_t i, j;
    for( i = 0; i < found.size(); i++ )
    {
    Rect r = found[i];
    for( j = 0; j < found.size(); j++ )
    if( j != i && (r & found[j]) == r)
    break;
    if( j == found.size() )
    found_filtered.push_back(r);
    }
    for( i = 0; i < found_filtered.size(); i++ )
    {
    Rect r = found_filtered[i];
    // the HOG detector returns slightly larger rectangles than the real objects.
    // so we slightly shrink the rectangles to get a nicer output.
    r.x += cvRound(r.width*0.1);
    r.width = cvRound(r.width*0.8);
    r.y += cvRound(r.height*0.07);
    r.height = cvRound(r.height*0.8);
    rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
    }
    return 0;
    }

    void  update_mhi_Real( IplImage* img, IplImage* dst, int diff_threshold )
    {
        double timestamp = (double)clock()/CLOCKS_PER_SEC; // get current time in seconds
        CvSize size = cvSize(img->width,img->height); // get current frame size
        int i, idx1 = last, idx2;
        IplImage* silh;
        CvSeq* seq;
        CvRect comp_rect;
        double count;
        double angle;
        //CvPoint center;
        double magnitude;
        CvScalar color;
    CvPoint LeftHigh;
    CvPoint LeftLow;
    CvPoint RightHigh;
    CvPoint RightLow;

        // allocate images at the beginning or
        // reallocate them if the frame size is changed
        if( !mhi || mhi->width != size.width || mhi->height != size.height ) 
    {
            if( buf == 0 ) 
    {
                buf = (IplImage**)malloc(N*sizeof(buf[0]));
                memset( buf, 0, N*sizeof(buf[0]));
            }

            for( i = 0; i < N; i++ ) 
    {
                cvReleaseImage( &buf[i] );
                buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
                cvZero( buf[i] );
            }

            cvReleaseImage( &mhi );
            cvReleaseImage( &orient );
            cvReleaseImage( &segmask );
            cvReleaseImage( &mask );

            mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
            cvZero( mhi ); // clear MHI at the beginning
            orient = cvCreateImage( size, IPL_DEPTH_32F, 1 );
            segmask = cvCreateImage( size, IPL_DEPTH_32F, 1 );
            mask = cvCreateImage( size, IPL_DEPTH_8U, 1 );
        }

        cvCvtColor( img, buf[last], CV_BGR2GRAY ); // convert frame to grayscale

        idx2 = (last + 1) % N; // index of (last - (N-1))th frame
        last = idx2;

        silh = buf[idx2];
        cvAbsDiff( buf[idx1], buf[idx2], silh ); // get difference between frames

        cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ); // and threshold it
        cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); // update MHI

        // convert MHI to blue 8u image
        /*cvCvtScale( mhi, mask, 255./MHI_DURATION,
                    (MHI_DURATION - timestamp)*255./MHI_DURATION );
        cvZero( dst );
        cvMerge( mask, 0, 0, 0, dst );
    */
        // calculate motion gradient orientation and valid orientation mask
        cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 );//3

        if( !storage )
            storage = cvCreateMemStorage(0);
        else
            cvClearMemStorage(storage);

        // segment motion: get sequence of motion components
        // segmask is marked motion components map. It is not used further
        seq = cvSegmentMotion( mhi, segmask, storage, timestamp, MAX_TIME_DELTA );

        // iterate through the motion components,
        // One more iteration (i == -1) corresponds to the whole image (global motion)
        for( i = -1; i < seq->total; i++ ) 
    {

            if( i < 0 ) { // case of the whole image
                comp_rect = cvRect( 0, 0, size.width, size.height );
                color = CV_RGB(255,255,255);
                magnitude = 100;//100
            }
            else { // i-th motion component
                comp_rect = ((CvConnectedComp*)cvGetSeqElem( seq, i ))->rect;
                if( comp_rect.width + comp_rect.height < precision )//100 // reject very small components
                    continue;
                color = CV_RGB(255,0,0);
                magnitude = 30;//30
            }

            // select component ROI
            cvSetImageROI( silh, comp_rect );
            cvSetImageROI( mhi, comp_rect );
            cvSetImageROI( orient, comp_rect );
            cvSetImageROI( mask, comp_rect );

            // calculate orientation
            angle = cvCalcGlobalOrientation( orient, mask, mhi, timestamp, MHI_DURATION);
            angle = 360.0 - angle;  // adjust for images with top-left origin

            count = cvNorm( silh, 0, CV_L1, 0 ); // calculate number of points within silhouette ROI

            cvResetImageROI( mhi );
            cvResetImageROI( orient );
            cvResetImageROI( mask );
            cvResetImageROI( silh );

            // check for the case of little motion
            if( count < comp_rect.width*comp_rect.height * 0.05 )//0.05
                continue;

            // draw a clock with arrow indicating the direction
            //center = cvPoint( (comp_rect.x + comp_rect.width/2),
            //                  (comp_rect.y + comp_rect.height/2) );

    if(0)
    {
    LeftHigh = cvPoint(comp_rect.x,comp_rect.y);
    LeftLow = cvPoint(comp_rect.x,(comp_rect.y+comp_rect.height));
    RightHigh = cvPoint((comp_rect.x+comp_rect.width),comp_rect.y);
    RightLow = cvPoint((comp_rect.x+comp_rect.width),(comp_rect.y+comp_rect.height));

    //Draw rectangle
    cvRectangle( dst,LeftHigh, RightLow, color,1, 8, 0 );

    /*
    cvLine(dst,LeftHigh,LeftLow,color,1,8);
    cvLine(dst,LeftLow,RightLow,color,1,8);
    cvLine(dst,RightLow,RightHigh,color,1,8);
    cvLine(dst,RightHigh,LeftHigh,color,1,8);
    */

    CvFont font;
    double hScale = 1;
    double vScale = 1;
    int lineWidth = 2;

    TCHAR showHuman[] = "Human";
    TCHAR showNotHuman[] = "Not human";

    cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,hScale,vScale,0,lineWidth);

    if(comp_rect.height > comp_rect.width)
    {
    cvPutText(dst,showHuman,RightLow,&font,color);
    }

    if(comp_rect.height < comp_rect.width)
    {
    cvPutText(dst,showNotHuman,RightLow,&font,color);
    }
    }
    if(dst->width < 64 || dst->height < 64)
    {
    continue;
    }
    else
    {
    PeopleDetect(dst);
    }

            //cvCircle( dst, center, cvRound(magnitude*0.5), color, 3, CV_AA, 0 );//1.2
    //cvCircle( dst, center, cvRound(magnitude*0.8), color, 3, CV_AA, 0 );
            //cvLine( dst, center, cvPoint( cvRound( center.x + magnitude*cos(angle*CV_PI/180)),
            //cvRound( center.y - magnitude*sin(angle*CV_PI/180))), color, 3, CV_AA, 0 );
        }
    }

    这是出错的代码

    2013年11月27日 5:34