人脸识别之face_recognition学习笔记(三)

上一篇文章学习了一些例子,但是这些例子都是其中文版包含的,且并不全面,这里学习一下face_recognition所包含的API,不足之处请指正

五、face_recognition库包含的API

(一)批量图片定位人脸位置

face_recognition.api.batch_face_locations(images, number_of_times_to_upsample=1, batch_size=128)

这个API主要是用来返回一个人脸位置的二维数组,使用的是cnn,并且必须使用GPU,否则不能使用这个API

参数:
images:这是一个照片的list,每一张图片都是numpy array;

number_of_times_to_upsample:上采样多少次来寻找照片中的人脸,这个参数越大,可以寻找越小的人脸;

batch_size:GPU中一次处理的图片数量

(二)人脸之间的比较

face_recognition.api.compare_faces(known_face_encodings, face_encoding_to_check, tolerance=0.6)

这个API是用于比较两个人脸,或者准确地说是拿着一张(未知)的人脸,去和一个list的(已知)人脸进行比较,返回True/False的list

参数:
known_face_encodings:这个是已知人脸的encoding的list;

face_encoding_to_check:这是待检测人脸的encoding;

tolerance:是一个阈值,两张人脸之间的距离小于这个阈值将会被认为是相同的,这个数值越小,检测越是严格;

(三)人脸之间的distence

face_recognition.api.face_distance(face_encodings, face_to_compare)

这个API是用一个list人脸的encoding去和一个参照的人脸的encoding作比较,返回一个list,这个list包含每个人脸比较得出的欧式距离(Returns: A numpy ndarray with the distance for each face in the same order as the ‘faces’ array)

参数:
face_encodings:一个list,包含人脸的encoding;

face_to_compare:一个参照人脸的encoding;

(四)face_encodings

face_recognition.api.face_encodings(face_image, known_face_locations=None, num_jitters=1, model='small')

这个API,对照片中的每一张人脸生成一个128维的encoding

参数:
face_image:一张包含一张或者多张人脸的图片;

known_face_locations:这是一个可选参数,如果你已经知道一张人脸的边框,可以使用;

num_jitters:计算encoding时候,进行多少次重采样,这个数值越高,越是精确,但是速度会变慢;

model:这是一个可选参数,默认是“large”,当使用“small”时候可以更快地生成结果;

(五)面部特征位置

face_recognition.api.face_landmarks(face_image, face_locations=None, model='large')

这个API,针对图片中每一张人脸,生成关键特征点的位置(如眼睛,鼻子,嘴)

参数:
face_image:需要进行检测的图片;

face_locations:这是一个可选参数,如果已知人脸的位置,可以使用;

model:这是一个可选参数,默认是“large”,当使用“small”时候可以更快地生成结果;

(六)人脸位置

face_recognition.api.face_locations(img, number_of_times_to_upsample=1, model='hog')

这个API返回照片中人脸的位置【A list of tuples of found face locations in css (top, right, bottom, left) order】

参数:

img:一张numpy array形式的图片;

number_of_times_to_upsample:上采样多少次来寻找照片中的人脸,这个参数越大,可以寻找越小的人脸;

model:使用哪种检测模型,“hog”不精确但是在CPU上速度快,“cnn”是一种更加精确的深度学习模型,如果有GPU可以加速,默认是前者;

(七)加载图片

face_recognition.api.load_image_file(file, mode='RGB')

这个API可以加载图片(如.jpg),变成一个numpy array

参数:
file:图片文件夹的名字;

mode:将图片转换成什么样的格式,“RGB”是三通道彩色图片,“L”是单通道黑白图片

发布了23 篇原创文章 · 获赞 0 · 访问量 671

猜你喜欢

转载自blog.csdn.net/forever_008/article/details/103641059
今日推荐