使用 OpenCV CascadeClassifier 进行人脸检测:.exe 已触发断点

Face Detection with OpenCV CascadeClassifier: .exe has triggered a breakpoint

我正在尝试编写一个简单的程序,它读取图像、检测图像上的人脸并在图像上用矩形标记人脸。 我使用 Visual Studio 2012 和 OpenCV 2.4.9.

我使用OpenCV提供的cv::CascadeClassifier和haarcascade_frontalface_default.xml。这是我的代码:

#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>  // OpenCV window I/O
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/objdetect/objdetect.hpp>

#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{

    //load image, in this case it's allready gray
    Mat img = imread("H:/BioID/BioID-FaceDatabase-V1.2/BioID_0000.pgm");

    Mat grayImg;   
    cvtColor(img, grayImg, CV_BGR2GRAY);

    //create vector of rectangles that will represent the faces
    vector<Rect> faces;

    CascadeClassifier* faseCascade = new CascadeClassifier("C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml");

    faseCascade->detectMultiScale(grayImg, faces);

    //draw rectangle on img; param: image, rectangle, color
    cv::rectangle(img, faces[0],Scalar(255,0,0),2); 

    //display image
    imshow("image", img);

    waitKey(0);     

    return 0;
}

程序运行正常,最后它向我展示了面部周围有蓝色矩形的图像。但是在我按下一个键并且程序试图关闭之后,它中断了。

输出显示:

HEAP[myProgram.exe]: Invalid address specified to RtlValidateHeap( 00000004F9F30000, 00000004FC23ECE0 )
myProgram.exe has triggered a breakpoint.

如果我把detectMultiscale函数和draw rectangle函数注释掉。程序运行没有错误。

有人知道我做错了什么吗?

感谢您的帮助!

问题是我的环境变量中的 opencv bin 文件夹路径错误。 我最近停止使用 Visual Studio 2010 并开始使用 VS2012 并忘记调整路径。 我不得不将其更改为
C:\opencv\build\x64\vc10\bin;

C:\opencv\build\x64\vc11\bin;
并重新启动计算机。

现在似乎一切正常。