人臉特征點檢測是人臉檢測過程中的一個重要環(huán)節(jié)。以往我們采用的方法是OpenCV或者Dlib,雖然Dlib優(yōu)于OpenCV,但是檢測出的68個點并沒有覆蓋額頭區(qū)域。Reddit一位網(wǎng)友便在此基礎(chǔ)上做了進一步研究,能夠檢測出81個面部特征點,使得準(zhǔn)確度有所提高。
或許,這就是你需要的人臉特征點檢測方法。
人臉特征點檢測(Facial landmark detection)是人臉檢測過程中的一個重要環(huán)節(jié)。是在人臉檢測的基礎(chǔ)上進行的,對人臉上的特征點例如嘴角、眼角等進行定位。
近日,Reddit一位網(wǎng)友po出一個帖子,表示想與社區(qū)同胞們分享自己的一點研究成果:
其主要的工作就是在人臉檢測Dlib庫68個特征點的基礎(chǔ)上,增加了13個特征點(共81個),使得頭部檢測和圖像操作更加精確。
現(xiàn)在來看一下demo:
demo視頻鏈接:
https://www.youtube.com/watch?v=mDJrASIB1T0
81個特征點,人臉特征點檢測更加精準(zhǔn)
以往我們在做人臉特征點檢測的時候,通常會用OpenCV來進行操作。
但自從人臉檢測Dlib庫問世,網(wǎng)友們紛紛表示:好用!Dlib≥OpenCV!Dlib具有更多的人臉識別模型,可以檢測臉部68甚至更多的特征點。
我們來看一下Dlib的效果:
Dlib人臉特征點檢測效果圖
那么這68個特征點又是如何分布的呢?請看下面這張“面相圖”:
人臉68個特征點分布
但無論是效果圖和“面相圖”,我們都可以發(fā)現(xiàn)在額頭區(qū)域是沒有分布特征點的。
于是,網(wǎng)友便提出了一個特征點能夠覆蓋額頭區(qū)域的模型。
該模型是一個自定義形狀預(yù)測模型,在經(jīng)過訓(xùn)練后,可以找到任何給定圖像中的81個面部特征點。
它的訓(xùn)練方法類似于Dlib的68個面部特征點形狀預(yù)測器。只是在原有的68個特征點的基礎(chǔ)上,在額頭區(qū)域增加了13個點。這就使得頭部的檢測,以及用于需要沿著頭部頂部的點的圖像操作更加精準(zhǔn)。
81個特征點效果圖
這13個額外的特征點提取的方法,是根據(jù)該博主之前的工作完成的。
GitHub地址:
https://github.com/codeniko/eos
該博主繼續(xù)使用Surrey Face Model,并記下了他認為適合他工作的13個點,并做了一些細節(jié)的修改。
當(dāng)然,博主還慷慨的分享了訓(xùn)練的代碼:
1#!/usr/bin/python 2#Thecontentsofthisfileareinthepublicdomain.SeeLICENSE_FOR_EXAMPLE_PROGRAMS.txt 3# 4#Thisexampleprogramshowshowtousedlib'simplementationofthepaper: 5#OneMillisecondFaceAlignmentwithanEnsembleofRegressionTreesby 6#VahidKazemiandJosephineSullivan,CVPR2014 7# 8#Inparticular,wewilltrainafacelandmarkingmodelbasedonasmall 9#datasetandthenevaluateit.Ifyouwanttovisualizetheoutputofthe 10#trainedmodelonsomeimagesthenyoucanrunthe 11#face_landmark_detection.pyexampleprogramwithpredictor.datastheinput 12#model. 13# 14#Itshouldalsobenotedthatthiskindofmodel,whileoftenusedforface 15#landmarking,isquitegeneralandcanbeusedforavarietyofshape 16#predictiontasks.Butherewedemonstrateitonlyonasimpleface 17#landmarkingtask. 18# 19#COMPILING/INSTALLINGTHEDLIBPYTHONINTERFACE 20#Youcaninstalldlibusingthecommand: 21#pipinstalldlib 22# 23#Alternatively,ifyouwanttocompiledlibyourselfthengointothedlib 24#rootfolderandrun: 25#pythonsetup.pyinstall 26# 27#Compilingdlibshouldworkonanyoperatingsystemsolongasyouhave 28#CMakeinstalled.OnUbuntu,thiscanbedoneeasilybyrunningthe 29#command: 30#sudoapt-getinstallcmake 31# 32#AlsonotethatthisexamplerequiresNumpywhichcanbeinstalled 33#viathecommand: 34#pipinstallnumpy 35 36importos 37importsys 38importglob 39 40importdlib 41 42#Inthisexamplewearegoingtotrainafacedetectorbasedonthesmall 43#facesdatasetintheexamples/facesdirectory.Thismeansyouneedtosupply 44#thepathtothisfacesfolderasacommandlineargumentsowewillknow 45#whereitis. 46iflen(sys.argv)!=2: 47print( 48"Givethepathtotheexamples/facesdirectoryastheargumenttothis" 49"program.Forexample,ifyouareinthepython_examplesfolderthen" 50"executethisprogrambyrunning: " 51"./train_shape_predictor.py../examples/faces") 52exit() 53faces_folder=sys.argv[1] 54 55options=dlib.shape_predictor_training_options() 56#Nowmaketheobjectresponsiblefortrainingthemodel. 57#Thisalgorithmhasabunchofparametersyoucanmesswith.The 58#documentationfortheshape_predictor_trainerexplainsallofthem. 59#YoushouldalsoreadKazemi'spaperwhichexplainsalltheparameters 60#ingreatdetail.However,hereI'mjustsettingthreeofthem 61#differentlythantheirdefaultvalues.I'mdoingthisbecausewe 62#haveaverysmalldataset.Inparticular,settingtheoversampling 63#toahighamount(300)effectivelybooststhetrainingsetsize,so 64#thathelpsthisexample. 65options.oversampling_amount=300 66#I'malsoreducingthecapacityofthemodelbyexplicitlyincreasing 67#theregularization(makingnusmaller)andbyusingtreeswith 68#smallerdepths. 69options.nu=0.05 70options.tree_depth=2 71options.be_verbose=True 72 73#dlib.train_shape_predictor()doestheactualtraining.Itwillsavethe 74#finalpredictortopredictor.dat.TheinputisanXMLfilethatliststhe 75#imagesinthetrainingdatasetandalsocontainsthepositionsoftheface 76#parts. 77training_xml_path=os.path.join(faces_folder,"training_with_face_landmarks.xml") 78dlib.train_shape_predictor(training_xml_path,"predictor.dat",options) 79 80#Nowthatwehaveamodelwecantestit.dlib.test_shape_predictor() 81#measurestheaveragedistancebetweenafacelandmarkoutputbythe 82#shape_predictorandwhereitshouldbeaccordingtothetruthdata. 83print(" Trainingaccuracy:{}".format( 84dlib.test_shape_predictor(training_xml_path,"predictor.dat"))) 85#Therealtestistoseehowwellitdoesondataitwasn'ttrainedon.We 86#traineditonaverysmalldatasetsotheaccuracyisnotextremelyhigh,but 87#it'sstilldoingquitegood.Moreover,ifyoutrainitononeofthelarge 88#facelandmarkingdatasetsyouwillobtainstate-of-the-artresults,asshown 89#intheKazemipaper. 90testing_xml_path=os.path.join(faces_folder,"testing_with_face_landmarks.xml") 91print("Testingaccuracy:{}".format( 92dlib.test_shape_predictor(testing_xml_path,"predictor.dat"))) 93 94#Nowlet'suseitasyouwouldinanormalapplication.Firstwewillloadit 95#fromdisk.Wealsoneedtoloadafacedetectortoprovidetheinitial 96#estimateofthefaciallocation. 97predictor=dlib.shape_predictor("predictor.dat") 98detector=dlib.get_frontal_face_detector() 99100#Nowlet'srunthedetectorandshape_predictorovertheimagesinthefaces101#folderanddisplaytheresults.102print("Showingdetectionsandpredictionsontheimagesinthefacesfolder...")103win=dlib.image_window()104forfinglob.glob(os.path.join(faces_folder,"*.jpg")):105print("Processingfile:{}".format(f))106img=dlib.load_rgb_image(f)107108win.clear_overlay()109win.set_image(img)110111#Askthedetectortofindtheboundingboxesofeachface.The1inthe112#secondargumentindicatesthatweshouldupsampletheimage1time.This113#willmakeeverythingbiggerandallowustodetectmorefaces.114dets=detector(img,1)115print("Numberoffacesdetected:{}".format(len(dets)))116fork,dinenumerate(dets):117print("Detection{}:Left:{}Top:{}Right:{}Bottom:{}".format(118k,d.left(),d.top(),d.right(),d.bottom()))119#Getthelandmarks/partsforthefaceinboxd.120shape=predictor(img,d)121print("Part0:{},Part1:{}...".format(shape.part(0),122shape.part(1)))123#Drawthefacelandmarksonthescreen.124win.add_overlay(shape)125126win.add_overlay(dets)127dlib.hit_enter_to_continue()
有需要的小伙伴們,快來試試這個模型吧!
-
人臉識別
+關(guān)注
關(guān)注
76文章
4012瀏覽量
81911 -
人臉特征
+關(guān)注
關(guān)注
0文章
2瀏覽量
1299 -
dlib
+關(guān)注
關(guān)注
0文章
3瀏覽量
2598
原文標(biāo)題:超越Dlib!81個特征點覆蓋全臉,面部特征點檢測更精準(zhǔn)(附代碼)
文章出處:【微信號:AI_era,微信公眾號:新智元】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
評論