zoukankan      html  css  js  c++  java
  • Python DLib库进行人脸关键点识别

    人脸识别之Python DLib库进行人脸关键点识别

    安装dlib模块

    pip install dlib -i https://pypi.doubanio.com/simple

    人脸检测

    首先调用dlib.get_frontal_face_detector() 来加载dlib自带的人脸检测器
    dets = detector(img, 1)将检测器应用在输入图片上,结果返回给dets(参数1表示对图片进行上采样一次,有利于检测到更多的人脸);
    dets的个数即为检测到的人脸的个数;
    遍历dets可以获取到检测到的每个人脸四个坐标极值。

    import dlib
    import cv2
    
    def rect_to_bb(rect): # 获得人脸矩形的坐标信息
        x = rect.left()
        y = rect.top()
        w = rect.right() - x
        h = rect.bottom() - y
        return (x, y, w, h)
    def detect(imgPath):
        detector = dlib.get_frontal_face_detector() # 加载dlib自带的人脸检测器
        image = cv2.imread(imgPath) # 读取图片
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # 将图片转化为灰度值图像
        rects = detector(gray, 1) # 将检测器应用在输入图片
        for (i, rect) in enumerate(rects):#遍历获得坐标
            (x, y, w, h) = rect_to_bb(rect)
            cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) # 绘画矩形框
            cv2.putText(image, "Face", (x - 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 写入文字
        cv2.imshow("Output", image)
        cv2.waitKey(0)
    if __name__ == '__main__':
        detect("1.jpg")
    
  • 相关阅读:
    t=20点击发送pingback
    Hibernate 序列生成主键
    oracle创建存储过程
    mysql允许某ip访问
    ORACLE用户解锁
    oracle查询锁表
    oracle杀掉执行的死循环存储过程
    oracle以逗号分隔查询结果列表
    查询oracle的session数
    oracle存储过程-获取错误信息
  • 原文地址:https://www.cnblogs.com/lyhLive/p/13390286.html
Copyright © 2011-2022 走看看