zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    转 linux下vi命令大全
    转 html5 canvas 详细使用教程
    怎么让手机网站自适应设备屏幕宽度? 转自百度经验
    转 :<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 的说明
    转自haorooms :网页防止黑客跨框架攻击,及浏览器安全性想到的
    元信息标记<meta>
    Java语言的主要特性
    学习面向对象的三条主线之一 java类及类的成员
    1.5 MySQL信息源
    1.4在MySQL 8.0中添加,不建议使用或删除的服务器和状态变量及选项
  • 原文地址:https://www.cnblogs.com/wuzaipei/p/9727120.html
Copyright © 2011-2022 走看看