【发布时间】: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;
}
我正在附上我的错误日志。请任何人帮忙。 提前致谢
【问题讨论】:
-
我似乎在 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时,还请复制粘贴full和complete i> 编译器的错误输出。诸如您显示的错误之类的错误通常还包含信息性消息,这将说明存在哪些可能的替代方案。
-
再次,请向我们展示full错误输出。并告诉我们这个
FaceDetector类是什么(甚至可能向我们展示FaceDetector.h头文件)。请read about how to ask good questions. -
复制粘贴文本作为文本。不要将链接(可能会过时)发布到图像。 然而在那里你可以看到
FaceDetector构造函数所期望的,一个字符串和一些你没有提供的其他值。这就是为什么你得到错误,你没有提供足够的论据。也许您应该花些时间阅读FaceDetector文档?或者至少是它的来源?
标签: c++ opencv face-detection