python实现人脸瑕疵检测(斑点,黑头,毛孔,痤疮)

发布时间:2023年12月21日

 该项目基于dlib模块提供的人脸检测器以及关键点定位工具完成。首先通过检测器在图像中定位人脸的位置,然后通过关键点定位工具提取脸部关键点坐标,最后绘制脸部特征点。

dlib关键点定位工具:shape_predictor_81_face_landmarks.dat

根据特征点对各个待检测区域进行划分

import sys
import os
import dlib
import glob
# from skimage import io
import errno
import numpy as np
import cv2
import argparse
#关键点提取
def main():
    args = parse_arguments()
    srcimg = cv2.imread(args.imgpath)
    predictor_path = 'shape_predictor_81_face_landmarks.dat'
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(predictor_path)
    faceMarks=[]
    mouthMarks=[]
    noseMarks=[]
    dets = detector(srcimg)
    for k, d in enumerate(dets):
        shape = predictor(srcimg, d)
        landmarks = np.matrix([[p.x, p.y] for p in shape.parts()])
        faceCouter = [75, 70, 80, 74, 22, 42, 47, 46, 16, 15, 13, 12, 11, 5, 4, 3, 0, 40, 39, 21, 20]
        mouthCouter=[48,49,50,51,52,53,54,55,56,57,58,59,48]
        noseCouter = [27, 31, 35]
        for id1 in faceCouter:
            faceMarks.append(landmarks[id1])
        for id2 in mouthCouter:
            mouthMarks.append(landmarks[id2])
        for id3 in noseCouter:
            noseMarks.append(landmarks[id3])
        mask = np.zeros(srcimg.shape, np.uint8)
        maskf = cv2.polylines(mask, [np.array(faceMarks, dtype=np.int32)], True, (255, 255, 255), 2)  # 画多边形
        maskface = cv2.fillPoly(maskf.copy(), [np.array(faceMarks, dtype=np.int32)], (255, 255, 255))  # 将多边形区域填充白色
        maskface2 = cv2.fillPoly(maskface.copy(),
文章来源:https://blog.csdn.net/wangmengmeng99/article/details/135133269
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。