Ask Your Question

Revision history [back]

Debug assertion failed std::vector crashes on deallocation for CascadeClassifier::detectMultiScale

I am using this function to detect faces:

void FaceDetector::findFacesInImage(const Mat &img, vector<Rect> &res) {
Mat tmp;
int width = img.size().width,
    height = img.size().height;
Size minScaleSize = Size(_minSizeRatio  * width, _minSizeRatio  * height),
    maxScaleSize = Size(_maxSizeRatio  * width, _maxSizeRatio  * height);

//convert the image to grayscale and normalize histogram:
cvtColor(img, tmp, CV_BGR2GRAY);
equalizeHist(tmp, tmp);

//clear the vector:

//detect faces:
_cascade.detectMultiScale(tmp, res, _scaleFactor, _minNeighbors, 0, minScaleSize, maxScaleSize);

And this function is called in the main(), it works perfectly on release mode. However in debug, when the codes finish and calls the destructor for vector<rect> res. It gets a debug assertion error.