文章目录

  • 操作步骤
  • 关键类与接口方法定义
    • 方法
  • 示例代码

操作步骤

  1. 人脸检测
  2. 人脸关键点检测
  3. 人脸对齐

关键类与接口方法定义

  1. 人脸检测类 : dlib.fhog_object_detectordlib.cnn_face_detection_model_v1,前者基于HOG模型,后者基于CNN模型,前者检测方法调用为__call(img)__ ->dlib.rectanglesrun(img,upsample_num,threshold)->(dlib.rectangles,List[scores:int],List[int]),后者检测方法调用为__call(img)__->dlib.mmod_rectangles
  2. 关键点检测类: dlib.shape_predictor,预测调用方法__call__(self,image, box: dlib.rectangle)->dlib.full_object_detection
  3. 检测结果类 : dlib.full_object_detection, 常用方法 part(self, idx: int)->dlib.point 单个关键点信息 、parts(self)->dlib.points 所有的关键点信息
  4. 关键点类:dlib.point关键点,成员包含x,y,dlib.points关键点列表

方法

  1. 获取单个人脸对齐结果

    padding参数可调整图像返回值的尺寸大小

get_face_chip(img: numpy.ndarray[(rows,cols,3),uint8], face: _dlib_pybind11.full_object_detection, size: int=150, padding: float=0.25) -> numpy.ndarray[(rows,cols,3),uint8]Takes an image and a full_object_detection that references a face in that image and returns the face as a Numpy array representing the image.  The face will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.
  1. 获取多个人脸对齐结果
get_face_chips(img: numpy.ndarray[(rows,cols,3),uint8], faces: _dlib_pybind11.full_object_detections, size: int=150, padding: float=0.25)->listTakes an image and a full_object_detections object that reference faces in that image and returns the faces as a list of Numpy arrays representing the image.  The faces will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.

示例代码

import dlib
import numpy as npfrom cv2 import cv2# step 1. create face detect and shape predict model
face_detector_model_path = '../models/mmod_human_face_detector.dat'
face_detector = dlib.cnn_face_detection_model_v1(face_detector_model_path)  # dlib.cnn_face_detection_model_v1
shape_model_path = r'../models/shape_predictor_68_face_landmarks.dat'
face_shape_predictor = dlib.shape_predictor(shape_model_path)  # dlib.shape_predictor# step 2. get all face detections
image_path = "sample.jpg"
img = dlib.load_rgb_image(image_path)
detections = face_detector(img, 1)  # dlib.mmod_rectangles# step 3. fetch one of all face detections, and if it's mmod_rectangle , convert to rectabgle
detection = detections[0]  # dlib.mmod_rectangle
# the mmod_rectangle contains two parts : confidence and rect# step 4. get one face shape and return a single object name full_object_detection
shape = face_shape_predictor(img, detection.rect)  # dlib.full_object_detection# step 5. get one aligned face
image = dlib.get_face_chip(img, shape, size=150, padding=0.45) # numpy.ndarray# Optionally: get all the aligned faces that was detected in the first place
faces = [face.rect for face in detections]
# Get the aligned face images
# faces = dlib.full_object_detections()
# faces.append(shape)
# Optionally:
images = dlib.get_face_chips(img, faces, size=160, padding=0.25)

dlib实现人脸对齐方法相关推荐

  1. 一种实时轻量级3D人脸对齐方法

    论文链接: https://xueshu.baidu.com/usercenter/paper/show?paperid=1e090pe0h36k0m002a7q06d0at215203&si ...

  2. dlib实现人脸识别方法

    文章目录 概述 方法实现 实现步骤 示例代码 重载方法 概述 此示例演示如何使用dlib作为人脸识别工具,dlib提供一个方法可将人脸图片数据映射到128维度的空间向量,如果两张图片来源于同一个人,那 ...

  3. dlib实现人脸检测方法

    文章目录 `dlib`概述 人脸检测 CPU版本人脸检测算法 检测步骤 示例代码: CUDA版本人脸检测算法 检测步骤 示例代码 类定义与接口源码 人脸检测中用到的重要的类(概述) `fhog_obj ...

  4. 人脸对齐--Unconstrained Face Alignment without Face Detection

    Unconstrained Face Alignment without Face Detection CVPRW2017 以前人脸对齐主要存在的问题:1)人脸对齐严重依赖于人脸检测来初始化,2)任意 ...

  5. 人脸对齐(二十)--PRN

    Joint3D Face Reconstruction and Dense Alignment with Position Map Regression(PRN2018) 我们从之前的论文可以看出,基 ...

  6. 人脸对齐(十四)--LPFA

    Large-Pose Face Alignment via CNN-Based Dense 3D Model Fitting(LPFA) 作者试图使用3D人脸建模解决大姿态下面部特征点定位问题.其实跟 ...

  7. 人脸对齐(九)--SDM算法

    转自:http://blog.csdn.net/huneng1991/article/details/51901912 http://blog.csdn.net/qq_14845119/article ...

  8. 人脸对齐(五)--ESR算法

    原文:http://www.thinkface.cn/thread-2911-1-2.html 原文翻译我看的好蛋疼,完全机器翻译.甚至怀疑作者是否有通读过一次....这里再修改下. 现在回头看看 ...

  9. 机器学习--详解人脸对齐算法SDM-LBF

    https://www.cnblogs.com/Anita9002/p/7095380.html 引自:http://blog.csdn.net/taily_duan/article/details/ ...

  10. 人脸识别之人脸对齐(一)--定义及作用

    原文: http://www.thinkface.cn/thread-4354-1-1.html http://www.thinkface.cn/thread-4488-1-1.html 人脸对齐 ...

最新文章

  1. Delphi 2009 中 TStrings 与 TStream 的增强
  2. 网站优化之关键词的挖掘准则有哪些?
  3. [翻译] JTCalendar
  4. JQuery对checkbox操作 (循环)
  5. 该文章为递归寻找目录下目标文件(待完善,但是能用)
  6. Redis面试复习大纲在手面试不慌,讲的明明白白!
  7. silverlightLogo动画
  8. SAP License:物料账差异
  9. 5个性能强悍的黑科技APP,请低调收藏,高调使用!
  10. Flink 第8.2章 Flink 的键组 KeyGroup 与 缩放 Rescale
  11. android渠道首发规则,酷传推广手册Android渠道首发规则.doc
  12. redis set设置有效时间问题
  13. JAVA异常:java.lang.AbstractMethodError: ...tomcat.websocket.server.WsSessionListener.sessionCreated
  14. Ubuntu上AMD显卡能够使用的stable diffusion webui部署方案流程
  15. 招聘巨头Monster公司宣布全面收购中华英才网
  16. PHP Array to string conversion
  17. Google谷歌在世界各地的市场占有率
  18. 【openlayer2】清理图层OpenLayers.Layer.WMS
  19. java 修改exif_照片EXIF信息的读取和改写的JAVA实现
  20. Java8新特性 Lambda、Stream、Optional实现原理

热门文章

  1. 波动率模型:现货、期货及期货期权
  2. 企业信用评分卡模型概述
  3. 2.3 sklearn中的metrics.roc_curve评价指标
  4. 冲突域和广播域的理解
  5. 动态链接库劫持--libc
  6. 苹果屏幕镜像_给你们科普一下手机投屏和镜像的区别
  7. GIF工具大全(网站)
  8. 【备忘】最新区块链开发入门到精通视频教程下载
  9. 微信小程序点击事件传递参数
  10. wallhaven怎么下原图_Wallhaven Top高清壁纸抓取工具