【问题标题】:std::algorithm Read access violationstd::algorithm 读取访问冲突
【发布时间】:2019-09-17 05:00:21
【问题描述】:

我在 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
}

我已经解释了详细信息,但在算法中访问读取内存时出现错误。

照片:

【问题讨论】:

  • mc您遇到了什么错误?请发布minimal reproducible example 重现问题。
  • 如果可以选择,请始终使用文本,因为它更具可读性、可进一步处理、一般可访问。

标签: c++ opencv face-detection


【解决方案1】:

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

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

这应该是&lt; 而不是&lt;=,否则在最后一次迭代中,i 的值将超出范围。

【讨论】:

  • 我认为除非循环体中确实需要i,否则它应该是for (auto&amp;&amp; face : faces) { … }
  • @Deduplicator 是的,增强的 for 循环非常棒,因为它们定义了一个错误。
  • 但是如果我删除 for (auto&& face : faces) { ... } 或其他循环,它也会给我错误。
  • 和 for (auto&& face : faces) { ... } 它也不起作用
  • 不知道怎么解决。它说它在 opencv_world310d.dll
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多