关于opencv-python:基于OpenCV的人脸视频文字检测以及识别的项目三-人脸轮廓化妆

23次阅读

共计 2256 个字符,预计需要花费 6 分钟才能阅读完成。

1. 装置 face_recognition

这个 face_recognition 是一个很简略的人脸识别库,是在 dlib 框架(蕴含机器学习算法和工具的现代化工具包)上做的整合

第一步装置这俩
pip install Cmake
pip install boost

而后就要装置 dlib Windows 上装置 dlib 容易出问题 能够间接装置 .whl 文件
留神:这个 whl 文件 要跟 python 配套 然而当初这个 whl 文件高版本根本没进去 我前两天装的 python3.11 找不到对应 whl 文件 又从新装的 python3.8 从新配的环境
上面的 对应 3.8 的 dlib..whl 文件
链接:https://pan.baidu.com/s/1g33E…
提取码:xu0f

第二步  装置 whl
到你寄存 whl 文件的文件夹外面  cmd  输出命令
pip install dlib-19.19.0-cp38-cp38-win_amd64.whl
第三步 而后就能够欢快的装置装置 face_recognition 了
pip install face_recognition

而后就可能欢快的写轮廓检测程序了

2. 人脸轮廓检测

# coding=utf-8
# 绘制面部轮廓
import face_recognition
from PIL import Image, ImageDraw

# 将图片文件加载到 numpy 数组中
image = face_recognition.load_image_file("./8.jpg")

# 查找图像中所有面部的所有面部特色
face_landmarks_list = face_recognition.face_landmarks(image)

for face_landmarks in face_landmarks_list:
    facial_features = [
        'chin', 'left_eyebrow', 'right_eyebrow', 'nose_bridge', 'nose_tip',
        'left_eye', 'right_eye', 'top_lip', 'bottom_lip'
    ]
    pil_image = Image.fromarray(image)
    d = ImageDraw.Draw(pil_image)
    for facial_feature in facial_features:
        d.line(face_landmarks[facial_feature], fill=(255, 255, 255), width=3)
    pil_image.show()

这次我大威少能够了 hhhh

三 化妆

间接上代码

# coding=utf-8
# 数字化妆类
import face_recognition
from PIL import Image, ImageDraw

# 加载图片到 numpy array
image = face_recognition.load_image_file("./8.jpg")

# 标识脸部特色
face_landmarks_list = face_recognition.face_landmarks(image)

for face_landmarks in face_landmarks_list:
    pil_image = Image.fromarray(image)
    d = ImageDraw.Draw(pil_image, 'RGBA')

    # 绘制眉毛
    d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
    d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
    d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
    d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)

    # 绘制嘴唇
    d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
    d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
    d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)
    d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)

    # 绘制眼睛
    d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
    d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))

    # 绘制眼线
    d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]],
           fill=(0, 0, 0, 110),
           width=6)
    d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]],
           fill=(0, 0, 0, 110),
           width=6)

    pil_image.show()

xswl hhh 威少的大红唇

代码学习自:
https://github.com/vipstone/f…
https://github.com/vipstone/f…

正文完
 0