学习笔记 - 面部融合 - 泊松图像编辑

1 换脸难点

(1)人类面部几何形状差异明显,并且存在一些异常值;

(2)光照使得面部肤色色调发生偏移;

(3)头部姿态影响;

(4)皮肤纹理差异。

2 换脸方案

%matplotlib inline
from utils.plot_imgs import *
#from utils.delaunay_triangulation import *
from utils.dlib_face_api import *

import cv2
import glob
import os

2.1 面部对齐

用源图像 g ( x , y ) g(x, y) g(x,y)面部区域覆盖目标图像 f ∗ ( x , y ) f^{\ast}(x, y) f(x,y)面部区域。

# 读取示例图像
filename_src = "./img/ted_cruz.jpg"
filename_dst = "./img/donald_trump.jpg"

img_src = cv2.imread(filename_src)
img_dst = cv2.imread(filename_dst)
img_dst_warped = np.copy(img_dst)

idx_fig = 1
plot_imgs(idx_fig, [img_src, img_dst])

在这里插入图片描述

2.1.1 面部关键点定位

(1)面部关键点定位(68,dlib)

dlib.get_frontal_face_detector()

dlib.shape_predictor()

(2)狄洛尼三角剖分

面部外轮廓关键点(jaw[1 - 17]、right_brow[18 - 22]、left_brow[23 - 27])

# 读取关键点
def read_points(str_file_path):
    
    lst_points = []
    with open(str_file_path) as fr:
        
        for str_line in fr.readlines():
            lst_points.append(
                [int(item) for item in str_line.strip().split(" ")])
            
    return lst_points

# 面部关键点
points_src = read_points(filename_src + ".txt")
points_dst = read_points(filename_dst + ".txt")

2.1.2 凸包

凸包(convex hull):没有凹陷的边界

cv2.convexHull()

# 凸包
hull_pt_src = []
hull_pt_dst = []

hull_pt_indices = cv2.convexHull(np.array(points_dst),
                                 returnPoints = False)
hull_pt_indices = hull_pt_indices.
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值