face_recognition呼吁行器材可以在单张图片或一个图片文件夹中辨认人脸身份。起首,必要一个你已经知道名字的人脸图片文件夹,一小我私人一张图,图片的文件名即为对应的人的名字,然后,必要第二个图片文件夹,文件夹内里是你但愿识此外图片:
然后,在呼吁行中切换到这两个文件夹地址路径,行使 face_recognition 呼吁行,传入这两个图片文件夹,然后就会输出未知图片中人的名字:
- $ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/
- /unknown_pictures/unknown.jpg,Barack Obama
- /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
输出功效的每一行对应着图片中的一张脸,图片名字和对应人脸辨认功效用逗号分隔。
假如功效输出了unknown_person,那么代表这张脸没有对应上已知人脸图片文件夹中的任何一小我私人。
face_detection 呼吁行器材
face_detection呼吁行器材可以在单张图片或一个图片文件夹中定位人脸位置(输出像素点坐标)。在呼吁行中行使face_detection,传入一个图片文件夹或单张图片文件来举办人脸位置检测:
- $ face_detection ./folder_with_pictures/
- examples/image1.jpg,65,215,169,112
- examples/image2.jpg,62,394,211,244
- examples/image2.jpg,95,941,244,792
输出功效的每一行都对应图片中的一张脸,输出坐标代表着这张脸的上、右、下、左像素点坐标。
调解人脸识此外容错率和敏感度
假如一张脸辨认出不止一个功效,那么这意味着他和其他人长的太像了(另外,本项目对付小孩和亚洲人的人脸辨认精确率有待晋升)。你可以把容错率调低一些,使辨认功效越发严酷。这个成果可通过传入参数 --tolerance 来实现,默认的容错率是0.6,容错率越低,辨认越严酷精确。
- $ face_recognition --tolerance 0.54 ./pictures_of_people_i_know/ ./unknown_pictures/
- /unknown_pictures/unknown.jpg,Barack Obama
- /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
人脸匹配的详细数值可以通过传入参数 --show-distance true 来查察
- $ face_recognition --show-distance true ./pictures_of_people_i_know/ ./unknown_pictures/
- /unknown_pictures/unknown.jpg,Barack Obama,0.378542298956785
- /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None
对辨认速率不满足怎么办?
假如你的CPU是多核的,你可以通过并行运算加快人脸辨认。譬喻,假如你的CPU有四个焦点,那么你可以通过并行运算晋升或许四倍的运算速率。
假如你行使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
对人脸辨认有精准要求怎么办? (编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|