std::algorithm 读取访问冲突

std::algorithm Read access violation

我正在 opencv/c++ 中使用延迟相机设置人脸检测。我怎样才能做到不出错?

检测我用的是CascadeClassifier.Detectmultiscale.

void detectAndDraw(Mat& img, CascadeClassifier& cascade,

    double scale)
{
    vector<Rect> faces;
    Mat gray;

    cvtColor(img, gray, COLOR_BGR2GRAY); // Convert to Gray Scale 


    // Resize the Grayscale Image  

    equalizeHist(gray, gray);

    // Detect faces of different sizes using cascade classifier  
    cascade.detectMultiScale(gray, faces);

    // Draw circles around the faces 
for(int i = 0; i<=faces.size();i++){
//and cout of x,y,width,height
}

我已经详细说明了,但是我在算法中访问读取内存时遇到错误。

照片:

看起来你在这个循环中有一个差一错误:

for(int i = 0; i <= faces.size(); i++) {
   ...
}

那可能应该是 < 而不是 <=,否则在最后一次迭代中你的 i 值将超出范围。