dlib人脸探测

环境:mac 虚拟机centos7


安装:

1、opencv-python

pip install opencv-python

2、dlib

pip install dlib

注:依赖cmake、gcc、gcc-c++模块

yum install cmake

代码:

#coding=utf-8

import cv2

import dlib

path = "131.jpg"

img = cv2.imread(path)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#人脸分类器

detector = dlib.get_frontal_face_detector()

# 获取人脸检测器

predictor = dlib.shape_predictor(

    "shape_predictor_68_face_landmarks.dat"

)

dets = detector(gray, 1)

for face in dets:

    shape = predictor(img, face)  # 寻找人脸的68个标定点

    # 遍历所有点,打印出其坐标,并圈出来

    for pt in shape.parts():

        pt_pos = (pt.x, pt.y)

        cv2.circle(img, pt_pos, 2, (0, 255, 0), 1)

    cv2.imshow("image", img)

cv2.waitKey(0)

cv2.destroyAllWindows()


结果:




参考文档:

http://www.cnblogs.com/vipstone/p/8964656.html

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容