使用dlib和opencv 简答的实现一个换脸程序

这篇博客介绍了如何使用dlib和opencv库来实现一个人脸换脸程序。作者首先展示了代码片段,包括人脸检测和特征点检测,然后通过三角剖分和人脸融合函数完成换脸过程。博客中还包括了不同阶段的图像示例,如原始图像、检测到的人脸和最终的融合结果。
摘要由CSDN通过智能技术生成

人生第一次写博客,有错误的地方,给我回复下 , 话不多说,直接上代码

#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>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值