dlib庫是一個人臉中很常用的庫,用於數據預處理階段。
dlib庫的官方網站是:http://dlib.net/
在官網上,我們主要查看兩部分內容,一個是 python api,另一個就是 Python版本的 examples。
舉個我常用的小例子吧,比如要做人臉關鍵點或者屬性,需要把人臉部分提取出來,可以這樣:
import cv2
import dlib
detector = dlib.get_frontal_face_detector()
img = cv2.imread('/home/dddzz/worksapce/datasets/lfw/Aaron_Guiel/Aaron_Guiel_0001.jpg')
dets = detector(img, 1)
for i, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
i, d.left(), d.top(), d.right(), d.bottom()))
這樣可以獲得人臉框的座標。