python相簿中的人臉聚類 Dlib 人臉聚類

2021-10-11 20:18:06 字數 2177 閱讀 7961

人臉聚類

人臉聚類屬於無監督學習. 當你有許多未標記的待分類的**時, 使用人臉聚類是非常有用的. 其 python 指令碼位於 /python_examples/face_clustering.py.

待分類目錄下有兩張神仙的肖像和兩張觀海的肖像, 使用如下**可以將神仙和觀海分開.

import os

import sys

import dlib

import skimage.draw

import skimage.io

predictor_path = 'shape_predictor_68_face_landmarks.dat'

face_rec_model_path = 'dlib_face_recognition_resnet_model_v1.dat'

faces_folder_path = sys.ar**[1]

detector = dlib.get_frontal_face_detector()

sp = dlib.shape_predictor(predictor_path)

facerec = dlib.face_recognition_model_v1(face_rec_model_path)

face_results =

for entry in os.scandir(faces_folder_path):

print(f'processing file: ')

img = skimage.io.imread(entry.path)

dets = detector(img, 1)

print("number of faces detected: {}".format(len(dets)))

for k, d in enumerate(dets):

shape = sp(img, d)

face_descriptor = facerec.compute_face_descriptor(img, shape)

'path': entry.path,

'det': d,

'shape': shape,

'descriptor': face_descriptor

labels = dlib.chinese_whispers_clustering([e['descriptor'] for e in face_results], 0.5)

num_classes = len(set(labels))

print("number of clusters: {}".format(num_classes))

for i, r in enumerate(face_results):

r['label'] = labels[i]

for e in face_results:

path = e['path']

d = e['det']

det = [d.top(), d.left(), d.bottom(), d.right()]

label = e['label']

print(label, path, det)

執行結果

Python基於OpenCV的人臉檢測並儲存

import cv2cv2.cascadeclassifier cv2.data.haarcascades haarcascade frontalface default.xml coding utf 8 import opencv的庫 import cv2 import os,math,opera...

基於Python的人臉識別和對比

github 位址 使用face recognition人臉識別庫檢測識別對比人臉。測試環境 python 3.6.4 windows 10 anaconda 4.5.12 dlib 19.16.0 face recognition 1.2.3 cmake 3.13.2 visual studio ...

python基於opencv最簡單的人臉檢測01

準備開始學習opencv4 opencv 的意思就是開放的計算機視覺,是乙個基於c 的超實用庫 執行此 需要安裝opencv庫 可以通過pip安裝 以下是基於opencv自帶的人臉檢測模型的人臉檢測 import cv2 as cv defplot rectangle image,faces for...