对于普通人来说怎么换脸呢?
为了验证效果,小编将应用部署在简捷工具网上,换脸神器:http://www.shulijp.com/image/swapface/swapface.html
看一下效果还是不错滴!
接下来当然是开源代码啦:
def changeface(p1,p2):
record={}
record1={}
record2={}
eye_right, eye_left, mouth1 = get_eye(p1,record,record1,record2)
eye_right2, eye_left2, mouth2 = get_eye(p2,record,record1,record2)
eye_right_resized = cv2.resize(eye_right,(record[p2][2]-record[p2][0],record[p2][3]-record[p2][1]),interpolation=cv2.INTER_AREA)
eye_left_resized = cv2.resize(eye_left, (record1[p2][2] - record1[p2][0], record1[p2][3] - record1[p2][1]),interpolation=cv2.INTER_AREA)
eye_right2_resized = cv2.resize(eye_right2,(record[p1][2]-record[p1][0],record[p1][3]-record[p1][1]),interpolation=cv2.INTER_AREA)
eye_left2_resized = cv2.resize(eye_left2, (record1[p1][2] - record1[p1][0], record1[p1][3] - record1[p1][1]),interpolation=cv2.INTER_AREA)
mouth1_resized = cv2.resize(mouth1,(record2[p2][2]-record2[p2][0],record2[p2][3]-record2[p2][1]),interpolation=cv2.INTER_AREA)
mouth2_resized = cv2.resize(mouth2, (record2[p1][2] - record2[p1][0], record2[p1][3] - record2[p1][1]),interpolation=cv2.INTER_AREA)
im = cv2.imread(p1)
obj = eye_right2_resized
# Create an all white mask
mask = 255 * np.ones(obj.shape, obj.dtype)
center = (int((record[p1][0] + record[p1][2]) / 2), int((record[p1][1] + record[p1][3]) / 2))
# Seamlessly clone src into dst and put the results in output
normal_clone = cv2.seamlessClone(obj, im, mask, center, cv2.NORMAL_CLONE)
im1 = normal_clone
obj1 = eye_left2_resized
# Create an all white mask
mask1 = 255 * np.ones(obj1.shape, obj1.dtype)
center1 = (int((record1[p1][0] + record1[p1][2]) / 2), int((record1[p1][1] + record1[p1][3]) / 2))
# Seamlessly clone src into dst and put the results in output
normal_clone1 = cv2.seamlessClone(obj1, im1, mask1, center1, cv2.NORMAL_CLONE)
im2 = normal_clone1
obj2 = mouth2_resized
mask2 = 255 * np.ones(obj2.shape, obj2.dtype)
center2 = (int((record2[p1][0] + record2[p1][2]) / 2), int((record2[p1][1] + record2[p1][3]) / 2))
normal_clone2 = cv2.seamlessClone(obj2, im2, mask2, center2, cv2.NORMAL_CLONE)
p1 = "".join(p1.split('.')[:-1]) + "_ted.jpg"
cv2.imwrite(p1, normal_clone2)
return p1;
好了以上就是我的分享,有喜欢换脸技术的请 联系我