欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3利用Dlib19.7實(shí)現(xiàn)人臉68個(gè)特征點(diǎn)標(biāo)定

 更新時(shí)間:2018年02月26日 14:05:55   作者:TimeStamp  
這篇文章主要為大家詳細(xì)介紹了python3利用Dlib19.7實(shí)現(xiàn)人臉68個(gè)特征點(diǎn)標(biāo)定,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

0.引言

利用Dlib官方訓(xùn)練好的模型“shape_predictor_68_face_landmarks.dat”進(jìn)行68點(diǎn)標(biāo)定,利用OpenCv進(jìn)行圖像化處理,在人臉上畫出68個(gè)點(diǎn),并標(biāo)明序號(hào);

實(shí)現(xiàn)的68個(gè)特征點(diǎn)標(biāo)定功能如下圖所示:

圖1 人臉68個(gè)特征點(diǎn)的標(biāo)定 

1.開發(fā)環(huán)境

  python:3.6.3

  dlib:19.7

  OpenCv, numpy

需要調(diào)用的庫: 

import dlib #人臉識(shí)別的庫dlib
import numpy as np #數(shù)據(jù)處理的庫numpy
import cv2 #圖像處理的庫OpenCv

2.設(shè)計(jì)流程

工作內(nèi)容主要以下兩大塊:68點(diǎn)標(biāo)定OpenCv繪點(diǎn)

68點(diǎn)標(biāo)定:

借助官方的Demo(face_landmark_detection.py,在之前另一篇博客里面介紹過學(xué)習(xí)Python3 Dlib19.7進(jìn)行人臉面部識(shí)別)實(shí)現(xiàn);

OpenCv繪點(diǎn):

介紹了用到的 畫圓函數(shù)cv2.circle() 和 輸出字符串函數(shù) cv2.putText() ;

流程:

  1.調(diào)用dlib庫來進(jìn)行人臉識(shí)別,調(diào)用預(yù)測(cè)器“shape_predictor_68_face_landmarks.dat”進(jìn)行68點(diǎn)標(biāo)定

  2.存入68個(gè)點(diǎn)坐標(biāo)

  3.利用cv2.circle來畫68個(gè)點(diǎn)

  4.利用cv2.putText()函數(shù)來畫數(shù)字1-68

3.源碼

# 68-points
# 2017-12-28
# By TimeStamp
# #cnblogs: http://www.cnblogs.com/AdaminXie/
import dlib      #人臉識(shí)別的庫dlib
import numpy as np    #數(shù)據(jù)處理的庫numpy
import cv2      #圖像處理的庫OpenCv

# dlib預(yù)測(cè)器
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')

path="********************"

# cv2讀取圖像
img=cv2.imread(path+"test.jpg")

# 取灰度
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# 人臉數(shù)rects
rects = detector(img_gray, 0)

for i in range(len(rects)):
 landmarks = np.matrix([[p.x, p.y] for p in predictor(img, rects[i]).parts()])

 for idx, point in enumerate(landmarks):
  # 68點(diǎn)的坐標(biāo)
  pos = (point[0, 0], point[0, 1])

  # 利用cv2.circle給每個(gè)特征點(diǎn)畫一個(gè)圈,共68個(gè)
  cv2.circle(img, pos, 5, color=(0, 255, 0))

  # 利用cv2.putText輸出1-68
  font = cv2.FONT_HERSHEY_SIMPLEX
  cv2.putText(img, str(idx+1), pos, font, 0.8, (0, 0, 255), 1, cv2.LINE_AA)

cv2.namedWindow("img", 2)
cv2.imshow("img", img)
cv2.waitKey(0) 

note:OpenCv的畫圖函數(shù)

         1. 畫圓 cv2.circle( img, (p1,p2), r, (255,255,255) )

    參數(shù)1:  img-          圖片對(duì)象;

    參數(shù)2:  (p1,p2)-          圓心坐標(biāo);

    參數(shù)3:  r-          半徑;

    參數(shù)4:  (255,255,255)-  顏色數(shù)組;  

   2. 輸出字符 cv2.putText( img,"test", (p1,p2), font, 4, (255,255,255), 2, cv2, LINE_AA )

    參數(shù)1:  img-      圖像對(duì)象;

    參數(shù)2:  "test"-      需要打印的字符text(數(shù)字的話可以利用str()轉(zhuǎn)成字符);

    參數(shù)3:  (p1,p2)-      坐標(biāo)textOrg;

    參數(shù)4:  font-      字體fontFace(注意這里 font = cv2.FONT_HERSHEY_SIMPLEX);

    參數(shù)5:  4-       字號(hào)fontScale;

    參數(shù)6:  (255,255,255)-   顏色數(shù)組;

    參數(shù)7:  2-        線寬thickness;

    參數(shù)8:  LINE_AA-      線條種類line_type;

*關(guān)于 顏色數(shù)組:

      (255,255,255), (藍(lán)色,綠色,紅色),每個(gè)值都是0-255;

      比如:藍(lán)色(255,0,0),紫色(255,0,255)    

可以調(diào)整cv2.circle()函數(shù)和cv2.putText()函數(shù)中的 半徑、線寬 等參數(shù)使得輸出滿足需求方便查看;

結(jié)果:

圖2 測(cè)試結(jié)果1 

  

圖3 測(cè)試結(jié)果2

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

相關(guān)文章

最新評(píng)論