我使用 dlib
库成功地对一张图片进行了嘴部特征的遮盖(masked)。
masked
类似地,我有另一张未经过遮盖的嘴唇裁剪图像(colorlip)。
colorlip
我已经按比例缩放并替换了这些图像 (replaced),并使用如下代码中的 np.where
函数。
replaced
#Get the values of the lip and the target mask
lip = pred_toblackscreen[bbox_lip[0]:bbox_lip[1], bbox_lip[2]:bbox_lip[3],:]
target = roi[bbox_mask[0]:bbox_mask[1], bbox_mask[2]:bbox_mask[3],:]
cv2.namedWindow('masked', cv2.WINDOW_NORMAL)
cv2.imshow('masked', target)
#Resize the lip to be the same scale/shape as the mask
lip_h, lip_w, _ = lip.shape
target_h, target_w, _ = target.shape
fy = target_h / lip_h
fx = target_w / lip_w
scaled_lip = cv2.resize(lip,(0,0),fx=fx,fy=fy)
cv2.namedWindow('colorlip', cv2.WINDOW_NORMAL)
cv2.imshow('colorlip', scaled_lip)
update = np.where(target==[0,0,0],scaled_lip,target)
cv2.namedWindow('replaced', cv2.WINDOW_NORMAL)
cv2.imshow('replaced', update)
但是'colorlip'中的特征形状(唇)与'masked'图像不匹配,因此存在错位,使得掩模的边缘看起来锐利,就好像图像被叠加了一样。如何解决这个问题?并且如何使最终替换的图像看起来更加细腻和正常?