使用OpenCV haar级联检测返回时断言失败

时间:2017-04-18 20:52:05

标签: c++ visual-studio opencv assertions

以下函数返回函数返回时失败的断言崩溃。这只发生在视觉研究中;当我使用cmake在linux中运行它时,一切都很好。调试和断言模式都会出现此问题。

我正在使用Visual Studio 2015和OpenCV 3.1.0。正确包含OpenCV文件我确定,因为程序不会在OpenCV函数中崩溃。

功能:

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

断言消息:

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.

更新

由于face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80));行而发生错误。

0 个答案:

没有答案