第一步:编码——将人脸表示为128为的向量
def face_encodings(face_image,known_face_locations=None,num_jitters=1)
"""
return:128维人脸编码向量
param face_image:包含人脸图像
param known_face_locations:是否已知人脸位置
param num_jitters:计算编码时,重新采样的次数
"""
raw_landmarks=_raw_face_landmarks(face_image,known_face_locations,model="small")
return [np.array(face_encoder.compute_face_descriptor(face_image,raw_landmark_set,numjitters)) for raw_landmark_set in raw_landmarks]
1.1 初始人脸标记
def _raw_face_landmarks(face_image, face_locations=None, model="large"):
"""
return:
face_locations: 人脸位置是否已知
model: 两种模式,5特征点(small)和68特征点(large)
"""
if face_locations is None:
face_locations=_raw_face_locations(fa