dlib的人脸地标检测程序中如何获取点坐标位置?

     2023-03-16     16

关键词:

【中文标题】dlib的人脸地标检测程序中如何获取点坐标位置?【英文标题】:How to get points coordinate position in the face landmark detection program of dlib? 【发布时间】:2017-02-09 03:49:36 【问题描述】:

dlib 中有一个示例 python 程序来检测面部标志位置。 face_landmark_detection.py

该程序检测人脸特征,并在原始照片中用点和线表示地标。

我想知道是否可以获取每个点的坐标位置。就像 (10, 25)。 'a' 表示嘴角。

在稍微修改程序一次处理一张图片后,我尝试打印出dets和shape的值,但没有成功。

>>>print(dets)
<dlib.dlib.rectangles object at 0x7f3eb74bf950>
>>>print(dets[0])
[(1005, 563) (1129, 687)]

表示面部标志点的参数和参数的数据类型仍然未知。 这是简化的代码

import dlib
from skimage import io

#shape_predictor_68_face_landmarks.dat is the train dataset in the same directory
predictor_path = "shape_predictor_68_face_landmarks.dat"

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
win = dlib.image_window()

#FDT.jpg is the picture file to be processed in the same directory
img = io.imread("FDT.jpg")

win.set_image(img)

dets = detector(img)

print("Number of faces detected: ".format(len(dets)))
for k, d in enumerate(dets):
    print("Detection : Left:  Top:  Right:  Bottom: ".format(
        k, d.left(), d.top(), d.right(), d.bottom()))
    # Get the landmarks/parts for the face in box d.
    shape = predictor(img, d)
    #print(shape)
    print("Part 0: , Part 1:  ...".format(shape.part(0),
                                              shape.part(1)))
# Draw the face landmarks on the screen.
win.add_overlay(shape)

win.add_overlay(dets)
dlib.hit_enter_to_continue()

---------------2016 年 3 月 10 日更新--------------- ------------

今天想起python中的help()方法,试了一下。

>>>help(predictor)

Help on shape_predictor in module dlib.dlib object:

class shape_predictor(Boost.Python.instance)
 |  This 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.

在原代码中,变量shape是预测器方法的输出。

>>>help(shape)

形状描述

class full_object_detection(Boost.Python.instance)
 |  This object represents the location of an object in an image along 
with the positions of each of its constituent parts.
----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  num_parts
 |      The number of parts of the object.
 |  
 |  rect
 |      The bounding box of the parts.
 |  
 |  ----------------------------------------------------------------------

变量shape似乎与点坐标位置有关。

>>>print(shape.num_parts)
68
>>>print(shape.rect)
[(1005, 563) (1129, 687)]

我假设有 68 个表示人脸标志点。

>>> print(shape.part(68))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: Index out of range
>>> print(shape.part(65))
(1072, 645)
>>> print(shape.part(66))
(1065, 647)
>>> print(shape.part(67))
(1059, 646)

如果是真的。剩下的问题是哪个部分在响应哪个面部标志点。

【问题讨论】:

您可以检测点并在图像上绘制它们的数字。或者你可以看这里matthewearl.github.io/2015/07/28/switching-eds-with-python 哇,这是个好主意。 检查这里,pyimagesearch.com/2017/04/03/… 【参考方案1】:

我稍微修改了代码。

import dlib
import numpy as np
from skimage import io

predictor_path = "shape_predictor_68_face_landmarks.dat"

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)

img = io.imread("FDT.jpg")

dets = detector(img)

#output face landmark points inside retangle
#shape is points datatype
#http://dlib.net/python/#dlib.point
for k, d in enumerate(dets):
    shape = predictor(img, d)

vec = np.empty([68, 2], dtype = int)
for b in range(68):
    vec[b][0] = shape.part(b).x
    vec[b][1] = shape.part(b).y

print(vec)

这是输出

[[1003  575]
 [1005  593]
 [1009  611]
 [1014  627]
 [1021  642]
 [1030  655]
 [1041  667]
 [1054  675]
 [1069  677]
 [1083  673]
 [1095  664]
 [1105  651]
 [1113  636]
 [1120  621]
 [1123  604]
 [1124  585]
 [1124  567]
 [1010  574]
 [1020  570]
 [1031  571]
 [1042  574]
 [1053  578]
 [1070  577]
 [1081  572]
 [1092  568]
 [1104  566]
 [1114  569]
 [1063  589]
 [1063  601]
 [1063  613]
 [1063  624]
 [1050  628]
 [1056  630]
 [1064  632]
 [1071  630]
 [1077  627]
 [1024  587]
 [1032  587]
 [1040  586]
 [1048  588]
 [1040  590]
 [1031  590]
 [1078  587]
 [1085  585]
 [1093  584]
 [1101  584]
 [1094  588]
 [1086  588]
 [1045  644]
 [1052  641]
 [1058  640]
 [1064  641]
 [1070  639]
 [1078  640]
 [1086  641]
 [1080  651]
 [1073  655]
 [1066  656]
 [1059  656]
 [1052  652]
 [1048  645]
 [1059  645]
 [1065  646]
 [1071  644]
 [1083  642]
 [1072  645]
 [1065  647]
 [1059  646]]

还有一个开源项目OpenFace,它基于dlib,描述了face中每个点的相关部分。

The url of describing image

【讨论】:

如何在 dlib 中保存结果人脸地标图像?

】如何在dlib中保存结果人脸地标图像?【英文标题】:Howtosaveresultedfacelandmarkimageindlib?【发布时间】:2016-08-0808:32:47【问题描述】:我正在使用dlib的face_landmark_detection_ex.cpp,它显示检测到的人脸图像和原始图像上的所有人脸地... 查看详情

使用 dlib 检测眼睛地标

...019-04-2007:49:17【问题描述】:使用dlib,是否可以在不进行人脸检测的情况下检测眼睛地标?如果是,如何?如果没有,有什么建议或建议吗?谢谢!Sample【问题讨论】:【参考方案1】:问:是否可以在不进行人脸检测的情况下... 查看详情

使用 Dlib/python 检测前额点

...】:2019-12-0516:27:24【问题描述】:我们有什么方法可以在人脸图像的额头上获取点吗?我正在使用68点地标shape_predictor来获取脸上的其他点,但对于这个特殊问题,我需要从发际线到前额中心的点。任何建议都会有所帮助。【问... 查看详情

使用 dlib 进行人脸地标检测

】使用dlib进行人脸地标检测【英文标题】:Facelandmarksdetectionwithdlib【发布时间】:2021-03-2209:24:19【问题描述】:我有以下代码:image_1=cv2.imread(\'headshot13-14-2.jpg\')image_1_rgb=cv2.cvtColor(image_1,cv2.COLOR_BGR2RGB)image_1_gray=cv2.cvtColor(image_1_r 查看详情

Android 人脸地标裁剪

】Android人脸地标裁剪【英文标题】:FacelandmarkcroppingbyAndroid【发布时间】:2018-05-0818:07:46【问题描述】:我正在尝试检测面部特征并裁剪面部特征区域。我已经使用dlib成功检测了界标区域,下一步是裁剪检测区域,我已经阅读... 查看详情

OpenCV,dlib 地标旋转

...,我不确定我的设计是否正确。我想为android手机编写C++人脸检测器,它应该检测具有不同手机方向和旋转角度的人脸。当手机方向是纵向和横向时,让我们留下来。我正在使用OpenCV旋转/编辑图像和dlib来检测人脸。使用shape_predi 查看详情

人脸识别完整项目实战(14):实时人脸特征点标定程序设计

一、前言本文是《人脸识别完整项目实战》系列博文第14章《实时人脸特征点标定程序设计》,本章内容详细介绍Win10环境下,基于VisualStudio2015+Opencv+Dlib开发环境,如何实现实时视频流人脸特征点标定程序的设计。本文内容已经... 查看详情

给定 dlib 的 68 点面部标志,确定它们有多好

...间】:2018-05-0614:52:48【问题描述】:我正在使用dlib进行人脸检测,然后进行68点面部地标检测。一般来说,这很有效。但是,dlib的人脸检测器有时会检测到(例如)只有一只眼睛可见或人的嘴巴不可见(或在极少数情况下是非... 查看详情

有没有办法在使用 dlib 检测面部标志后选择面部的特定点?

...间】:2021-07-2511:01:18【问题描述】:我正在使用Dlib的68点人脸界标预测器,它有68个点标记在人脸的各个区域,如下图所示:我已经设法从预测的地标中访问特定点,例如,我可以通过以 查看详情

如何在 Dlib C++ 中获取头部姿势估计的 3D 坐标轴

...】:2016-08-0402:00:39【问题描述】:DlibC++可以很好地检测地标和估计面部姿势。但是,如何获得头部姿势的3D坐标轴方向(x,y,z)?【问题讨论】:这个问题已经有一个可接受的答案。尽管如此,为了将来参考,还有一篇关于这个主... 查看详情

在 dlib 中获取检测到人脸的概率[关闭]

】在dlib中获取检测到人脸的概率[关闭]【英文标题】:Gettingprobabilityofdetectedfaceindlib[closed]【发布时间】:2017-11-2217:45:22【问题描述】:我正在使用dlib库(使用python2)在静态图像中进行人脸检测,如果检测到的人脸的概率/质量... 查看详情

地标检测与人脸识别

】地标检测与人脸识别【英文标题】:landmarkdetectionvsfacerecognition【发布时间】:2021-07-2613:37:36【问题描述】:人脸地标检测和人脸识别一样吗?或者它们是两个不同的东西?如果是,它们之间有何不同?任何澄清将不胜感激。... 查看详情

使用 Dlib 进行面部标志检测

...ip安装它。pipinstalldlib会这样做。而this是一个使用dlib提取人脸地标的例子【讨论】: 查看详情

如何检测包括前额在内的面部特征?

...】:2021-08-2109:04:42【问题描述】:This教程教授如何检测人脸的地标。在这里,前额没有标记。我该怎么做才能使地标也检测到前额?【问题讨论】:【参考方案1】:前额不是面部“可靠”的部分,它经常被毛发覆盖。出于同样... 查看详情

带有面部检测和形状预测的 Dlib 网络摄像头捕获速度很慢

...正在开发一个C++程序,该程序应该从网络摄像头流中检测人脸,而不是使用人脸地标裁剪它们并交换它们。我使用OpenCV和Viola-Jones人脸检测对人脸检测进行了编程。工作正常。比我搜索 查看详情

如何在 dlib python 中保存/裁剪检测到的人脸

】如何在dlibpython中保存/裁剪检测到的人脸【英文标题】:howtosave/cropdetectedfacesindlibpython【发布时间】:2017-02-2120:35:18【问题描述】:我想通过裁剪矩形将检测到的人脸保存在dlib中任何人都知道我该如何裁剪它。我第一次使用dli... 查看详情

dlib实现人脸的68点检测

Dlib实现68点标定效果图展示:主要是通过68点的模型进行提取脸部的68点的特征值。(相应细节都已经注释)//设置人脸的标记点#include<dlibopencv.h>#include<opencv2opencv.hpp>#include<dlibimage_processingfrontal_face_detector.h>#include< 查看详情

在android中检测人脸地标点

】在android中检测人脸地标点【英文标题】:Detectingfacelandmarkspointsinandroid【发布时间】:2016-11-2023:57:18【问题描述】:我正在开发应用程序,在该应用程序中,我需要在诸如镜子凸轮或化妆凸轮之类的凸轮上获取面部标志点。我... 查看详情