Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Face comparison (Not recognition or detection) using OpenCV and Keras?

First of all here is my github link for the question.

And here is my question:

I would like to do a face comparison function using Python. And I can successfully(?) recognize faces using OpenCV. Now, how do I do the comparison thing?

What I understand is this:

In general Machine learning approach, I need to gather lots of data about that particular person and finalize it using a CNN.

However, I just got 2 images, how do I do the comparison? Should I think it in terms of classification or clustering (Using KNN)?

Thank you very much in advance for all your help.

like image 945
Ellery Leung Avatar asked Sep 12 '17 04:09

Ellery Leung


People also ask

Is OpenCV good for face recognition?

OpenCV is a video and image processing library and it is used for image and video analysis, like facial detection, license plate reading, photo editing, advanced robotic vision, and many more.

Which algorithm is best for face detection?

The Eigen faces Algorithm is the most commonly used methods in the field of facial recognition.

How do you compare faces in Python?

Use compare_faces.py to compare two images of people to see if they are the same person.


3 Answers

You can use the idea of face-embeddings, which for example is proposed in the highly-cited paper FaceNet and implemented in OpenFace (which also comes pre-trained).

The general idea: take some preprocessed face (frontal, cropped, ...) and embedd it to some lower dimension with the characteristic, that similar faces in input should have low euclidean-distance in the output.

So in your case: use the embedding-CNN to map your faces to the reduced space (usually a vector of size 128) and calculate the distance as in the euclidean-space. Of course you also cluster faces then, but that's not your task.

The good thing here besides the general idea: openface is a nice implementation ready to use and it's homepage also explains the idea:

Use a deep neural network to represent (or embed) the face on a 128-dimensional unit hypersphere.

The embedding is a generic representation for anybody's face. Unlike other face representations, this embedding has the nice property that a larger distance between two face embeddings means that the faces are likely not of the same person.

This property makes clustering, similarity detection, and classification tasks easier than other face recognition techniques where the Euclidean distance between features is not meaningful.

They even have a comparison-demo here.

like image 106
sascha Avatar answered Oct 21 '22 23:10

sascha


You need to learn similarity metric for faces. It will allow to extract features good to distinguish different persons. Then you'll be able to find dissimilarity (distance) between them. You can read in more detail here for instance. kNN and such things are useful to find groups of similar faces, but it need to use features, extracted before.

like image 42
Andrey Smorodov Avatar answered Oct 22 '22 00:10

Andrey Smorodov


Use face_recognition library (compare faces feature) . It will compare encoding of face features and give you boolean in return.

like image 43
Nihat Quliyev Avatar answered Oct 21 '22 22:10

Nihat Quliyev