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

python使用dlib進(jìn)行人臉檢測(cè)和關(guān)鍵點(diǎn)的示例

 更新時(shí)間:2020年12月05日 10:15:52   作者:dangxusheng  
這篇文章主要介紹了python使用dlib進(jìn)行人臉檢測(cè)和關(guān)鍵點(diǎn)的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
#!/usr/bin/env python
# -*- coding:utf-8-*-
# file: {NAME}.py
# @author: jory.d
# @contact: dangxusheng163@163.com
# @time: 2020/04/10 19:42
# @desc: 使用dlib進(jìn)行人臉檢測(cè)和人臉關(guān)鍵點(diǎn)

import cv2
import numpy as np
import glob
import dlib

FACE_DETECT_PATH = '/home/build/dlib-v19.18/data/mmod_human_face_detector.dat'
FACE_LANDMAKR_5_PATH = '/home/build/dlib-v19.18/data/shape_predictor_5_face_landmarks.dat'
FACE_LANDMAKR_68_PATH = '/home/build/dlib-v19.18/data/shape_predictor_68_face_landmarks.dat'


def face_detect():
  root = '/media/dangxs/E/Project/DataSet/VGG Face Dataset/vgg_face_dataset/vgg_face_dataset/vgg_face_dataset'
  imgs = glob.glob(root + '/**/*.jpg', recursive=True)
  assert len(imgs) > 0

  detector = dlib.get_frontal_face_detector()
  predictor = dlib.shape_predictor(FACE_LANDMAKR_68_PATH)
  for f in imgs:
    img = cv2.imread(f)
    # The 1 in the second argument indicates that we should upsample the image
    # 1 time. This will make everything bigger and allow us to detect more
    # faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))
    for i, d in enumerate(dets):
      x1, y1, x2, y2 = d.left(), d.top(), d.right(), d.bottom()
      print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
        i, x1, y1, x2, y2))

      cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 1)

      # Get the landmarks/parts for the face in box d.
      shape = predictor(img, d)
      print("Part 0: {}, Part 1: {} ...".format(shape.part(0), shape.part(1)))
      # # Draw the face landmarks on the screen.
      '''
      # landmark 順序: 外輪廓 - 左眉毛 - 右眉毛 - 鼻子 - 左眼 - 右眼 - 嘴巴
      '''
      for i in range(shape.num_parts):
        x, y = shape.part(i).x, shape.part(i).y
        cv2.circle(img, (x, y), 2, (0, 0, 255), 1)
        cv2.putText(img, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX, 0.3, (0, 0, 255), 1)

    cv2.resize(img, dsize=None, dst=img, fx=2, fy=2)
    cv2.imshow('w', img)
    cv2.waitKey(0)


def face_detect_mask():
  root = '/media/dangxs/E/Project/DataSet/VGG Face Dataset/vgg_face_dataset/vgg_face_dataset/vgg_face_dataset'
  imgs = glob.glob(root + '/**/*.jpg', recursive=True)
  assert len(imgs) > 0

  detector = dlib.get_frontal_face_detector()
  predictor = dlib.shape_predictor(FACE_LANDMAKR_68_PATH)
  for f in imgs:
    img = cv2.imread(f)
    # The 1 in the second argument indicates that we should upsample the image
    # 1 time. This will make everything bigger and allow us to detect more
    # faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))
    for i, d in enumerate(dets):
      x1, y1, x2, y2 = d.left(), d.top(), d.right(), d.bottom()
      print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
        i, x1, y1, x2, y2))

      cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 1)

      # Get the landmarks/parts for the face in box d.
      shape = predictor(img, d)
      print("Part 0: {}, Part 1: {} ...".format(shape.part(0), shape.part(1)))
      # # Draw the face landmarks on the screen.
      '''
      # landmark 順序: 外輪廓 - 左眉毛 - 右眉毛 - 鼻子 - 左眼 - 右眼 - 嘴巴
      '''
      points = []
      for i in range(shape.num_parts):
        x, y = shape.part(i).x, shape.part(i).y
        if i < 26:
          points.append([x, y])
        # cv2.circle(img, (x, y), 2, (0, 0, 255), 1)
        # cv2.putText(img, str(i), (x,y),cv2.FONT_HERSHEY_COMPLEX, 0.3 ,(0,0,255),1)

      # 只把臉切出來(lái)
      points[17:] = points[17:][::-1]
      points = np.asarray(points, np.int32).reshape(-1, 1, 2)
      img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      black_img = np.zeros_like(img)
      cv2.polylines(black_img, [points], 1, 255)
      cv2.fillPoly(black_img, [points], (1, 1, 1))
      mask = black_img
      masked_bgr = img * mask

      # 位運(yùn)算時(shí)需要轉(zhuǎn)化成灰度圖像
      mask_gray = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
      masked_gray = cv2.bitwise_and(img_gray, img_gray, mask=mask_gray)

    cv2.resize(img, dsize=None, dst=img, fx=2, fy=2)
    cv2.imshow('w', img)
    cv2.imshow('mask', mask)
    cv2.imshow('mask2', masked_gray)
    cv2.imshow('mask3', masked_bgr)
    cv2.waitKey(0)


if __name__ == '__main__':
  face_detect()

以上就是python使用dlib進(jìn)行人臉檢測(cè)和關(guān)鍵點(diǎn)的示例的詳細(xì)內(nèi)容,更多關(guān)于python 人臉檢測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python實(shí)現(xiàn)刪除列表中滿足一定條件的元素示例

    Python實(shí)現(xiàn)刪除列表中滿足一定條件的元素示例

    這篇文章主要介紹了Python實(shí)現(xiàn)刪除列表中滿足一定條件的元素,結(jié)合具體實(shí)例形式對(duì)比分析了Python針對(duì)列表元素的遍歷、復(fù)制、刪除等相關(guān)操作技巧,需要的朋友可以參考下
    2017-06-06
  • 盤點(diǎn)總結(jié)Python爬蟲(chóng)常用庫(kù)(附官方文檔)

    盤點(diǎn)總結(jié)Python爬蟲(chóng)常用庫(kù)(附官方文檔)

    在信息時(shí)代,數(shù)據(jù)是無(wú)處不在的寶藏,從網(wǎng)頁(yè)內(nèi)容、社交媒體帖子到在線商店的產(chǎn)品信息,互聯(lián)網(wǎng)上存在著大量的數(shù)據(jù)等待被收集和分析,Python爬蟲(chóng)是一種強(qiáng)大的工具,用于從互聯(lián)網(wǎng)上獲取和提取數(shù)據(jù)
    2023-11-11
  • Python?Jinja2?庫(kù)靈活性廣泛性應(yīng)用場(chǎng)景實(shí)例解析

    Python?Jinja2?庫(kù)靈活性廣泛性應(yīng)用場(chǎng)景實(shí)例解析

    Jinja2,作為Python中最流行的模板引擎之一,為開(kāi)發(fā)者提供了強(qiáng)大的工具,用于在Web應(yīng)用和其他項(xiàng)目中生成動(dòng)態(tài)內(nèi)容,本文將深入研究?Jinja2?庫(kù)的各個(gè)方面,提供更豐富的示例代碼,能夠充分理解其靈活性和廣泛應(yīng)用的場(chǎng)景
    2024-01-01
  • pydev debugger: process 10341 is connecting無(wú)法debu的解決

    pydev debugger: process 10341 is co

    這篇文章主要介紹了pydev debugger: process 10341 is connecting無(wú)法debu的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Python生成短uuid的方法實(shí)例詳解

    Python生成短uuid的方法實(shí)例詳解

    python的uuid都是32位的,比較長(zhǎng),處理起來(lái)效率比較低。這篇文章主要介紹了Python生成短uuid的方法,需要的朋友可以參考下
    2018-05-05
  • python讀取圖片的幾種方式及圖像寬和高的存儲(chǔ)順序

    python讀取圖片的幾種方式及圖像寬和高的存儲(chǔ)順序

    這篇文章主要介紹了python讀取圖片的幾種方式及圖像寬和高的存儲(chǔ)順序,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • 在Python下進(jìn)行UDP網(wǎng)絡(luò)編程的教程

    在Python下進(jìn)行UDP網(wǎng)絡(luò)編程的教程

    這篇文章主要介紹了在Python下進(jìn)行UDP網(wǎng)絡(luò)編程的教程,UDP編程是Python網(wǎng)絡(luò)編程部分的基礎(chǔ)知識(shí),示例代碼基于Python2.x版本,需要的朋友可以參考下
    2015-04-04
  • Pycharm激活碼激活兩種快速方式(附最新激活碼和插件)

    Pycharm激活碼激活兩種快速方式(附最新激活碼和插件)

    這篇文章主要介紹了Pycharm兩種快速激活方式(附最新激活碼和插件) ,本文給大家分享兩種方式,小編在文章給大家推薦方法二,大家可以根據(jù)自己需要選擇,感興趣的朋友跟隨小編一起看看吧
    2020-03-03
  • python 常見(jiàn)的反爬蟲(chóng)策略

    python 常見(jiàn)的反爬蟲(chóng)策略

    這篇文章主要介紹了python反爬蟲(chóng)策略,幫助大家更好的理解和使用python 爬蟲(chóng),感興趣的朋友可以了解下
    2020-09-09
  • PyTorch實(shí)現(xiàn)線性回歸詳細(xì)過(guò)程

    PyTorch實(shí)現(xiàn)線性回歸詳細(xì)過(guò)程

    本文介紹PyTorch實(shí)現(xiàn)線性回歸,線性關(guān)系是一種非常簡(jiǎn)單的變量之間的關(guān)系,因變量和自變量在線性關(guān)系的情況下,可以使用線性回歸算法對(duì)一個(gè)或多個(gè)因變量和自變量間的線性關(guān)系進(jìn)行建模,該模型的系數(shù)可以用最小二乘法進(jìn)行求解,需要的朋友可以參考一下
    2022-03-03

最新評(píng)論

西乡县| 新昌县| 昆山市| 天峻县| 泊头市| 平谷区| 池州市| 乌拉特中旗| 梁山县| 石柱| 疏勒县| 阜新| 贞丰县| 乐业县| 呼玛县| 平凉市| 金乡县| 出国| 鄂州市| 盐津县| 新野县| 西安市| 景德镇市| 新乡县| 聂荣县| 商都县| 枣阳市| 彭阳县| 鄂尔多斯市| 萨嘎县| 沭阳县| 高州市| 丹凤县| 曲周县| 页游| 礼泉县| 八宿县| 二手房| 西吉县| 芒康县| 金沙县|