超越Dlib!81個特徵點覆蓋全臉,面部特徵點檢測更精準(附代碼)

2020-12-01 和訊科技

  新智元原創

  來源:Reddit、GitHub

  編輯: 金磊

  【新智元導讀】人臉特徵點檢測是人臉檢測過程中的一個重要環節。以往我們採用的方法是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# 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()

  99

  100# Now let's run the detector and shape_predictor over the images in the faces

  101# 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)

  107

  108    win.clear_overlay()

  109    win.set_image(img)

  110

  111    # Ask the detector to find the bounding boxes of each face. The 1 in the

  112    # second argument indicates that we should upsample the image 1 time. This

  113    # 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)

  125

  126    win.add_overlay(dets)

  127    dlib.hit_enter_to_continue()

  有需要的小夥伴們,快來試試這個模型吧!

  參考連結:

  GitHub:

  https://github.com/codeniko/shape_predictor_81_face_landmarks

  Reddit:

  https://www.reddit.com/r/MachineLearning/comments/b20b9i/p_i_trained_a_face_predictor_that_detects_fulls/

  Youtube:

  https://www.youtube.com/watch?v=mDJrASIB1T0

  新智元春季招聘開啟,一起弄潮AI之巔!

  崗位詳情請戳:

  【春招英雄貼】新智元呼召智士主筆,2019勇闖AI之巔!

  【2019新智元 AI 技術峰會倒計時9天】

  2019年的3月27日,新智元再匯AI之力,在北京泰富酒店舉辦AI開年盛典——2019新智元AI技術峰會。峰會以「智能雲?芯世界「為主題,聚焦智能雲和AI晶片的發展,重塑未來AI世界格局。

  同時,新智元將在峰會現場權威發布若干AI白皮書,聚焦產業鏈的創新活躍,評述華人AI學者的影響力,助力中國在世界級的AI競爭中實現超越。

  購票二維碼

  活動行購票連結:http://hdxu.cn/9Lb5U

  點擊文末「閱讀原文」,馬上參會!

本文首發於微信公眾號:新智元。文章內容屬作者個人觀點,不代表和訊網立場。投資者據此操作,風險請自擔。

(責任編輯:何一華 HN110)

相關焦點

  • 【實驗】OpenCV/Python/dlib眨眼檢測
    用OpenCV,Python和dlib進行眼睛眨眼檢測我們的眨眼檢測實驗分為四個部分:第一步,我們將討論眼睛的縱橫比以及如何用它來確定一個人是否在給定的視頻幀中閃爍第二步,我們將編寫Python,OpenCV和dlib代碼來執行面部標誌檢測和檢測視頻流中的眨眼。第三步,基於代碼,我們將應用我們的方法來檢測示例攝像頭流中的眨眼以及視頻文件。最後,我將通過討論改進我們的眨眼檢測器的方法來結束。
  • 解密:面部特徵點檢測的關鍵技術
    相關研究成果發表在計算機視覺國際頂級學術會議ICCV, CVPR和ECCV,並擔任國際頂級期刊TIP和TNNLS審稿人。面部特徵點定位任務即根據輸入的人臉圖像,自動定位出面部關鍵特徵點,如眼睛、鼻尖、嘴角點、眉毛以及人臉各部件輪廓點等,如下圖所示。
  • 如何使用Python進行面部識別?
    使用Haar人臉特徵分類器用以下圖像為例:來看看識別這張圖片中的人臉代碼:import cv2group_of_people_image = cv2.面部特徵檢測Dlib是一個擁有一些分類器的庫,可以幫助我們檢測人臉的某些部分,例如:眼睛、眉毛、鼻子和洋娃娃的區域。
  • OpenCV特徵點檢測——ORB特徵
    這個特徵描述子是由EPFL的Calonder在ECCV2010上提出的。主要思路就是在特徵點附近隨機選取若干點對,將這些點對的灰度值的大小,組合成一個二進位串,並將這個二進位串作為該特徵點的特徵描述子。
  • 【OpenCV+Python】輪廓特徵中階
    第二個參數:(x,y)是矩陣的左上點坐標。第三個參數:(x+w,y+h)是矩陣的右下點坐標。第四個參數:(0,255,0)是畫線對應的rgb顏色。第五個參數:2是所畫的線的寬度。它是一個以最小面積完全覆蓋對象的圓圈。
  • 大牛200行Python代碼手把手教你如何做一個換臉小程序,附源碼
    1.使用 dlib 提取面部標記該腳本使用 dlib 的 Python 綁定來提取面部標記:Dlib 實現了 Vahid Kazemi 和 Josephine Sullivan 的《使用回歸樹一毫秒臉部對準》論文中的算法。
  • 圖像特徵點|SIFT特徵點之圖像金字塔
    ,但SIFT除了計算比較耗時以外,其他方面的優點讓其成為特徵點提取算法中的一顆璀璨的明珠。局部影像特徵的描述與偵測可以幫助辨識物體,SIFT特徵是基於物體上的一些局部外觀的興趣點而與影像的大小和旋轉無關。對於光線、噪聲、些微視角改變的容忍度也相當高。基於這些特性,它們是高度顯著而且相對容易擷取,在母數龐大的特徵資料庫中,很容易辨識物體而且鮮有誤認。
  • 乾貨|一文讀懂圖像局部特徵點檢測算法
    而後者更關心一些全局特徵,如顏色分布,紋理特徵,主要物體的形狀等。全局特徵容易受到環境的幹擾,光照,旋轉,噪聲等不利因素都會影響全局特徵。相比而言,局部特徵點,往往對應著圖像中的一些線條交叉,明暗變化的結構中,受到的幹擾也少。而斑點與角點是兩類局部特徵點。斑點通常是指與周圍有著顏色和灰度差別的區域,如草原上的一棵樹或一棟房子。它是一個區域,所以它比角點的噪能力要強,穩定性要好。
  • 一種用於SLAM/SFM的深度學習特徵點 SuperPoint
    介紹諸多應用(諸如SLAM/SfM/相機標定/立體匹配)的首要一步就是特徵點提取,這裡的特徵點指的是能夠在不同光照&不同視角下都能夠穩定且可重複檢測的2D圖像點位置。基於CNN的算法幾乎在以圖像作為輸入的所有領域表現出相比於人類特徵工程更加優秀的表達能力。
  • 一種基於點雲的Voxel(三維體素)特徵的深度學習方法
    本文介紹一種基於點雲的Voxel(三維體素)特徵的深度學習方法,實現對點雲中目標的準確檢測,並提供一個簡單的ROS實現,供大家參考。,通過大量的訓練數據集,即可學習到對應的目標的特徵,從而檢測出點雲中的目標,如下: VoxelNet的網絡結構主要包含三個功能模塊:
  • 圖像特徵點、投影變換與圖像拼接
    在上面的過程中,我們忽略了獲取不同圖像視角對應點坐標的過程,事實上可以手動指定圖像的對應坐標點來計算出單應矩陣。比如在「名片全能王」這樣的應用中,就是通過檢測到名片的四個角位置,然後指定屏幕上的名片框的四個角的位置,從而計算出單應矩陣並進行名片圖像的變換的。
  • 曠視科技新增「狗臉識別」專利 可檢測狗鼻紋特徵點
    天眼查數據顯示,近日,北京曠視科技有限公司新增一條「狗臉識別」專利,一種狗鼻紋特徵點的檢測方法、裝置、系統及存儲介質。本專利申請於2018年12月,公布日在2020年7月。 天眼查數據顯示,近日,北京曠視科技有限公司新增一條「狗臉識別」專利,一種狗鼻紋特徵點的檢測方法、裝置、系統及存儲介質。
  • 圖像特徵點、投影變換與圖像拼接
    在上面的過程中,我們忽略了獲取不同圖像視角對應點坐標的過程,事實上可以手動指定圖像的對應坐標點來計算出單應矩陣。比如在「名片全能王」這樣的應用中,就是通過檢測到名片的四個角位置,然後指定屏幕上的名片框的四個角的位置,從而計算出單應矩陣並進行名片圖像的變換的。
  • 40行Python代碼,實現卷積特徵可視化
    本文的結構如下:首先,我將展示 VGG-16 網絡的幾個層次中的卷積特徵的可視化;然後,嘗試理解其中一些可視化,我將展示如何快速測試一個假設,即特定的濾波器會檢測到哪種模式;最後,我將解釋創建本文中提供的模式所需的代碼。
  • 罕見的特徵:僅在少數人身上存在的5個罕見的身體特徵
    然而,在人類的群體當中,有些人身上所存在的古怪的特徵,卻不是通過努力就一定能夠獲得的。這一次,擼哥就要為你介紹,罕見身體特徵:僅在少數人身上存在的5個罕見的身體特徵。輕鬆控制這部分的結構幫助它們檢測特定聲音的來源。然而,在人類中,擺動耳朵是一種從祖先那裡遺留下來的特徵。此外,這種罕見的特徵也具有父母遺傳性。關於為什麼有些人可以保留這個基因,有些人卻不可以,科學家也無法完全弄懂。
  • 寶寶面部有這3點特徵,代表天生智商高,傳說中的「一臉聰明相」
    但其實,要想提前知道寶寶的智商,從他們的面部特徵就能辨別一二。 相比較孕期的沉重,「卸貨」後小琳明顯身體更輕鬆,而身邊的親朋好友抱著這小娃娃,都說他是一臉福氣相。
  • 一文解析基於特徵點的視覺全局定位技術
    從關鍵點檢測層面,主要使用高斯差分 (Difference of Gaussian, DoG) 方法檢測多尺度空間上的極值點,作為關鍵點。而 Babaud 等人 [9] 證明了高斯平滑是唯一的能用多尺度空間平滑濾波核,為相關方法提供了充足的理論支持。
  • 深度學習閱讀導航 | 03 FPN:基於特徵金字塔網絡的目標檢測
    此外,該方法在GPU上的運行速度可以達到6FPS,是一種實用而準確的多尺度目標檢測解決方案,代碼將公之於眾。一、引言檢測大小不一的目標是計算機視覺中的一項基本的挑戰。FPN結合Faster RCNN可以在COCO物體檢測比賽中取得當前單模型的最佳性能(SOTA)。另外,通過對比實驗發現,FPN能促使Faster RCNN中的RPN網絡的召回率提高8個點;不僅如此,它也能使Fast RCNN的檢測性能提升2.3個點(COCO)和3.8個點(VOC)。