“
Github开源人脸识别项目face_recognition
译者注:
本项目face_recognition是一个强大、简单、易上手的人脸识别开源项目,并且配备了完整的开发文档和应用案例,特别是兼容树莓派系统。为了便于中国开发者研究学习人脸识别、贡献代码,我将本项目README文件翻译成中文。向本项目的所有贡献者致敬。
”
face-recognition这个开源项目,大家可以去github上找找,有很多的demo可以拿来用,比如用knn或者调用webcam视频来进行识别。然后我这边用的是face_recognition_knn这个demo来进行的。
整个demo有训练,预测,以及结果展示三个部分:
首先是train
def train(train_dir, model_save_path=None, n_neighbors=None, knn_algo='ball_tree', verbose=False):
"""
Trains a k-nearest neighbors classifier for face recognition.
:param train_dir: directory that contains a sub-directory for each known person, with its name.
(View in source code to see train_dir example tree structure)
Structure:
<train_dir>/
├── <person1>/
│ ├── <somename1>.jpeg
│ ├── <somename2>.jpeg
│ ├── ...
├── <person2>/
│ ├── <somename1>.jpeg
│ └── <somename2>.jpeg
└── ...
:param model_save_path: (optional) path to save model on disk
:param n_neighbors: (optional) number of neighbors to weigh in classification. Chosen automatically if not specified
:param knn_algo: (optional) underlying data structure to support knn.default is ball_tree
:param verbose: verbosity of training
:return: returns knn classifier that was trained on the given data.
"""
X = []
y = []
# Loop through each person in the training set
for class_dir in o