臉部偵測python__python

來源:互聯網
上載者:User
效果圖


Dlib Python 檢測人臉特徵點 Face Landmark Detection
首先安裝Dlib,Opencv庫 安裝Dlib

1.到這裡去下載你需要的的dlib輪子:Links for dlib

2.cmd進入你剛下好whl檔案的位置,然後輸入

pip install 檔案名稱.whl
注意尾碼是whl,並且選擇安裝的版本要和python版本一致,如果一次安裝不成功選擇不同的dlib安裝試試,總有一款會成功。 下載特徵檢測器

設定特徵檢測器,dlib有已經訓練的好的需要下載,也可以自己根據需要訓練

下載連結:http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

下載完之後解壓,將路徑送到dlib.shape_predictor()裡面

import cv2import dlibdetector = dlib.get_frontal_face_detector()landmark_predictor = dlib.shape_predictor('D:/python/shape/shape_predictor_68_face_landmarks.dat')img = cv2.imread('D:/python/demos/d.jpg')faces = detector(img,1)if (len(faces) > 0):    for k,d in enumerate(faces):           cv2.rectangle(img,(d.left(),d.top()),(d.right(),d.bottom()),(255,255,255))        shape = landmark_predictor(img,d)        for i in range(68):            cv2.circle(img, (shape.part(i).x, shape.part(i).y),5,(0,255,0), -1, 8)            cv2.putText(img,str(i),(shape.part(i).x,shape.part(i).y),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,2555,255))cv2.imwrite("D:/python/demos/fdres/hh.jpg", img)//將實驗的映像儲存在fdres檔案夾下            cv2.imshow('Frame',img)cv2.waitKey(0)

detector是dlib訓練好的臉部偵測器,是基於HOG特徵的

shape = landmark_predictor(img,d)

我們想要的特徵點全部儲存在了shape裡面,d是dlib.rectangle(),裡面儲存著臉部偵測矩形的左上和右下座標,shape.part(i)是第i個特徵點landmark_predictor也是dlib訓練好的人臉特徵檢測器,是基於Ensemble of Regression Trees的,在CVPR2014的論文有過,單人臉的特徵點檢測速度極快,Dlib就是實現了這種演算法的,想要研究一下的可以看一下。
論文連結https://pdfs.semanticscholar.org/d78b/6a5b0dcaa81b1faea5fb0000045a62513567.pdf

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.