why the source face detection not work in open cv 3 and VS 2012 [closed]

asked 2015-07-22 06:47:21 -0600

stackprogramer gravatar image

Hello dear friend i configure OpenCv 3 in vs2012 and int it the source work correctly.a show image source image description its work corrcotly,but when i test face detection source it have break image description when it run i have break errors "First-chance exception at 0x770FB727 in opencv.exe: Microsoft C++ exception: cv::Exception at memory location 0x001DF60C.

If there is a handler for this exception, the program may be safely continued"

image description why its happens????????????????!! this source face detection is below

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

void doMosaic(IplImage* in, int x, int y,
              int width, int height, int size);

int main (int argc, char **argv)
    {
    int i, c;
    IplImage *src_img = 0, *src_gray = 0;
    const char *cascade_name = "/opt/local/share/opencv/haarcascades/haarcascade_frontalface_default.xml";
    CvHaarClassifierCascade *cascade = 0;
    CvMemStorage *storage = 0;
    CvSeq *faces;

    cascade = (CvHaarClassifierCascade *) cvLoad (cascade_name, 0, 0, 0);
    cvNamedWindow ("Capture", CV_WINDOW_AUTOSIZE);
    CvCapture *capture = cvCreateCameraCapture(0);
    assert(capture != NULL);

    while (1) {
        src_img = cvQueryFrame (capture);
        src_gray = cvCreateImage (cvGetSize(src_img), IPL_DEPTH_8U, 1);

        storage = cvCreateMemStorage (0);
        cvClearMemStorage (storage);
        cvCvtColor (src_img, src_gray, CV_BGR2GRAY);
        cvEqualizeHist (src_gray, src_gray);

        faces = cvHaarDetectObjects (src_gray, cascade, storage,
            1.11, 4, 0, cvSize (40, 40));
        for (i = 0; i < (faces ? faces->total : 0); i++) {
            CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
            doMosaic(src_img, r->x, r->y, r->width, r->height, 20);
            }

        cvShowImage("Capture", src_img);
        cvReleaseImage(&src_gray);

        c = cvWaitKey (2);
        if (c == '\x1b')
            break;
        }

    cvReleaseCapture (&capture);
    cvDestroyWindow ("Capture");

    return 0;
    }

void doMosaic(IplImage* in, int x0, int y0,
              int width, int height, int size)
    {
    int b, g, r, col, row;

    int xMin = size*(int)floor((double)x0/size);
    int yMin = size*(int)floor((double)y0/size);
    int xMax = size*(int)ceil((double)(x0+width)/size);
    int yMax = size*(int)ceil((double)(y0+height)/size);

    for(int y=yMin; y<yMax; y+=size){
        for(int x=xMin; x<xMax; x+=size){
            b = g = r = 0;
            for(int i=0; i<size; i++){
                if( y+i > in->height ){
                    break;
                    }
                row = i;
                for(int j=0; j<size; j++){
                    if( x+j > in->width ){
                        break;
                        }
                    b += (unsigned char)in->imageData[in->widthStep*(y+i)+(x+j)*3];
                    g += (unsigned char)in->imageData[in->widthStep*(y+i)+(x+j)*3+1];
                    r += (unsigned char)in->imageData[in->widthStep*(y+i)+(x+j)*3+2];
                    col = j;
                    }
                }
            row++;
            col++;
            for(int i=0;i<row;i++){
                for(int j=0;j<col;j++){
                    in->imageData[in->widthStep*(y+i)+(x+j)*3]   = cvRound((double)b/(row*col));
                    in->imageData[in->widthStep*(y+i)+(x+j)*3+1] = cvRound((double)g/(row*col));
                    in->imageData[in->widthStep*(y+i)+(x+j)*3+2] = cvRound((double)r/(row*col));
                    }
                }
            }
        }
    }
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-19 16:28:08.451519

Comments

1

no idea, where you found that code, but it is outdated, and you must not use it.

if you see IplImages* anywhere, - move on, and try to find a fresher example.

please start all over again with the objdetect tutorial

and then - please, next time - no screenshots ! (they' useless, take a lot of bandwith, and we still can't see anything there)

berak gravatar imageberak ( 2015-07-22 07:18:58 -0600 )edit

i find this c

stackprogramer gravatar imagestackprogramer ( 2015-07-22 08:07:16 -0600 )edit

yes, your code is using opencv's no more maintained c-api. they moved away from using that half a decade ago, and so should you !

berak gravatar imageberak ( 2015-07-22 08:11:04 -0600 )edit

apart from that, - "/opt/local/share/opencv/haarcascades/haarcascade_frontalface_default.xml" probably does not exist on your windows box.

  • do not just copy and paste code without understanding any of it
  • if you want to try out things, - start here
berak gravatar imageberak ( 2015-07-22 09:37:01 -0600 )edit