文章目录

  • 概述
  • 关键点检测实现方法
    • 实现步骤
    • 代码示例
    • 效果实例
  • 关键类与接口方法
    • 概述
    • 关键点检测类: `dlib.shape_predictor`
    • 检测结果类 : `dlib.full_object_detection`
    • 关键点类:`dlib.point` `dlib.points`

概述

dlib支持检测人脸特征关键点,官方提供了68维度和5维度的人脸关键店检测预训练模型提供下载使用。

关键点检测实现方法

实现步骤

  1. 加载图片,进行人脸区域的检测 (包含人脸检测模型创建等)
  2. 传入图片和人脸检测结果,获取人脸换关键点数据(包含face landmark模型创建等)
  3. 解析人脸关键点数据

相关数据与模型文件下载:地址
CNN人脸检测模型名称 :mmod_human_face_detector.dat.bz2
68维人脸检测模型名称 : shape_predictor_68_face_landmarks.dat.bz2
5维人脸检测模型名称 :shape_predictor_5_face_landmarks.dat.bz2

代码示例

本实例中,使用CNN人脸检测模型和68维人脸关键点检测模型

import dlib
import numpy as npfrom cv2 import cv2# step 1. create the face detector and shape predictor 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. process face detection
# note that the difference between the image data formated as numpy.ndarray read by dlib and cv2 is that dlib read it channels as *R G B* order while cv2 read as *B G R*,so you should do one more step to convert the image if using cv2
image_path = "sample.jpg"
img = dlib.load_rgb_image(image_path)
# img = cv2.cvtColor(cv2.imread(image_path),cv2.COLOR_BGR2RGB)
detections = face_detector(img, 1)  # dlib.mmod_rectangles# step 3. get shape of one face for example
detection = detections[0]  # dlib.mmod_rectangle
# the mmod_rectangle contains two parts : confidence and rectshape = face_shape_predictor(img, detection.rect)  # dlib.full_object_detectionstep 4. get all the face landmark pointslandmark_points = shape.parts() # dlib.points

效果实例

将所有的68维度人脸特征关键点连接之后的效果图如下所示

关键点的顺序与对应面部位置:

关键类与接口方法

概述

  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关键点列表

关键点检测类: dlib.shape_predictor

class dlib.shape_predictorThis object is a tool that takes in an image region containing some object and outputs a set of point locations that define the pose of the object. The classic example of this is human face pose prediction, where you take an image of a human face as input and are expected to identify the locations of important facial landmarks such as the corners of the mouth and eyes, tip of the nose, and so forth.__call__(self: dlib.shape_predictor, image: array, box: dlib.rectangle) → dlib.full_object_detectionrequiresimage is a numpy ndarray containing either an 8bit grayscale or RGB image.box is the bounding box to begin the shape prediction inside.ensuresThis function runs the shape predictor on the input image and returns a single full_object_detection.__init__(*args, **kwargs)Overloaded function.__init__(self: dlib.shape_predictor) -> None__init__(self: dlib.shape_predictor, arg0: unicode) -> NoneLoads a shape_predictor from a file that contains the output of the train_shape_predictor() routine.save(self: dlib.shape_predictor, predictor_output_filename: unicode) → NoneSave a shape_predictor to the provided path.

检测结果类 : dlib.full_object_detection

class dlib.full_object_detectionThis object represents the location of an object in an image along with the positions of each of its constituent parts.__init__(self: dlib.full_object_detection, rect: dlib.rectangle, parts: object) → Nonerequiresrect: dlib rectangleparts: list of dlib.point, or a dlib.points object.num_partsThe number of parts of the object.part(self: dlib.full_object_detection, idx: int) → dlib.pointA single part of the object as a dlib point.parts(self: dlib.full_object_detection) → dlib.pointsA vector of dlib points representing all of the parts.rectBounding box from the underlying detector. Parts can be outside box if appropriate.

关键点类:dlib.point dlib.points

class dlib.pointThis object represents a single point of integer coordinates that maps directly to a dlib::point.__init__(*args, **kwargs)Overloaded function.__init__(self: dlib.point, x: int, y: int) -> None__init__(self: dlib.point, p: dlib::vector<double, 2l>) -> None__init__(self: dlib.point, v: numpy.ndarray[int64]) -> None__init__(self: dlib.point, v: numpy.ndarray[float32]) -> None__init__(self: dlib.point, v: numpy.ndarray[float64]) -> Nonenormalize(self: dlib.point) → dlib::vector<double, 2l>Returns a unit normalized copy of this vector.xThe x-coordinate of the point.yThe y-coordinate of the point.
class dlib.pointsAn array of point objects.__init__(*args, **kwargs)Overloaded function.__init__(self: dlib.points) -> None__init__(self: dlib.points, arg0: dlib.points) -> NoneCopy constructor__init__(self: dlib.points, arg0: iterable) -> None__init__(self: dlib.points, initial_size: int) -> Noneappend(self: dlib.points, x: dlib.point) → NoneAdd an item to the end of the listclear(self: dlib.points) → Nonecount(self: dlib.points, x: dlib.point) → intReturn the number of times x appears in the listextend(*args, **kwargs)Overloaded function.extend(self: dlib.points, L: dlib.points) -> NoneExtend the list by appending all the items in the given listextend(self: dlib.points, arg0: list) -> Noneinsert(self: dlib.points, i: int, x: dlib.point) → NoneInsert an item at a given position.pop(*args, **kwargs)Overloaded function.pop(self: dlib.points) -> dlib.pointRemove and return the last itempop(self: dlib.points, i: int) -> dlib.pointRemove and return the item at index iremove(self: dlib.points, x: dlib.point) → NoneRemove the first item from the list whose value is x. It is an error if there is no such item.resize(self: dlib.points, arg0: int) → None

dlib实现人脸关键点检测检测方法相关推荐

  1. 基于Python,dlib实现人脸关键点检测

    @代码实现及安装过程 基于Python,dlib实现人脸关键点检测 dilb 在做人脸检测人脸识别方面用到比较多的.face_recognition就是基于dlib实现的. 这篇文章将使用Python ...

  2. python 实现81个人脸关键点实时检测

    python 实现81个人脸关键点实时检测 文章目录: 一.81个关键点介绍 二.81 个关键点的使用 该库也是基于dlib实现的,还有face_recognition也同样是基于dlib来实现的 d ...

  3. Dlib库中实现正脸人脸关键点(landmark)检测的测试代码

    Dlib库中提供了正脸人脸关键点检测的接口,这里参考dlib/examples/face_landmark_detection_ex.cpp中的代码,通过调用Dlib中的接口,实现正脸人脸关键点检测的 ...

  4. OpenCV基于dlib进行人脸关键点检测(摄像头)

    1. dlib.get_frontal_face_detector()获取人脸检测器 2. dlib.shape_predictor()预测人脸关键点 人脸关键点模型,下载地址: http://dli ...

  5. dlib实现人脸识别+活体检测

    目录: 一:dlib的shape_predictor_68_face_landmarks模型 二.眨眼检测 三.张口检测 四.眨眼检测+张口检测 五.人脸识别 六.人脸识别+活体检测 七.人脸识别破解 ...

  6. 【Opencv】基于dlib的人脸关键点检测和闭眼检测

    关键点定位 #导入工具包 from collections import OrderedDict import numpy as np import argparse import dlib impo ...

  7. 人脸关键点检测综述(含论文、数据集、方法等)

    人脸关键点 人脸关键点检测是人脸识别和分析领域中的关键一步,它是诸如自动人脸识别.表情分析.三维人脸重建及三维动画等其它人脸相关问题的前提和突破口.近些年来,深度学习(http://www.rainc ...

  8. dlib库包的介绍与使用,opencv+dlib检测人脸框、opencv+dlib进行人脸68关键点检测,opencv+dlib实现人脸识别,dlib进行人脸特征聚类、dlib视频目标跟踪

    文章目录: 1 dlib库介绍 2 dlib人脸检测:绘制出人脸检测框 2.1 dlib人脸检测源码 2.2 opencv + dlib 人脸检测 2.3 dlib人脸检测总结 3 dlib人脸关键点 ...

  9. 【机器学习】 - 使用dlib进行人脸定位,人脸检测,给人脸图片戴口罩

    detector = dlib.get_frontal_face_detector() 功能:人脸检测画框 参数:无 返回值:默认的人脸检测器 faces = detector(img_gray, 0 ...

  10. 基于人脸关键点检测的驾驶员睡意检测系统

    摘要 驾驶员注意力不集中或者分心是道路交通事故的主要原因. 为了减少道路交通事故,设计开发驾驶员疲劳检测系统至关重要. 本研究利用人脸关键点检测方法提出了驾驶员睡意检测系统,目的是使驾驶更安全. 一. ...

最新文章

  1. 降低预测过程计算成本,这些NLP模型压缩方法要知道
  2. Windows Phone本地数据库(SQLCE):11、使用LINQ查询数据库(翻译) (转)
  3. 京东小程序上线,剑指何方?
  4. hdu 1881 毕业bg
  5. wxWidgets:wxProcess类用法
  6. matlab 实现 stacked Autoencoder 解决图像分类问题
  7. 设计模式之Builder (创建者模式)的一些个人理解(转)
  8. 机票分享第一篇 机票由何而来
  9. android随机抽奖代码_用Excel实现不放回随机抽样
  10. 利用NABCD模型进行竞争性需求分析
  11. jeecg导出Excel
  12. js-showModalDialog和dialogArguments
  13. html颜色代码错误,HTML颜色代码表
  14. Chrome调试工具使用及waterfall含义详解
  15. 技巧分享:简单的流程图怎么作?
  16. ASPICE_SWE.1_01_01_QA
  17. 虚函数与纯虚函数以及虚函数表之间的关系
  18. 基于过程的软件测试全景图 (2)
  19. postgresql 随笔
  20. 项目规划中的Epic、Feature、Story和Task的关系

热门文章

  1. 忆亚强建筑预算软件的2001年半年时光
  2. 计算机无法连接打印机主机,打印机无法连接电脑问题的处理方法
  3. MAC系统级鼠标手势功能软件BetterAndBetter
  4. 音乐节拍自动标记插件 BeatEdit
  5. DelayQueue延时队列操作实例
  6. 爬虫实战:遇上gb2312编码的网页
  7. 计算机分区硬盘有写保护,如何去掉磁盘写保护实测方法
  8. Java 汉字转拼音(完美支持解决多音字)
  9. 数据分析之描述性统计分析
  10. 计算机关机怎么按,按什么键电脑关机