dlib讀取68個人臉特徵點

2021-10-14 18:23:25 字數 2070 閱讀 8279

可以讀取到人臉上的68個特徵點,可以利用這些特徵點做點有意思的事

# -*- coding: utf-8 -*-

"""created on thu jan 14 16:49:37 2021

@author: yuyanchuan

"""import dlib

import cv2

import os

predictor_path=

'shape_predictor_68_face_landmarks.dat'

detector=dlib.get_frontal_face_detector(

)sp=dlib.shape_predictor(os.path.join(

"f:\code\pythoncode\dlib\shape_predictor_68_face_landmarks"

,predictor_path)

)point_size =

1point_color =(0

,0,255

)# bgr

thickness =

4# 可以為 0 、4、8

cap=cv2.videocapture(0)

while

true

:#ret,frame=cap.read()

frame=cv2.imread(

"gyy1.png"

)#if not cap.isopened():

#print("開啟攝像頭")

dets=detector(frame,1)

img=frame.copy(

)print

(frame.shape)

num_faces=

len(dets)

if num_faces==0:

print

("沒有發現人臉"

) cv2.puttext(frame,

'faces:{}'

.format

(num_faces),(

10,30)

,cv2.font_hershey_plain,2,

(0,0

,255),

2)faces=dlib.full_object_detections(

)for k,d in

enumerate

(dets):)

print

(d.left())

#cv2.rectangle(frame,(d.left(),d.top()),(d.right(),d.bottom()),[0,255,0],3)

shape = sp(frame, d)

for index, pt in

enumerate

(shape.parts())

: pt_pos=

(pt.x,pt.y)

cv2.circle(frame, pt_pos, point_size, point_color, thickness)

#利用cv2.puttext輸出1-68

font = cv2.font_hershey_******x

cv2.puttext(frame,

str(index+1)

,pt_pos,font,

0.3,(0

,0,255),

1, cv2.line_aa)

cv2.puttext(frame,

'press esc quit',(

10,450)

,cv2.font_hershey_plain,2,

(0,0

,255),

2)

cv2.imshow(

'image'

,frame)

if cv2.waitkey(10)

==27

:break

cv2.destroyallwindows(

)

人臉識別Dlib 68個特徵點

前面說了怎麼開啟攝像頭框出人臉,接下來學習了一下人臉的68個特徵點 直接 import dlib import cv2 與人臉檢測相同,使用dlib自帶的frontal face detector作為人臉檢測器 detector dlib.get frontal face detector 使用官方...

基於Dlib庫的人臉68個特徵點檢測

利用dlib.get frontal face detector 獲取人臉框 利用dlib.shape predictor shape predictor 68 face landmarks.dat 獲取人臉68個特徵點 import numpy as np import cv2 import dl...

dlib人臉68特徵點檢測提速 毫秒級

參考文章 把原本低速的dlib人臉檢測換成了高速的haar檢測,提速明顯,但是精度下降 include include include include include include include include include include include include include us...