给我写一个c++函数,传入一个mat,用dlib找出mat中所有人脸的关键点,并存入full_object_detection数组中,该函数的返回值需要为bool,判断是否成功
时间: 2023-02-12 20:28:53 浏览: 99
以下是一个示例代码:
```
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/shape_predictor.h>
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <vector>
using namespace dlib;
using namespace std;
bool detect_face_keypoints(cv::Mat &mat, std::vector<full_object_detection> &keypoints) {
try {
// 加载人脸检测器
frontal_face_detector face_detector = get_frontal_face_detector();
// 加载关键点预测器
shape_predictor shape_predictor;
deserialize("shape_predictor_68_face_landmarks.dat") >> shape_predictor;
// 转换为dlib图像
cv_image<bgr_pixel> cv_img(mat);
// 检测人脸
std::vector<rectangle> faces = face_detector(cv_img);
// 检测关键点
for (auto &face : faces) {
full_object_detection shape = shape_predictor(cv_img, face);
keypoints.push_back(shape);
}
return true;
} catch (exception &e) {
return false;
}
}
```
阅读全文