文件名称:人脸识别程序,运用python软件
文件大小:6.41MB
文件格式:RAR
更新时间:2021-07-14 09:36:40
RAR
import face_recognition as fr import pickle import os from face_recognition.face_recognition_cli import image_files_in_folder as ifi from sklearn.neighbors import KNeighborsClassifier as knc """ face_encodings() 3. 对给定的图片中的每一张人脸, 返回128-dimension人脸编码. X 4. :param face_image: 包含一张或多张人脸之图片(一个numpy数组) 5. :param known_face_locations: 可选 - 已经认识的每张脸的bounding boxes. 6. :param num_jitters: 计算编码时,re-sample的次数. 其值越高, 越精确, 但更慢 (i.e. 100 is 100x slower) 7. :return: 128-dimensional人脸编码的列表(对图片中每一张脸都会生成这样一个列表) """ def train(train_dir, knn_clf = 'face.clf'): X = [] y = [] # 遍历训练集中的每一个人 for class_dir in os.listdir(train_dir): if not os.path.isdir(os.path.join(train_dir, class_dir)): continue # 结束当前循环, 进入下一个循环 # 遍历这个人的每一张照片 for img_path in ifi(os.path.join(train_dir, class_dir)): image = fr.load_image_file(img_path) boxes = fr.face_locations(image) dim = fr.face_encodings(image,known_face_locations=boxes,num_jitters=3) X.append(dim[0])