人臉特征點(diǎn)檢測是人臉檢測過程中的一個(gè)重要環(huán)節(jié)。以往我們采用的方法是OpenCV或者Dlib,雖然Dlib優(yōu)于OpenCV,但是檢測出的68個(gè)點(diǎn)并沒有覆蓋額頭區(qū)域。Reddit一位網(wǎng)友便在此基礎(chǔ)上做了進(jìn)一步研究,能夠檢測出81個(gè)面部特征點(diǎn),使得準(zhǔn)確度有所提高。
或許,這就是你需要的人臉特征點(diǎn)檢測方法。
人臉特征點(diǎn)檢測(Facial landmark detection)是人臉檢測過程中的一個(gè)重要環(huán)節(jié)。是在人臉檢測的基礎(chǔ)上進(jìn)行的,對人臉上的特征點(diǎn)例如嘴角、眼角等進(jìn)行定位。
近日,Reddit一位網(wǎng)友po出一個(gè)帖子,表示想與社區(qū)同胞們分享自己的一點(diǎn)研究成果:
其主要的工作就是在人臉檢測Dlib庫68個(gè)特征點(diǎn)的基礎(chǔ)上,增加了13個(gè)特征點(diǎn)(共81個(gè)),使得頭部檢測和圖像操作更加精確。
現(xiàn)在來看一下demo:
demo視頻鏈接:
https://www.youtube.com/watch?v=mDJrASIB1T0
81個(gè)特征點(diǎn),人臉特征點(diǎn)檢測更加精準(zhǔn)
以往我們在做人臉特征點(diǎn)檢測的時(shí)候,通常會用OpenCV來進(jìn)行操作。
但自從人臉檢測Dlib庫問世,網(wǎng)友們紛紛表示:好用!Dlib≥OpenCV!Dlib具有更多的人臉識別模型,可以檢測臉部68甚至更多的特征點(diǎn)。
我們來看一下Dlib的效果:
Dlib人臉特征點(diǎn)檢測效果圖
那么這68個(gè)特征點(diǎn)又是如何分布的呢?請看下面這張“面相圖”:
人臉68個(gè)特征點(diǎn)分布
但無論是效果圖和“面相圖”,我們都可以發(fā)現(xiàn)在額頭區(qū)域是沒有分布特征點(diǎn)的。
于是,網(wǎng)友便提出了一個(gè)特征點(diǎn)能夠覆蓋額頭區(qū)域的模型。
該模型是一個(gè)自定義形狀預(yù)測模型,在經(jīng)過訓(xùn)練后,可以找到任何給定圖像中的81個(gè)面部特征點(diǎn)。
它的訓(xùn)練方法類似于Dlib的68個(gè)面部特征點(diǎn)形狀預(yù)測器。只是在原有的68個(gè)特征點(diǎn)的基礎(chǔ)上,在額頭區(qū)域增加了13個(gè)點(diǎn)。這就使得頭部的檢測,以及用于需要沿著頭部頂部的點(diǎn)的圖像操作更加精準(zhǔn)。
81個(gè)特征點(diǎn)效果圖
這13個(gè)額外的特征點(diǎn)提取的方法,是根據(jù)該博主之前的工作完成的。
GitHub地址:
https://github.com/codeniko/eos
該博主繼續(xù)使用Surrey Face Model,并記下了他認(rèn)為適合他工作的13個(gè)點(diǎn),并做了一些細(xì)節(jié)的修改。
當(dāng)然,博主還慷慨的分享了訓(xùn)練的代碼:
1#!/usr/bin/python 2# The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt 3# 4# This example program shows how to use dlib's implementation of the paper: 5# One Millisecond Face Alignment with an Ensemble of Regression Trees by 6# Vahid Kazemi and Josephine Sullivan, CVPR 2014 7# 8# In particular, we will train a face landmarking model based on a small 9# dataset and then evaluate it. If you want to visualize the output of the 10# trained model on some images then you can run the 11# face_landmark_detection.py example program with predictor.dat as the input 12# model. 13# 14# It should also be noted that this kind of model, while often used for face 15# landmarking, is quite general and can be used for a variety of shape 16# prediction tasks. But here we demonstrate it only on a simple face 17# landmarking task. 18# 19# COMPILING/INSTALLING THE DLIB PYTHON INTERFACE 20# You can install dlib using the command: 21# pip install dlib 22# 23# Alternatively, if you want to compile dlib yourself then go into the dlib 24# root folder and run: 25# python setup.py install 26# 27# Compiling dlib should work on any operating system so long as you have 28# CMake installed. On Ubuntu, this can be done easily by running the 29# command: 30# sudo apt-get install cmake 31# 32# Also note that this example requires Numpy which can be installed 33# via the command: 34# pip install numpy 35 36import os 37import sys 38import glob 39 40import dlib 41 42# In this example we are going to train a face detector based on the small 43# faces dataset in the examples/faces directory. This means you need to supply 44# the path to this faces folder as a command line argument so we will know 45# where it is. 46if len(sys.argv) != 2: 47 print( 48 "Give the path to the examples/faces directory as the argument to this " 49 "program. For example, if you are in the python_examples folder then " 50 "execute this program by running:\n" 51 " ./train_shape_predictor.py ../examples/faces") 52 exit() 53faces_folder = sys.argv[1] 54 55options = dlib.shape_predictor_training_options() 56# Now make the object responsible for training the model. 57# This algorithm has a bunch of parameters you can mess with. The 58# documentation for the shape_predictor_trainer explains all of them. 59# You should also read Kazemi's paper which explains all the parameters 60# in great detail. However, here I'm just setting three of them 61# differently than their default values. I'm doing this because we 62# have a very small dataset. In particular, setting the oversampling 63# to a high amount (300) effectively boosts the training set size, so 64# that helps this example. 65options.oversampling_amount = 300 66# I'm also reducing the capacity of the model by explicitly increasing 67# the regularization (making nu smaller) and by using trees with 68# smaller depths. 69options.nu = 0.05 70options.tree_depth = 2 71options.be_verbose = True 72 73# dlib.train_shape_predictor() does the actual training. It will save the 74# final predictor to predictor.dat. The input is an XML file that lists the 75# images in the training dataset and also contains the positions of the face 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# Now that we have a model we can test it. dlib.test_shape_predictor() 81# measures the average distance between a face landmark output by the 82# shape_predictor and where it should be according to the truth data. 83print("\nTraining accuracy: {}".format( 84 dlib.test_shape_predictor(training_xml_path, "predictor.dat"))) 85# The real test is to see how well it does on data it wasn't trained on. We 86# trained it on a very small dataset so the accuracy is not extremely high, but 87# it's still doing quite good. Moreover, if you train it on one of the large 88# face landmarking datasets you will obtain state-of-the-art results, as shown 89# in the Kazemi paper. 90testing_xml_path = os.path.join(faces_folder, "testing_with_face_landmarks.xml") 91print("Testing accuracy: {}".format( 92 dlib.test_shape_predictor(testing_xml_path, "predictor.dat"))) 93 94# Now let's use it as you would in a normal application. First we will load it 95# from disk. We also need to load a face detector to provide the initial 96# estimate of the facial location. 97predictor = dlib.shape_predictor("predictor.dat") 98detector = dlib.get_frontal_face_detector() 99100# Now let's run the detector and shape_predictor over the images in the faces101# folder and display the results.102print("Showing detections and predictions on the images in the faces folder...")103win = dlib.image_window()104for f in glob.glob(os.path.join(faces_folder, "*.jpg")):105 print("Processing file: {}".format(f))106 img = dlib.load_rgb_image(f)107108 win.clear_overlay()109 win.set_image(img)110111 # Ask the detector to find the bounding boxes of each face. The 1 in the112 # second argument indicates that we should upsample the image 1 time. This113 # will make everything bigger and allow us to detect more faces.114 dets = detector(img, 1)115 print("Number of faces detected: {}".format(len(dets)))116 for k, d in enumerate(dets):117 print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(118 k, d.left(), d.top(), d.right(), d.bottom()))119 # Get the landmarks/parts for the face in box d.120 shape = predictor(img, d)121 print("Part 0: {}, Part 1: {} ...".format(shape.part(0),122 shape.part(1)))123 # Draw the face landmarks on the screen.124 win.add_overlay(shape)125126 win.add_overlay(dets)127 dlib.hit_enter_to_continue()
有需要的小伙伴們,快來試試這個(gè)模型吧!
原文標(biāo)題:超越Dlib!81個(gè)特征點(diǎn)覆蓋全臉,面部特征點(diǎn)檢測更精準(zhǔn)(附代碼)
文章出處:【微信號:AI_era,微信公眾號:新智元】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。