最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 基于dlib庫的人臉檢測的實現(xiàn)

 更新時間:2019年11月08日 11:30:45   作者:我永遠(yuǎn)不知道我是誰  
這篇文章主要介紹了python 基于dlib庫的人臉檢測的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本周暫時比較清閑,可以保持每日一更的速度。

國外身份證項目新增需求,檢測出身份證正面的人臉。最開始考慮mobilenet-ssd,經(jīng)同事提醒,有現(xiàn)成的人臉庫dlib,那就用傳統(tǒng)方法嘗試一下。

dlib安裝

dlib的安裝小費一波周折,我的python版本是3.6,直接pip install dlib安裝失敗。https://pypi.org/project/dlib/19.6.0/找到python3.6對應(yīng)的whl文件下載安裝或者直接pip install dlib==19.6.0 提示Successfully installed dlib-19.6.0安裝成功。事情沒那么簡單,import dlib時報錯: ImportError: DLL load failed: 找不到指定的模塊。

還是版本的問題,查找最新版本的whl :https://pypi.org/simple/dlib/

下載 dlib-19.8.1-cp36-cp36m-win_amd64.whl  然后cd到相應(yīng)的目錄下 pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl

代碼

import dlib
import cv2
import os
 
def resize(img, width=None, height=None, inter=cv2.INTER_AREA):
  """
  initialize the dimensions of the input image and obtain
  the image size
  """
 
  dim = None
  (h, w) = img.shape[:2]
 
  if width is None and height is None:
    return img
  if width is None:
    r = height / float(h)
    dim = (int(w * r), height)
  else:
    r = width / float(w)
    dim = (width, int(h * r))
  # resize the image
  resized = cv2.resize(img, dim, interpolation=inter)
  # return the resized image
  return resized
 
# 使用 Dlib 的正面人臉檢測器 frontal_face_detector
detector = dlib.get_frontal_face_detector()
 
# 圖片所在路徑
imgs_path = 'test/'
filelist = os.listdir(imgs_path)
# 使用 detector 檢測器來檢測圖像中的人臉
for img_path in filelist:
  img = cv2.imread(imgs_path + img_path)
  img = resize(img, width=512)
  faces = detector(img, 1)
  print("人臉數(shù) / Faces in all: ", len(faces))
  for i, d in enumerate(faces):
    w = d.right() - d.left()
    h = d.bottom() - d.top()
    d_left = int(d.left() - w * 0.25)
    d_right = int(d.right() + w * 0.25)
    d_top = int(d.top() - w * 0.70)
    d_bottom = int(d.bottom() + w * 0.2)
    print("第", i + 1, "個人臉的矩形框坐標(biāo):",
       "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.imshow("img", img)
  cv2.waitKey(0)
  cv2.imwrite('./result.jpg',img)

隨便網(wǎng)上找了張圖測試,效果如下

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

基隆市| 河东区| 石屏县| 贵南县| 志丹县| 无为县| 枝江市| 西乌| 漾濞| 曲水县| 宜丰县| 肥东县| 政和县| 镇赉县| 廊坊市| 玉树县| 刚察县| 三亚市| 微博| 佛教| 白朗县| 元江| 永宁县| 河曲县| 施甸县| 洛阳市| 石家庄市| 会理县| 新化县| 澄迈县| 浮梁县| 老河口市| 梅河口市| 晋宁县| 三穗县| 武强县| 通海县| 西充县| 陆河县| 东乡族自治县| 比如县|