Assertion failed with fallback with cascade detection OpenCV haar

The function below will fail with a failed assertion on function return. This only happens in the visual studio; when i run it on linux with cmake everything works fine. The problem occurs in both debug mode and assertion mode.

I am using Visual Studio 2015 with OpenCV 3.1.0. OpenCV files are included correctly. I'm pretty sure because the program doesn't crash when working with 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");
}

      

Approval 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 due to the line face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80));

.

+3


source to share





All Articles