• winds dlib人脸检测与识别库


       在人脸检测与人脸识别库中dlib库所谓是非常好的了。检测效果非常ok,下面我们来了解一下这个神奇的库吧!

     第一步我们首先学会安装:dlib ,winds+pytho3.6.5  Windows不支持pip在线安装,所以我们直接下载whl文件在使用pip安装就可以了。dlib安装连接,主要注意的是cmake的安装,在Windows使用必须安装cmake进行编译,因为dlib源码是c写的。dlib进行关键点提取和人脸识别的模型见连接,下面来两个小案例把:

    简单人脸检测:

    import dlib
    import cv2
    
    # 使用 Dlib 的正面人脸检测器 frontal_face_detector
    detector = dlib.get_frontal_face_detector()
    
    # 图片所在路径
    # read image
    img = cv2.imread("./img/img_bjn.jpg")
    
    # 使用 detector 检测器来检测图像中的人脸
    # use detector of Dlib to detector faces
    faces = detector(img, 1)
    print("人脸数 / Faces in all: ", len(faces))
    
    # Traversal every face
    for i, d in enumerate(faces):
        print("", i+1, "个人脸的矩形框坐标:",
              "left:", d.left(), "right:", d.right(), "top:", d.top(), "bottom:", d.bottom())
        cv2.rectangle(img, tuple([d.left(), d.top()]), tuple([d.right(), d.bottom()]), (0, 255, 255), 2)
    
    cv2.namedWindow("img", 2)
    cv2.imshow("img", img)
    cv2.waitKey(0)

     特征检测:

    import dlib
    from skimage import io
    import cv2
    
    
    # 使用 Dlib 的正面人脸检测器 frontal_face_detector
    detector = dlib.get_frontal_face_detector()
    
    # Dlib 的 68点模型
    predictor = dlib.shape_predictor("./model/shape_predictor_68_face_landmarks.dat")
    
    # 图片所在路径
    img = io.imread("./img/sn.jpg")
    # img = cv2.imread("./img/sn.jpg")
    img = cv2.resize(img,(1000,600))
    
    # 生成 Dlib 的图像窗口
    win = dlib.image_window()
    win.set_image(img)
    
    # 使用 detector 检测器来检测图像中的人脸
    faces = detector(img,1)
    print("人脸数:", len(faces),[im for im in faces])
    
    for i, d in enumerate(faces):
        print("", i+1, "个人脸的矩形框坐标:",
              "left:", d.left(), "right:", d.right(), "top:", d.top(), "bottom:", d.bottom())
    
        # 使用predictor来计算面部轮廓
        shapes = predictor(img, faces[i])
        # print([i for i in shapes])
        # 绘制面部轮廓
        win.add_overlay(shapes)
    
    # 绘制矩阵轮廓
    win.add_overlay(faces)
    
    # 保持图像
    dlib.hit_enter_to_continue()

  • 相关阅读:
    Codefoces Gym 101652 【最大连续和】
    HYSBZ 4034 【树链剖分】+【线段树 】
    Codeforces Gym 101291C【优先队列】
    Codeforces gym 101291 M (最长交替子序列)【DP】
    HDU 3308 LCIS (经典区间合并)【线段树】
    POJ 3237 Tree (树链剖分+边权转点权)
    POJ 2763 Housewife Wind (树链剖分+边权转点权)
    P1054 等价表达式
    P1107 [BJWC2008]雷涛的小猫
    P1552 [APIO2012]派遣
  • 原文地址:https://www.cnblogs.com/wuzaipei/p/9727120.html
Copyright © 2020-2023  润新知