資源簡介
博客地址:https://blog.csdn.net/wen_fei/article/details/80261047 人臉識別源代碼,包括使用opencv、dlib和cnn實現(xiàn)的人臉檢測、opencv實現(xiàn)的人臉對齊以及vgg-face的人臉特征提取等,最后余弦函數(shù)計算相似度,并提供flask部署代碼,可以放在服務(wù)器上遠程調(diào)用
代碼片段和文件信息
#?-*-?coding:?UTF-8?-*-
import?cv2?as?cv
import?math
import?dlib
from?fileConfig?import?*
from?matplotlib?import?pyplot?as?plt
“““
人臉對齊模塊
“““
#?根據(jù)人臉關(guān)鍵點進行仿射變換,水平人臉
def?warpAffineImg(img):
????eyes?=?getEyes(img)
????#?當(dāng)獲取到正常的2個關(guān)鍵點時進行水平操作
????if?len(eyes)?==?2:
????????#?關(guān)鍵點1
????????x?y?w?h?=?eyes[0]
????????x1?=?(x?+?w)?/?2
????????y1?=?(y?+?h)?/?2
????????#?關(guān)鍵點2
????????x?y?w?h?=?eyes[1]
????????x2?=?(x?+?w)?/?2
????????y2?=?(y?+?h)?/?2
????????#?中心點
????????center_x?=?(x1?+?x2)?/?2
????????center_y?=?(y1?+?y2)?/?2
????????#?偏移角度
????????angle?=?math.atan((y2?-?y1)?/?(x2?-?x1))?*?180?/?math.pi
????????#?消除識別角度過大的錯誤識別
????????if?angle?25?and?angle?>?-25:
????????????M?=?cv.getRotationMatrix2D((center_x?center_y)?angle?1.0)#?創(chuàng)建變換矩陣
????????????img?=?cv.warpAffine(img?M?(224?224))
????????return?img
????else:
????????return?img
#?給出固定角度,旋轉(zhuǎn)圖片
def?warpAffilneByAngle(img?angle):
????height?width?color?=?img.shape
????#?旋轉(zhuǎn)矩陣
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-02?17:20??code\
?????文件????????2238??2018-03-27?14:56??code\face_alignment.py
?????文件????????1908??2018-03-27?15:04??code\face_Host.py
?????文件???????12239??2018-03-27?15:30??code\face_pretreate.py
?????文件????????9130??2018-03-27?15:53??code\face_recognition.py
?????文件????????1569??2018-03-27?14:10??code\fileConfig.py
?????文件?????????651??2018-03-27?14:27??code\socketHost.py
評論
共有 條評論