首页 > 编程知识 正文

人脸识别为什么用python开发(deepface)

时间:2023-05-04 13:15:19 阅读:77586 作者:4028

正在加载视频.

Face Recognition是一个基于Python的人脸识别库,还提供了命令行工具,可以通过命令行对任意文件夹中的图像进行人脸识别操作。

该库采用dlib顶级深度学习人脸识别技术构建,在室外人脸检测数据库基准测试(Labeled Faces in the Wild benchmark )中准确率达到99.38%。

Find faces in pictures

findallthefacesthatappearinapicture :

findandmanipulatefacialfeaturesinpictures

getthelocationsandoutlinesofeachperson ' se是,nose,mouth and chin。

findingfacialfeaturesissuperusefulforlotsofimportantstuff.butyoucanalsouseforreallystupidstufflikeapplyingdigitalmalmake-up ()

Recognize who appears in each photo。

youcanevenusethislibrarywithotherpythonlibrariestodoreal-timefacerecognition 3360

face _ recognitioncommandlinetool

theface _ recognitioncommandletsyourecognizefacesinaphotographorfolderfullforphotographs。

First,youneedtoprovideafolderwithonepictureofeachpersonyoualreadyknow.thereshouldbeoneimagefileforeachpersonwithefilesnanow

theninyousimplyrunthecommandface _ recognition,passinginthefolderofknownpeopleandthefolder (orsingleimage ) withunknownpeoper

$ face _ recognition./pictures _ of _ people _ I _ know/./unknown _ pictures /

/unknown_pictures/unknown.jpg,Barack Obama

/face _ recognition _ test/unknown _ pictures/unknown.jpg,unknown_person

there ' sonelineintheoutputforeachface.thedataiscomma-separatedwiththefilenameandthenameofthepersonfound。

an unknown _ personisafaceintheimagethatdidn ' tmatchanyoneinyourfolderofknownpeople。

face_detection command line tool

theface _ detectioncommandletsyoufindthelocation (pixelcoordinates ) of any faces in an image。

Jj

ust run the command face_detection, passing in a folder of images to check (or a single image):

$ 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

It prints one line for each face that was detected. The coordinates reported are the top, right, bottom and left coordinates of the face (in pixels).

Adjusting Tolerance / Sensitivity

If you are getting multiple matches for the same person, it might be that the people in your photos look very similar and a lower tolerance value is needed to make face comparisons more strict.

You can do that with the --tolerance parameter. The default tolerance value is 0.6 and lower numbers make face comparisons more strict:

$ 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

If you want to see the face distance calculated for each match in order to adjust the tolerance setting, you can use --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

More Examples

If you simply want to know the names of the people in each photograph but don't care about file names, you could do this:

$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ | cut -d ',' -f2 Barack Obama unknown_person

Speeding up Face Recognition

Face recognition can be done in parallel if you have a computer with multiple CPU cores. For example if your system has 4 CPU cores, you can process about 4 times as many images in the same amount of time by using all your CPU cores in parallel.

If you are using Python 3.4 or newer, pass in a --cpus <number_of_cpu_cores_to_use> parameter:

$ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/

You can also pass in --cpus -1 to use all CPU cores in your system.

Python Module

You can import the face_recognition module and then easily manipulate faces with just a couple of lines of code. It's super easy!

API Docs: https://face-recognition.readthedocs.io.

Automatically find all the faces in an image

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!

See this example to try it out.

You can also opt-in to a somewhat more accurate deep-learning-based face detection model.

Note: GPU acceleration (via nvidia's CUDA library) is required for good performance with this model. You'll also want to enable CUDA support when compliling dlib.

import face_recognition image = face_recognition.load_image_file("my_picture.jpg") face_locations = face_recognition.face_locations(image, model="cnn")# face_locations is now an array listing the co-ordinates of each face!

See this example to try it out.

If you have a lot of images and a GPU, you can also find faces in batches.

Automatically locate the facial features of a person in an image

import face_recognition image = face_recognition.load_image_file("my_picture.jpg") face_landmarks_list = face_recognition.face_landmarks(image)# face_landmarks_list is now an array with the locations of each facial feature in each face.# face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.

See this example to try it out.

Recognize faces in images and identify who they are

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 me!")

See this example to try it out.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。