Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Face recognition

Ilya Kochankov edited this page Oct 22, 2021 · 4 revisions

Photo face recognition using opencv

Use Haar cascades for face detection (opencv/build/etc/haarcascades)

face_cascade_db = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")

Detect face

face = face_cascade_db.detectMultiScale(img, 1.1, 19)

Square face (Only for the demo)

for (x,y,w,h) in face: cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2)

Skin tone extractor

Use KMeans from sklearn to make color-clusters

k_means = KMeans(n_clusters=1)

Create k_means

k_means.fit(image.reshape(image.shape[0] * image.shape[1], 3))

Fit to k_means image (with flatten shape in 0 and 1 axis)

tuple(map(int, self.k_means.cluster_centers_[0]))

Get color in BGR format