如果你使用Python3.4或更新的版本,可以传入 --cpus <number_of_cpu_cores_to_use> 参数:
- $ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/
(你可以传入 --cpus -1参数来调用cpu的所有核心。)此外,子豪兄Tommy 表示树莓派3B有4个CPU核心,传入多核参数可以显著提升图片识别的速度。
更多案例
如果你并不在乎图片的文件名,只想知道文件夹中的图片里有谁,可以用这个管道命令:
- $ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ | cut -d ',' -f2
- Barack Obama
- unknown_person
2.使用Python
在 Python 中导入 face_recognition模块,调用丰富的API接口,用几行代码就可以轻松玩转各种人脸识别功能!API 接口文档:
https://face-recognition.readthedocs.io
如何定位人脸位置或者识别人脸身份?
在 Python 中可以分别通过以下代码来实现在图片中定位人脸的位置
- import face_recognition
- image = face_recognition.load_image_file("my_picture.jpg")
- face_locations = face_recognition.face_locations(image)
- # face_locations is now an array listing the co-ordinates of each face
参考案例:
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py
在图片中识别人脸身份
- import face_recognition
- picture_of_me = face_recognition.load_image_file("me.jpg")
- my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
- # my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!
- unknown_picture = face_recognition.load_image_file("unknown.jpg")
- unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
- # Now we can see the two face encodings are of the same person with `compare_faces`!
- results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
- if results[0] == True:
- print("It's a picture of me!")
- else:
- print("It's not a picture of
参考案例:
https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py
对人脸识别有精准要求怎么办? (编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|