如何將人臉變漂亮(三)

该篇博客介绍了如何利用Mediapipe库进行人脸检测,并对面部特征进行美容处理,包括高反差保留、曝光度调整、颜色叠加、图像亮度调整和口红涂抹等步骤,以实现人脸美化效果。作者通过代码示例展示了如何获取并处理人脸关键点信息,最终将处理后的人脸重新贴回原图像。
摘要由CSDN通过智能技术生成

利用 mediapipe 進行處理
規劃
1.先把人臉辨識,然後取出框框
2.把框框內的人臉,進行美容
-高反差保留
(1)曝光度調整
(2)綠色與藍色,疊加
(3)YUCIHighPassSkinSmoothingMaskBoost
-調整圖像亮度
-混合
3.把人臉的嘴巴,進行塗紅
4.把人臉的眼睛塗黑

把人臉抓下來處理後,貼回去
如何將人臉變漂亮(一)是針對 mediapipe.solutions.face_detection 劃出框的,因為後面要在畫上 口紅,使人變漂亮,因此 改用 mediapipe.solutions.face_mesh

import cv2
import mediapipe
from numpy import greater
import matplotlib.pyplot as plt

img = cv2.imread("./images/person.jpg")

def landmarksDetection(img, results, draw=False):
    img_height, img_width= img.shape[:2]
    # list[(x,y), (x,y)....]
    mesh_coord = [(int(point.x * img_width), int(point.y * img_height)) for point in results.multi_face_landmarks[0].landmark]
    if draw :
        [cv2.circle(img, p, 2, utils.GREEN, -1) for p in mesh_coord]
    # returning the list of tuples for each landmarks 
    return mesh_coord

def np2pil(numpy_image):
    return Image.fromarray(np.uint8(numpy_image*255.0)).convert('RGB')

mp_face_mesh = mediapipe.solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh(max_num_faces=1,min_detection_confidence=0.5,min_tracking_confidence=0.5)
results = face_mesh.process(img)

if results.multi_face_landmarks:
    for face_landmarks in results.multi_face_landmarks:
        mesh_coords = landmarksDetection(img, results, False)
        print("...:",mesh_coords[10],mesh_coords[152],mesh_coords[234],mesh_coords[454])
  #  img =utils.fillPolyTrans(img, [mesh_coords[10],mesh_coords[152],mesh_coords[234],mesh_coords[454]], utils.RED, opacity=0.7)
    img=cv2.line(img, mesh_coords[10],mesh_coords[152],(255,0,0),10)
    img=cv2.line(img, mesh_coords[234],mesh_coords[454],(255,0,0),10)  
    y=mesh_coords[10][1]    
    h=abs(mesh_coords[10][1]-mesh_coords[152][1])
    yy = y - int(h/4)
    hh = h + int(h/4)
    xx=mesh_coords[234][0]    
    ww=abs(mesh_coords[454][0]-mesh_coords[234][0])
    print("xx:",x,w)    
    print("yy:",y,h,yy,hh)
    cv2.rectangle(img, (xx, yy), (xx + ww, yy + hh), (255, 255, 255), thickness = 5)

plt.figure(figsize=(10,10))
plt.subplot(121)
plt.imshow(img[:,:,::-1])
plt.axis('off')

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值