人生第一次写博客,有错误的地方,给我回复下 , 话不多说,直接上代码
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
//#include<opencv2/photo.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include<facedetect-dll.h>
#include"ColorT.h"
#include<vector>
dlib::shape_predictor sp;
int detectctFace(cv::Mat &mat, std::vector<cv::Point> &point) //使用的是于仕琪老师的人脸检测
{
dlib::full_object_detection shape1;
cv::Mat mat1, gra;
mat.copyTo(mat1);
cv::cvtColor(mat1, gra, CV_BGR2GRAY);
int * pResults = NULL;
unsigned char * pBuffer = (unsigned char *)malloc(0x20000);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.\n");
return -1;
}
pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gra.ptr(0)), gra.cols, gra.rows, (int)gra.step, 1.15f, 5, 15, 0, 0);
std::vector<cv::Point>().swap(point);
point.clear();
if (*pResults > 0)
{
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
dlib::rectangle det;
short * p = ((short*)(pResults + 1)) + 142 * i;
int x = p[0];
int y = p[1];
int w = p[2];
int h = p[3];
if (w > 0 && h > 0 && x + w < gra.cols&&y + h < gra.rows)
{
det.set_top(y);
det.set_left(x);
det.set_bottom(y + h);
det.set_right(x + w);
dlib::cv_image<dlib::bgr_pixel>