【问题标题】:error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'错误:没有匹配函数调用'FaceDetector::FaceDetector(std::__cxx11::string)'
【发布时间】:2018-03-10 23:47:53
【问题描述】:

我是 C++ 新手,遇到类似错误

error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'
     FaceDetector fd(string(DEFAULT_CASCADE_PATH));

我附上了我的代码和错误日志如何解决这个问题请指导我

#define DEFAULT_CASCADE_PATH "cascades/haarcascade_frontalface_default.xml"
#define ORIGINALS_LIST "obama_raw/list"
#define OUTPUT_DIR "obama_faces"
#define OUTPUT_LIST "list"
#define FACE_SIZE Size(150,150)
#include <cstdlib>
#include <fstream>
#include "cv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "FaceDetector.h"
using namespace std; 
using namespace cv;

void read_input_list(const string &list_path, vector<Mat> &images) {
    ifstream file(list_path.c_str());
    string path;
    while (getline(file, path)) {
        images.push_back(imread(path));
    }
}

int main(int argc, char** argv) {
    FaceDetector fd(string(DEFAULT_CASCADE_PATH));
    vector<Mat> raw_faces;
    ofstream out_list(format("%s/%s", OUTPUT_DIR, OUTPUT_LIST).c_str());
    read_input_list(string(ORIGINALS_LIST), raw_faces);
    int img_c = 0; //images counter

//now detect the faces in each of the raw images:
    for (vector<Mat>::const_iterator raw_img = raw_faces.begin() ; raw_img != raw_faces.end() ; raw_img++){
        vector<Rect> faces;
        //detect faces in the image (there should be only one):
        fd.findFacesInImage(*raw_img, faces);

        //cut each face and write to disk:
        for (vector<Rect>::const_iterator face = faces.begin() ; face != faces.end() ; face++){
            int edge_size = max(face->width, face->height);
            Rect square(face->x, face->y, edge_size, edge_size);
            Mat face_img = (*raw_img)(square);

            //resize:
            resize(face_img, face_img, FACE_SIZE);

            //write to disk:
            string face_path = format("%s/%d.jpg", OUTPUT_DIR, img_c++);
            imwrite(face_path,face_img);
            out_list << face_path << endl;
        }
    }
    out_list.close();
    return 0;
}

我正在附上我的错误日志。请任何人帮忙。 提前致谢

错误:https://i.stack.imgur.com/RZXXK.jpg

【问题讨论】:

  • 我似乎在 OpenCV 文档中找不到对 FaceDetector 类的任何引用。你是从哪里弄来的?你包括哪些头文件?请编辑您的问题,包括Minimal, Complete, and Verifiable Example
  • 感谢您的宝贵回复,我正在使用头文件#define DEFAULT_CASCADE_PATH "cascades/haarcascade_frontalface_default.xml" #define ORIGINALS_LIST "obama_raw/list" #define OUTPUT_DIR "obama_faces" #define OUTPUT_LIST "list" #define FACE_SIZE Size(150,150) #include #include #include "cv.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "FaceDetector.h "
  • 哦,当您编辑您的问题以包含Minimal, Complete, and Verifiable Example时,还请复制粘贴fullcomplete i> 编译器的错误输出。诸如您显示的错误之类的错误通常还包含信息性消息,这将说明存在哪些可能的替代方案。
  • 再次,向我们展示full错误输出。并告诉我们这个FaceDetector 类是什么(甚至可能向我们展示FaceDetector.h 头文件)。请read about how to ask good questions.
  • 复制粘贴文本作为文本。不要将链接(可能会过时)发布到图像。 然而在那里你可以看到FaceDetector构造函数所期望的,一个字符串一些你没有提供的其他值。这就是为什么你得到错误,你没有提供足够的论据。也许您应该花些时间阅读FaceDetector 文档?或者至少是它的来源?

标签: c++ opencv face-detection


【解决方案1】:

从 GCC 5 开始,默认启用新的 ABI。在那个新的 ABI 中,引入了 std::__cxx11 命名空间。

根据您的错误消息,您要链接的程序和 OpenCV 库似乎是使用不同的 GCC 版本构建的,这导致二进制文件不兼容。

欲了解更多信息,您可以阅读以下页面: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

【讨论】:

  • 这将导致关于“未定义引用”或类似内容的 linker 错误,而不是 OP 的编译器错误。
  • @Someprogrammerdude,我同意你的看法。
  • 我没有收到任何链接器错误,所以这对我来说不是正确的解决方案,但感谢您提供的信息,它在其他时候会有所帮助
猜你喜欢
  • 1970-01-01
  • 2020-07-14
  • 2018-12-05
  • 1970-01-01
  • 2020-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多