许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  人脸Landmark提取方法(68点/关键点检测)

人脸Landmark提取方法(68点/关键点检测)

阅读数 1
点赞 0
article_banner

背景和理论

计算机处理人脸,先要找到face在哪。怎么找?就是检测landmark。landmark是什么意思呢?就是在脸上绘制的若干标记点,标记点一般画在边、角、轮廓、交叉、等分等关键位置,借助它们就可以描述人脸的形态(shape).

       现在常用的开源landmark检测工具是dlib,其 开源模型 中的landmark包含68个点,按顺序来说: 0-16是下颌线(红),17-21是右眼眉(橙),22-26是左眼眉(黄),27-35是鼻子(浅绿),36-41是右眼(深绿),42-47是左眼(浅蓝),48-60是嘴外轮廓(深蓝),61-67是嘴内轮廓(紫)。

那么dlib是如何做到的呢?算法是基于histogram of oriented gradients ( HOG  ) 和linear classifier,论文是这篇:One Millisecond Face Alignment with an Ensemble of Regression Trees by# Vahid Kazemi and Josephine Sullivan, CVPR 2014, 以后会研究一下。其开源model(shape_predictor_68_face_landmarks)是用300w的图片库训练的( iBUG 300-W face landmark dataset),直接拿来用就是了。

安装包

pip install opencv-python
pip install dlib
pip install imutils

dlib有 python 的封装,所以用起来非常简单。shape_predictor_68_face_landmarks.dat是模型,可以直接下载(http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2),get_facial_landmarks函数返回一个68*2的numpy array就是landmark了。

整体代码

import dlib
# import face_utils
import cv2
import numpy as np
from imutils import face_utils
from pathlib import Path
import os

here = os.path.dirname(os.path.abspath(__file__))
print(here)

predictor_path = os.path.join(here, 'shape_predictor_68_face_landmarks.dat')
print(predictor_path)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)

def get_facial_landmarks(image):
    # detect face(s)
    dets = detector(image, 1)
    shape = np.empty([1,1])
    for k, d in enumerate(dets):
        # Get the landmarks/parts for the face in box d.
        shape = predictor(image, d)
        # 遍历所有点
        for pt in shape.parts():
            # 绘制特征点
            pt_pos = (pt.x, pt.y)
            cv2.circle(img, pt_pos, 1, (255,0, 0), 2)

        shape = face_utils.shape_to_np(shape)
    return shape

img = cv2.imread(os.path.join(here, 'abama.jpg'))
landmarks = get_facial_landmarks(img)
print(landmarks.shape, landmarks)

cv2.imwrite(os.path.join(here, 'abama_landmark.jpg'), img)
# cv2.imshow('opencv_face_laowang',img)  # 显示图片
# cv2.waitKey(0) # 等待用户关闭图片窗口
# cv2.destroyAllWindows()# 关闭窗口

效果



参考:https://www.jianshu.com/p/122dbbde0ccf

   https://blog.csdn.net/qq_44431690/article/details/106573853


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空