esimov / pigo

Fast face detection, pupil/eyes localization and facial landmark points detection library in pure Go.
MIT License
4.39k stars 310 forks source link

Comparison of two face #47

Closed deepch closed 3 years ago

deepch commented 3 years ago

I use a stream of images and one of the tasks is to group faces, could you recommend a method for comparing faces.

esimov commented 3 years ago

One of the obvious question it pops up in my mind is by which terms do you want to compare faces? Object detection at the moment is not possible with Pigo, but is on the track (see https://github.com/esimov/pigo#todo). I'm asking because maybe I can advice you in certain direction.

deepch commented 3 years ago

I work with a video stream. And I get 25 frames per second. In real time The idea is to filter out duplicate faces.

To get just 1 person. I thought to use https://github.com/vitali-fedulov/images

but that doesn't fit. You can try to average the color, but this is also not a good solution.

as I understand it in other projects https://github.com/ageitgey/face_recognition

there are functions that make a hash out of a person, which can then be compared with other people and get the difference.

https://github.com/ageitgey/face_recognition/blob/55b5c136292dcd4a1f5953f3eb3181235086efab/face_recognition/api.py#L217

esimov commented 3 years ago

You need to filter out duplicate faces per frame or to filter out duplicate faces during a certain frame interval?

deepch commented 3 years ago

filter out duplicate faces during a certain frame interval

Ideally, I would like to have a faceDistance function

func faceDistance (face1, face2) int {

compares two faces and returns the identity coefficient precent 0-100

esimov commented 3 years ago

Currently there is no such functionality implemented in Pigo, but the basic "ingredients" are there for making it happen. One way this could be achieved is by combining a few techniques together like delaunay triangulation and face morphing, then we can compare the resulted face with the original one and if the coefficient is below a certain threshold the the two faces could be considered identical. Something like here: https://learnopencv.com/average-face-opencv-c-python-tutorial/. Of course this is a first approach which needs to be analyzed more in depth.

However the best option is still the object detection and description towards I'm focusing right now, by implementing the SURF and/or SIFT methods.

These are however long term objectives, which requires some time for integration, so right now I cannot offer you a working solution for your problem. I will investigate other options and keep you updated with my findings, but I would keep this thread open for suggestions and proposals.

deepch commented 3 years ago

Thank you, thanks to your work!

deepch commented 3 years ago

Please tell me where exactly can I get the data for triangulation? Maybe you have some minimal sample that could guide me?

deepch commented 3 years ago

+1) Write landmark Point []float32 +2) Use PIGO found face +-3) Encode rect to jpeg ;( and use dlib (slow) found face landmark
+4) Use Avx avx.EuclideanDistance(sampleIlia, current) https://en.wikipedia.org/wiki/Euclidean_distance

it work very slow ;) try use https://github.com/esimov/pigo/blob/master/examples/facial_landmark/flploc.go

esimov commented 3 years ago

It's obvious that using dlib for face detection is way slower, since it relies on C bindings. This is a also the case for the Python example you just pointed out, because it's a C binding.

Regarding your question about triangulation, be aware that there are no working solutions and examples currently available for this feature. The one suggested by me is a possible approach which can be followed. I have developed a tool for triangulating images, this could be a logical approach.

Unfortunately currently I do have a busy period and I could not really focus on this request, but as I mentioned the object detection is the next step.

deepch commented 3 years ago

Tell me what is the format of such files lp38 lp42 lp44 lp46? The idea is how can I add custom mark on the face? maybe there is some kind of convector xml to bin?

esimov commented 3 years ago

These are binary formats. What do you mean by adding custom mark on the face? You mean to have your custom classifier?

deepch commented 3 years ago

I wanted to make the jawlines to build a better comparison model.

deepch commented 3 years ago
Снимок экрана 2021-03-19 в 17 14 50

I am working on face comparison at the moment but not sure if I will have enough points.

yes, custom classifier

esimov commented 3 years ago

Currently only these facial landmark points are encoded into the cascade binary tree.

deepch commented 3 years ago

But can I take the cascade file from opencv and encode it to a binary format?

esimov commented 3 years ago

I'm afraid not, because they have different structure and by encoding into a binary format would not guarantee that the cascade tree structure would be preserved.