使用dilb實現人臉檢測 識別

2022-08-23 19:00:10 字數 3409 閱讀 3858

以下是檢測**:

import

dlib

import

numpy as np

import

cv2detector = dlib.get_frontal_face_detector() #

載入正臉檢測器,使用dlib

sp = dlib.shape_predictor("

dlibmodel/shape_predictor_68_face_landmarks.dat

") #

載入人臉關鍵點檢測模型

facerec = dlib.face_recognition_model_v1("

dlibmodel/dlib_face_recognition_resnet_model_v1.dat

") #

載入人臉識別模型

返回人臉,(灰度圖,取樣次數)

tzs =

for (i, rect) in

enumerate(rects):

shape68 = sp(image, rect) #

返回68個特徵點

face_descriptor = facerec.compute_face_descriptor(image, shape68) #

計算人臉的128維的向量

tz = np.array(face_descriptor) #

人臉特徵值

for p in

shape68.parts():

cv2.circle(image, (p.x, p.y), 2, (0, 0, 255), 1)

cv2.rectangle(image, (rect.left(), rect.top()), (rect.right(), rect.bottom()), (0, 255, 0), 2)

print

(tzs)

cv2.imshow(

"output

", image)

cv2.waitkey(-1)

原圖

效果圖

列印的特徵值:

[array([-0.14579333,  0.06563152,  0.09314926, -0.17351562, -0.08750948,

-0.03944254, -0.05778341, -0.16003576, 0.18947695, -0.20229495,

0.22666875, -0.09615702, -0.15724032, -0.00979816, -0.02177811,

0.23944741, -0.21378906, -0.12338841, -0.04015261, 0.00419115,

0.07516268, 0.08075333, 0.01858632, 0.07583004, -0.1436058,

-0.33890599, -0.10919157, -0.05613485, -0.01440384, -0.0421476,

-0.02769968, 0.02456936, -0.19791584, -0.02495837, -0.01396229,

0.15883508, -0.05608664, -0.16127518, 0.14932884, -0.0153573,

-0.27676189, 0.08176911, 0.04226109, 0.19125782, 0.18729328,

-0.03498868, 0.0062949 , -0.20621458, 0.1477259 , -0.20221941,

-0.01363696, 0.06110315, -0.06132922, 0.05342007, 0.01454075,

-0.15085547, 0.06046266, 0.14739415, -0.21987613, -0.03639037,

0.08528309, -0.04437468, 0.03675304, -0.10165367, 0.14875233,

0.156369 , -0.08553442, -0.22346984, 0.11466061, -0.14528711,

-0.05263588, 0.10216871, -0.15159039, -0.19255549, -0.29263291,

-0.04936468, 0.33185786, 0.09766599, -0.13290709, 0.03094622,

-0.01321913, -0.01007816, 0.14334042, 0.12662645, 0.04984599,

0.00495763, -0.08788066, 0.05117153, 0.25504613, -0.03899687,

-0.01541797, 0.24360959, -0.00281113, 0.03764223, 0.02046303,

0.08831443, -0.15270098, 0.07429178, -0.16997421, -0.00883572,

0.01246334, 0.02862958, -0.01707144, 0.16006561, -0.15909354,

0.23000078, -0.02357504, -0.0060425 , -0.02578063, -0.03944276,

-0.05486409, 0.01571657, 0.15119481, -0.14951093, 0.16744466,

0.17089023, 0.05214873, 0.14098236, 0.10236948, 0.05116107,

-0.08004355, 0.01013784, -0.29215148, 0.0257933 , 0.08701295,

-0.02425266, 0.13502946, 0.02853448])]

進行識別時,將已有特徵值與檢測出的特徵值兩者之間計算歐式距離,設定閾值,大於閾值的不是同一人,小於閾值的為同一人

dist_ = numpy.linalg.norm(i - d_test)
numpy提供了linalg.norm方法來計算歐式距離,通常閾值設定在0.35即可

人臉識別之人臉檢測

人臉識別分為人臉檢測 人臉預處理 蒐集和學習人臉以及人臉識別四個部分,此部分將人臉檢測。本文基於opencv進行的。在opencv中常用的人臉檢測器有基於lbp的特徵檢測 基於haar的特徵檢測,兩者的區別 前者比後者快好幾倍且不需要許可協議,但很多haar檢測器需要許可協議。基於haar的臉部檢測...

Android實現人臉識別(人臉檢測)初識

title android實現人臉識別 人臉檢測 初識 categories 介紹 本篇文章主要介紹一下移動端android的人臉識別大致邏輯,後續文章會陸續放出乾貨,首先我們要明確兩個名詞 人臉檢測,即從一張 中或者乙個相機中,檢測有沒有人臉的出現,可以說在現在計算機視覺應用中,人臉識別尤為關鍵,...

dlib OpenCV實現人臉檢測與識別

設定人臉檢測器 初始化網路,使用dlib face recognition resnet model v1.dat 載入要檢測的目標資料 將資料庫中人臉灰度影象放於神經網路中,獲得128個特徵值 採用正面人臉檢測 快但是無法檢測側臉,輸入影象必須是灰度圖 首先人臉對齊,每個人臉有68個普遍存在的特徵...