3

The function below returns crashes with failed assertion at return of the function. This only occurs in visual studiol; when I run it in linux with cmake, everything works great. The issue occurs in both debug and assertion mode.

I am using Visual Studio 2015 with OpenCV 3.1.0. The OpenCV files are included correctly I'm sure because the program doesn't crash at the OpenCV functions.

function:

void detectFace(Mat frame, Scalar &face_colour) {
    printf("1\n");
    vector<Rect> faces;
    Mat frame_gray;
    Scalar main_face_colour;
    printf("2\n");

    cvtColor(frame, frame_gray, CV_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);
    printf("3\n");

    Rect main_face = Rect(0, 0, 0, 0);  // hold the main face to be recognized

    // Detect faces using the cascade
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80));
    printf("4\n");

    for (size_t i = 0; i < faces.size(); i++) {
        printf("5\n");
        if (faces[i].width * faces[i].height > main_face.width * main_face.height) {
            main_face.x = faces[i].x;
            main_face.y = faces[i].y;
            main_face.width = faces[i].width;
            main_face.height = faces[i].height;
        }
        printf("6\n");

        rectangle(frame, Point(faces[i].x, faces[i].y), Point(faces[i].x + faces[i].width, faces[i].y + faces[i].height), Scalar(229, 181, 51), 4);
        printf("7\n");
    }

    //int col = frame.at<int>(main_face.x + main_face.width / 2, main_face.y + main_face.height / 2);  // TODO: Average the colour of the pixels in the face region
        //toColour(col, face_colour);
    printf("8\n");
    main_face_colour = mean(frame(main_face));

    circle(frame, Point(main_face.x + main_face.width / 2, main_face.y + main_face.height / 2), 4, face_colour, 4);

    printf("9\n");
    if (main_face != Rect(0, 0, 0, 0))  // Send to mask maker
        //makeMesh(frame(main_face), main_face);
    printf("10\n");
    rectangle(frame, main_face, main_face_colour, 5);  // Indicate main face

    showUserId(frame, main_face_colour, faces.size());
    //cout << face_colour << endl;
    printf("11\n");
}

Assertion Message:

Debug Assertion Failed!

Program: ...\Documents\GitHub\Face Recognition\Debug\Face Recognition.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 892

Expression: is_block_type_valid(header->_block_use)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

Update:

The error is occuring because of the face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80)); line.

DSchana
  • 968
  • 3
  • 13
  • 28
  • WHICH ASSERTION failed? Post the whole message please... – Micka Apr 18 '17 at 21:09
  • @Micka Yea sorry, forgot to add that, I made an edit to the question. – DSchana Apr 18 '17 at 21:12
  • did you link against release libs in debug build, or vice versa? – Micka Apr 18 '17 at 21:14
  • I believe so, I have setup some property sheets that link all the external DLLs. – DSchana Apr 18 '17 at 21:36
  • no I meant, are you building in release mode or in debug mode? And are you linking the right libraries (*d.lib in debug mode and without d in release mode)? If you link the wrong ones, your heap gets corrupted at some unexpected locations. – Micka Apr 18 '17 at 22:31
  • I tried in both debug and release with the correct dlls. Both break. After a bit of testing, I've narrowed the issue to the detecMultiscale line. Indicated by the update. – DSchana Apr 18 '17 at 23:14
  • did you check all of these suggestions? http://stackoverflow.com/q/34760254/2393191 – Micka Apr 18 '17 at 23:22
  • can you check the size of ypur input image? Afaik there's a bug if the image size is close to your chosen minSize of detected faces. – Micka Apr 18 '17 at 23:33
  • my input image is of size 640x 480. I also tried to set the min size to 0x0. Still same result. – DSchana Apr 19 '17 at 00:03

0 Answers0