1、加载一张原图,并识别人脸的68个特征点
cv::Mat img = cv::imread("5.jpg");
// 人脸68特征点的识别函数
vector<Point2f> points_vec = dectectFace68(img);
// 大眼效果函数
Mat dst0 = on_BigEye(800, img, points_vec);
2、函数
vector<Point2f> dectectFace68(Mat src)
{
vector<Point2f> points_vec;
int* pResults = NULL;
//在检测函数中使用了pBuffer。
//如果你调用多个线程中的函数,请为每个线程创建一个缓冲区!
unsigned char* pBuffer = (unsigned char*)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.\n");
//return 100;
}
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
int doLandmark = 1;// do landmark detection
pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
1.2f, 2, 48, 0, doLandmark);
int cxa = *pResults;
ofstream file("facedata.txt", ios::out);
//打印检测结果
if (0 == cxa)
{
}
else
{
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
short* p = ((short*)(pResults + 1)) + 142 * i;
//rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
{
char c[8];
_itoa(j, c, 10);
Point2f ff(p[