1

I am building a type of "person counter" that is getting face images from live video footage. If a new face is detected in some frame the program will count that face/person. I thus need a way to check if a particular face has already been detected.

I have tried using a training program to recognize a template image to avoid counting the same face multiple times but due to there being only one template, the system was massively inaccurate and slightly too slow to run for every frame of the feed.

To better understand the process: at the beginning, as a face is detected the frame is cropped and the (new) face is saved in a file location. Afterwards, faces detected in subsequent frames need to go through a process to detect whether a similar face has been detected before and exist in the database (if they do, they shouldn't get added to the database).

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
Jason Rieder
  • 177
  • 1
  • 2
  • 10

1 Answers1

0

One recipe to face (pun! ;) this could be, for every frame:

  • get all the faces for all the frames (with opencv you can detect those and crop them)
  • generate face embeddings for the faces collected (e.g. using a tool for the purpose <- most likely this is the pre-trained component you are looking for, and allows you to "condense" the face image into a vector)
  • add all the the so-obtained face embeddings to a list

With some pre-defined time interval, run a clustering algorithm (see also Face clustering using Chinese Whispers algorithm) on the list of face embeddings collected. This will allow to group together faces belonging to the same person, and thus count the people appearing in the video.

Once that clusters are consolidated, you could prune some of the faces belonging to the same clusters/persons (to save storage in case you wanted)

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
  • For a more elaborate plan, check out https://www.pyimagesearch.com/2018/07/09/face-clustering-with-python/. If you have access to cloud resources, you may also consider leveraging tools like https://azure.microsoft.com/en-us/services/cognitive-services/face/ – Davide Fiocco Oct 23 '19 at 16:43
  • so by your second bullet point where i need to generate face embedding using the tool you provided, well iv been looking through the examples provided and i cant seem to find any relevant code to " "condense" the face image into a vector" or perhaps i'm missing something... ? – Jason Rieder Oct 25 '19 at 15:35
  • I expected code snippets at https://github.com/ageitgey/face_recognition/blob/master/README.md#identify-faces-in-pictures to that job: face_image -> embedding ! I refer to the `encoding` variables. – Davide Fiocco Oct 25 '19 at 15:58