人脸特征点检测是人脸检测过程中的一个重要环节。以往我们采用的方法是OpenCV或者Dlib,虽然Dlib优于OpenCV,但是检测出的68个点并没有覆盖额头区域。Reddit一位网友便在此基础上做了进一步研究,能够检测出81个面部特征点,使得准确度有所提高。
或许,这就是你需要的人脸特征点检测方法。
人脸特征点检测(Facial landmark detection)是人脸检测过程中的一个重要环节。是在人脸检测的基础上进行的,对人脸上的特征点例如嘴角、眼角等进行定位。
近日,Reddit一位网友po出一个帖子,表示想与社区同胞们分享自己的一点研究成果:
其主要的工作就是在人脸检测Dlib库68个特征点的基础上,增加了13个特征点(共81个),使得头部检测和图像操作更加精确。
现在来看一下demo:
demo视频链接:
https://www.youtube.com/watch?v=mDJrASIB1T0
81个特征点,人脸特征点检测更加精准
以往我们在做人脸特征点检测的时候,通常会用OpenCV来进行操作。
但自从人脸检测Dlib库问世,网友们纷纷表示:好用!Dlib≥OpenCV!Dlib具有更多的人脸识别模型,可以检测脸部68甚至更多的特征点。
我们来看一下Dlib的效果:
Dlib人脸特征点检测效果图
那么这68个特征点又是如何分布的呢?请看下面这张“面相图”:
人脸68个特征点分布
但无论是效果图和“面相图”,我们都可以发现在额头区域是没有分布特征点的。
于是,网友便提出了一个特征点能够覆盖额头区域的模型。
该模型是一个自定义形状预测模型,在经过训练后,可以找到任何给定图像中的81个面部特征点。
它的训练方法类似于Dlib的68个面部特征点形状预测器。只是在原有的68个特征点的基础上,在额头区域增加了13个点。这就使得头部的检测,以及用于需要沿着头部顶部的点的图像操作更加精准。
81个特征点效果图
这13个额外的特征点提取的方法,是根据该博主之前的工作完成的。
GitHub地址:
https://github.com/codeniko/eos
该博主继续使用Surrey Face Model,并记下了他认为适合他工作的13个点,并做了一些细节的修改。
当然,博主还慷慨的分享了训练的代码:
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()
有需要的小伙伴们,快来试试这个模型吧!
-
人脸识别
+关注
关注
76文章
4005浏览量
81751 -
人脸特征
+关注
关注
0文章
2浏览量
1288 -
dlib
+关注
关注
0文章
3浏览量
2594
原文标题:超越Dlib!81个特征点覆盖全脸,面部特征点检测更精准(附代码)
文章出处:【微信号:AI_era,微信公众号:新智元】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论