Face Recognition - GitHub

文章推薦指數: 80 %
投票人數:10人

Find and recognize unknown faces in a photograph based on photographs of known people · Identify and draw boxes around each person in a photo · Compare faces by ... Skiptocontent {{message}} ageitgey / face_recognition Public Notifications Fork 12.4k Star 45.2k Theworld'ssimplestfacialrecognitionapiforPythonandthecommandline License MITlicense 45.2k stars 12.4k forks Star Notifications Code Issues 658 Pullrequests 15 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights ageitgey/face_recognition Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository. master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 6 branches 2 tags Code Latestcommit ageitgey Mergepullrequest#1225fromdorozcom/master … 2e2dcce Jun10,2022 Mergepullrequest#1225fromdorozcom/master UpdateDockerfile 2e2dcce Gitstats 238 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime .github     docker     docs     examples     face_recognition     tests     .editorconfig     .gitignore     AUTHORS.rst     CONTRIBUTING.rst     Dockerfile     Dockerfile.gpu     HISTORY.rst     LICENSE     MANIFEST.in     Makefile     README.md     README.rst     README_Japanese.md     README_Korean.md     README_Simplified_Chinese.md     docker-compose.yml     pyproject.toml     requirements.txt     requirements_dev.txt     requirements_docs.txt     setup.cfg     setup.py     tox.ini     Viewcode FaceRecognition Features Findfacesinpictures Findandmanipulatefacialfeaturesinpictures Identifyfacesinpictures OnlineDemos Installation Requirements InstallationOptions: InstallingonMacorLinux InstallingonanNvidiaJetsonNanoboard InstallingonRaspberryPi2+ InstallingonFreeBSD InstallingonWindows Installingapre-configuredVirtualMachineimage Usage Command-LineInterface face_recognitioncommandlinetool face_detectioncommandlinetool AdjustingTolerance/Sensitivity MoreExamples SpeedingupFaceRecognition PythonModule Automaticallyfindallthefacesinanimage Automaticallylocatethefacialfeaturesofapersoninanimage Recognizefacesinimagesandidentifywhotheyare PythonCodeExamples FaceDetection FacialFeatures FacialRecognition CreatingaStandaloneExecutable ArticlesandGuidesthatcoverface_recognition HowFaceRecognitionWorks Caveats DeploymenttoCloudHosts(Heroku,AWS,etc) Havingproblems? Thanks README.md FaceRecognition YoucanalsoreadatranslatedversionofthisfileinChinese简体中文版orinKorean한국어orinJapanese日本語. RecognizeandmanipulatefacesfromPythonorfromthecommandlinewith theworld'ssimplestfacerecognitionlibrary. Builtusingdlib'sstate-of-the-artfacerecognition builtwithdeeplearning.Themodelhasanaccuracyof99.38%onthe LabeledFacesintheWildbenchmark. Thisalsoprovidesasimpleface_recognitioncommandlinetoolthatlets youdofacerecognitiononafolderofimagesfromthecommandline! Features Findfacesinpictures Findallthefacesthatappearinapicture: importface_recognition image=face_recognition.load_image_file("your_file.jpg") face_locations=face_recognition.face_locations(image) Findandmanipulatefacialfeaturesinpictures Getthelocationsandoutlinesofeachperson'seyes,nose,mouthandchin. importface_recognition image=face_recognition.load_image_file("your_file.jpg") face_landmarks_list=face_recognition.face_landmarks(image) Findingfacialfeaturesissuperusefulforlotsofimportantstuff.Butyoucanalsouseitforreallystupidstuff likeapplyingdigitalmake-up(think'Meitu'): Identifyfacesinpictures Recognizewhoappearsineachphoto. importface_recognition known_image=face_recognition.load_image_file("biden.jpg") unknown_image=face_recognition.load_image_file("unknown.jpg") biden_encoding=face_recognition.face_encodings(known_image)[0] unknown_encoding=face_recognition.face_encodings(unknown_image)[0] results=face_recognition.compare_faces([biden_encoding],unknown_encoding) YoucanevenusethislibrarywithotherPythonlibrariestodoreal-timefacerecognition: Seethisexampleforthecode. OnlineDemos User-contributedsharedJupyternotebookdemo(notofficiallysupported): Installation Requirements Python3.3+orPython2.7 macOSorLinux(Windowsnotofficiallysupported,butmightwork) InstallationOptions: InstallingonMacorLinux First,makesureyouhavedlibalreadyinstalledwithPythonbindings: HowtoinstalldlibfromsourceonmacOSorUbuntu Then,makesureyouhavecmakeinstalled: brewinstallcmake Finally,installthismodulefrompypiusingpip3(orpip2forPython2): pip3installface_recognition Alternatively,youcantrythislibrarywithDocker,seethissection. Ifyouarehavingtroublewithinstallation,youcanalsotryouta pre-configuredVM. InstallingonanNvidiaJetsonNanoboard JetsonNanoinstallationinstructions Pleasefollowtheinstructionsinthearticlecarefully.ThereiscurrentabugintheCUDAlibrariesontheJetsonNanothatwillcausethislibrarytofailsilentlyifyoudon'tfollowtheinstructionsinthearticletocommentoutalineindlibandrecompileit. InstallingonRaspberryPi2+ RaspberryPi2+installationinstructions InstallingonFreeBSD pkginstallgraphics/py-face_recognition InstallingonWindows WhileWindowsisn'tofficiallysupported,helpfulusershavepostedinstructionsonhowtoinstallthislibrary: @masoudr'sWindows10installationguide(dlib+face_recognition) Installingapre-configuredVirtualMachineimage Downloadthepre-configuredVMimage(forVMwarePlayerorVirtualBox). Usage Command-LineInterface Whenyouinstallface_recognition,yougettwosimplecommand-line programs: face_recognition-Recognizefacesinaphotographorfolderfullfor photographs. face_detection-Findfacesinaphotographorfolderfullforphotographs. face_recognitioncommandlinetool Theface_recognitioncommandletsyourecognizefacesinaphotographor folderfullforphotographs. First,youneedtoprovideafolderwithonepictureofeachpersonyou alreadyknow.Thereshouldbeoneimagefileforeachpersonwiththe filesnamedaccordingtowhoisinthepicture: Next,youneedasecondfolderwiththefilesyouwanttoidentify: Theninyousimplyrunthecommandface_recognition,passingin thefolderofknownpeopleandthefolder(orsingleimage)withunknown peopleandittellsyouwhoisineachimage: $face_recognition./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person There'sonelineintheoutputforeachface.Thedataiscomma-separated withthefilenameandthenameofthepersonfound. Anunknown_personisafaceintheimagethatdidn'tmatchanyonein yourfolderofknownpeople. face_detectioncommandlinetool Theface_detectioncommandletsyoufindthelocation(pixelcoordinatates) ofanyfacesinanimage. Justrunthecommandface_detection,passinginafolderofimages tocheck(orasingleimage): $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 Itprintsonelineforeachfacethatwasdetected.Thecoordinates reportedarethetop,right,bottomandleftcoordinatesoftheface(inpixels). AdjustingTolerance/Sensitivity Ifyouaregettingmultiplematchesforthesameperson,itmightbethat thepeopleinyourphotoslookverysimilarandalowertolerancevalue isneededtomakefacecomparisonsmorestrict. Youcandothatwiththe--toleranceparameter.Thedefaulttolerance valueis0.6andlowernumbersmakefacecomparisonsmorestrict: $face_recognition--tolerance0.54./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person Ifyouwanttoseethefacedistancecalculatedforeachmatchinorder toadjustthetolerancesetting,youcanuse--show-distancetrue: $face_recognition--show-distancetrue./pictures_of_people_i_know/./unknown_pictures/ /unknown_pictures/unknown.jpg,BarackObama,0.378542298956785 /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None MoreExamples Ifyousimplywanttoknowthenamesofthepeopleineachphotographbutdon't careaboutfilenames,youcoulddothis: $face_recognition./pictures_of_people_i_know/./unknown_pictures/|cut-d','-f2 BarackObama unknown_person SpeedingupFaceRecognition Facerecognitioncanbedoneinparallelifyouhaveacomputerwith multipleCPUcores.Forexample,ifyoursystemhas4CPUcores,youcan processabout4timesasmanyimagesinthesameamountoftimebyusing allyourCPUcoresinparallel. IfyouareusingPython3.4ornewer,passina--cpusparameter: $face_recognition--cpus4./pictures_of_people_i_know/./unknown_pictures/ Youcanalsopassin--cpus-1touseallCPUcoresinyoursystem. PythonModule Youcanimporttheface_recognitionmoduleandtheneasilymanipulate faceswithjustacoupleoflinesofcode.It'ssupereasy! APIDocs:https://face-recognition.readthedocs.io. Automaticallyfindallthefacesinanimage importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_locations=face_recognition.face_locations(image) #face_locationsisnowanarraylistingtheco-ordinatesofeachface! Seethisexample totryitout. Youcanalsoopt-intoasomewhatmoreaccuratedeep-learning-basedfacedetectionmodel. Note:GPUacceleration(viaNVidia'sCUDAlibrary)isrequiredforgood performancewiththismodel.You'llalsowanttoenableCUDAsupport whencomplilingdlib. importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_locations=face_recognition.face_locations(image,model="cnn") #face_locationsisnowanarraylistingtheco-ordinatesofeachface! Seethisexample totryitout. IfyouhavealotofimagesandaGPU,youcanalso findfacesinbatches. Automaticallylocatethefacialfeaturesofapersoninanimage importface_recognition image=face_recognition.load_image_file("my_picture.jpg") face_landmarks_list=face_recognition.face_landmarks(image) #face_landmarks_listisnowanarraywiththelocationsofeachfacialfeatureineachface. #face_landmarks_list[0]['left_eye']wouldbethelocationandoutlineofthefirstperson'slefteye. Seethisexample totryitout. Recognizefacesinimagesandidentifywhotheyare importface_recognition picture_of_me=face_recognition.load_image_file("me.jpg") my_face_encoding=face_recognition.face_encodings(picture_of_me)[0] #my_face_encodingnowcontainsauniversal'encoding'ofmyfacialfeaturesthatcanbecomparedtoanyotherpictureofaface! unknown_picture=face_recognition.load_image_file("unknown.jpg") unknown_face_encoding=face_recognition.face_encodings(unknown_picture)[0] #Nowwecanseethetwofaceencodingsareofthesamepersonwith`compare_faces`! results=face_recognition.compare_faces([my_face_encoding],unknown_face_encoding) ifresults[0]==True: print("It'sapictureofme!") else: print("It'snotapictureofme!") Seethisexample totryitout. PythonCodeExamples Alltheexamplesareavailablehere. FaceDetection Findfacesinaphotograph Findfacesinaphotograph(usingdeeplearning) Findfacesinbatchesofimagesw/GPU(usingdeeplearning) Blurallthefacesinalivevideousingyourwebcam(RequiresOpenCVtobeinstalled) FacialFeatures Identifyspecificfacialfeaturesinaphotograph Apply(horriblyugly)digitalmake-up FacialRecognition Findandrecognizeunknownfacesinaphotographbasedonphotographsofknownpeople Identifyanddrawboxesaroundeachpersoninaphoto ComparefacesbynumericfacedistanceinsteadofonlyTrue/Falsematches Recognizefacesinlivevideousingyourwebcam-Simple/SlowerVersion(RequiresOpenCVtobeinstalled) Recognizefacesinlivevideousingyourwebcam-FasterVersion(RequiresOpenCVtobeinstalled) Recognizefacesinavideofileandwriteoutnewvideofile(RequiresOpenCVtobeinstalled) RecognizefacesonaRaspberryPiw/camera RunawebservicetorecognizefacesviaHTTP(RequiresFlasktobeinstalled) RecognizefaceswithaK-nearestneighborsclassifier TrainmultipleimagesperpersonthenrecognizefacesusingaSVM CreatingaStandaloneExecutable Ifyouwanttocreateastandaloneexecutablethatcanrunwithouttheneedtoinstallpythonorface_recognition,youcanusePyInstaller.However,itrequiressomecustomconfigurationtoworkwiththislibrary.Seethisissueforhowtodoit. ArticlesandGuidesthatcoverface_recognition MyarticleonhowFaceRecognitionworks:ModernFaceRecognitionwithDeepLearning Coversthealgorithmsandhowtheygenerallywork FacerecognitionwithOpenCV,Python,anddeeplearningbyAdrianRosebrock Covershowtousefacerecognitioninpractice RaspberryPiFaceRecognitionbyAdrianRosebrock CovershowtousethisonaRaspberryPi FaceclusteringwithPythonbyAdrianRosebrock Covershowtoautomaticallyclusterphotosbasedonwhoappearsineachphotousingunsupervisedlearning HowFaceRecognitionWorks Ifyouwanttolearnhowfacelocationandrecognitionworkinsteadof dependingonablackboxlibrary,readmyarticle. Caveats Thefacerecognitionmodelistrainedonadultsanddoesnotworkverywellonchildren.Ittendstomix upchildrenquiteeasyusingthedefaultcomparisonthresholdof0.6. Accuracymayvarybetweenethnicgroups.Pleaseseethiswikipageformoredetails. DeploymenttoCloudHosts(Heroku,AWS,etc) Sinceface_recognitiondependsondlibwhichiswritteninC++,itcanbetrickytodeployanapp usingittoacloudhostingproviderlikeHerokuorAWS. Tomakethingseasier,there'sanexampleDockerfileinthisrepothatshowshowtorunanappbuiltwith face_recognitioninaDockercontainer.Withthat,youshouldbeabletodeploy toanyservicethatsupportsDockerimages. YoucantrytheDockerimagelocallybyrunning:docker-composeup--build TherearealsoseveralprebuiltDockerimages. LinuxuserswithaGPU(drivers>=384.81)andNvidia-DockerinstalledcanruntheexampleontheGPU:Openthedocker-compose.ymlfileanduncommentthedockerfile:Dockerfile.gpuandruntime:nvidialines. Havingproblems? Ifyourunintoproblems,pleasereadtheCommonErrorssectionofthewikibeforefilingagithubissue. Thanks Many,manythankstoDavisKing(@nulhom) forcreatingdlibandforprovidingthetrainedfacialfeaturedetectionandfaceencodingmodels usedinthislibrary.FormoreinformationontheResNetthatpowersthefaceencodings,checkout hisblogpost. ThankstoeveryonewhoworksonalltheawesomePythondatasciencelibrarieslikenumpy,scipy,scikit-image, pillow,etc,etcthatmakesthiskindofstuffsoeasyandfuninPython. ThankstoCookiecutterandthe audreyr/cookiecutter-pypackageprojecttemplate formakingPythonprojectpackagingwaymoretolerable. About Theworld'ssimplestfacialrecognitionapiforPythonandthecommandline Topics python machine-learning face-recognition face-detection Resources Readme License MITlicense Stars 45.2k stars Watchers 1.6k watching Forks 12.4k forks Releases 2 v1.2.2 Latest Apr2,2018 +1release Packages0 Nopackagespublished Contributors52 +41contributors Languages Python 79.1% Dockerfile 15.7% Makefile 5.2% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?