【问题标题】:C++ Debug Assertion Failed While Using Opencv使用 Opencv 时 C++ 调试断言失败
【发布时间】:2021-09-28 20:02:58
【问题描述】:

我正在尝试比较两个图像并检查它们是否属于同一个人。此代码给出调试断言失败Like here。我已经检查过了,它可以访问照片。那么有什么问题。人们说您正在尝试访问实际不存在的东西。但是,我在我的代码中找不到任何关于它的信息。 问候;

        #include <iostream>
        #include <string>
        #include "opencv2\core\core.hpp"
        #include "opencv2\core.hpp"
        #include "opencv2\face.hpp"
        #include "opencv2\highgui\highgui.hpp"
       #include "opencv2\objdetect\objdetect.hpp"
        #include "opencv2\opencv.hpp"
        #include<direct.h>
        #include "vector"


      using namespace std;
      using namespace cv;
      using namespace cv::face;

     int main() {
       vector<Mat> img;
       img[0]= imread("C://Users//Gökhan//Desktop//faces//faces442.jpg");
       Mat img2 = imread("C://Users//Gökhan//Desktop//faces//faces448.jpg");
       vector<int> label;
       label[0] = 1;
       Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create();
       model->train(img[0], label[0]);
       int predictedLabel = model->predict(img2);
       if (predictedLabel == 1) {
       cout << "found";
  }

  }

【问题讨论】:

    标签: c++ opencv vector face-recognition


    【解决方案1】:

    您正在尝试访问没有元素的向量的元素。 您必须在访问之前分配元素。 例如,您可以使用构造函数指定要分配的元素数来分配元素。为此,请更改行

    vector<Mat> img;
    vector<int> label;
    

    vector<Mat> img(1);
    vector<int> label(1);
    

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多