環(huán)境:mac 虛擬機(jī)centos7
安裝:
1灭返、opencv-python
pip install opencv-python
2肾扰、dlib
pip install dlib
注:依賴cmake、gcc、gcc-c++模塊
yum install cmake
代碼:
#coding=utf-8
import cv2
import dlib
path = "131.jpg"
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#人臉?lè)诸惼?/p>
detector = dlib.get_frontal_face_detector()
# 獲取人臉檢測(cè)器
predictor = dlib.shape_predictor(
? ? "shape_predictor_68_face_landmarks.dat"
)
dets = detector(gray, 1)
for face in dets:
? ? shape = predictor(img, face)? # 尋找人臉的68個(gè)標(biāo)定點(diǎn)
? ? # 遍歷所有點(diǎn),打印出其坐標(biāo)蚂蕴,并圈出來(lái)
? ? for pt in shape.parts():
? ? ? ? pt_pos = (pt.x, pt.y)
? ? ? ? cv2.circle(img, pt_pos, 2, (0, 255, 0), 1)
? ? cv2.imshow("image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
結(jié)果:
參考文檔:
http://www.cnblogs.com/vipstone/p/8964656.html