Face detection & recognition with Javascript

March 11, 2018 0 Comments

Face detection & recognition with Javascript



Antonio Russo
Mar 11, 2018 · 6 min read

Propelled into the mainstream discourse by Apple’s iPhone X, face recognition has the potential to become a prominent feature of future web applications.

Here’s a clue from Google Trends, which shows how interest towards this subject mirrors almost exactly that towards the iPhone X:

iPhoneX interest over time in 2017
Face Recognition interest over time in 2017

Javascript, Machine Learning & Computer Vision algorithms

In order to implement face recognition in our applications we need machine learning & computer vision algorithms.
Over the last few years new frameworks for machine learning & computer vision have sprung up across most used languages and environments, so what about javascript?

The backend approach

One of the de-facto industry standards when it comes to computer vision is OpenCV. (Open Source Computer Vision Library). OpenCV is an open source computer vision and machine learning software library released under a BSD license and built in optimised C++, with bindings available for C, Python and Java.

According to Vincent Mühler, who is working on bringing the library to the Node.js ecosystem through an asynchronous JavaScript interface,

the nature of javascript itself lacks the performance to implement Computer Vision tasks efficiently

Vincent’s opencv4nodejs package lets developers of web applications create OpenCV-powered HTTP APIs to provide browsers with the means to offload image recognition tasks to their backends.

The frontend approach

Despite our initial considerations about Javascript’s inherent performance issue, there’s a few pure-Javascript libraries that have successfully implemented computer vision tasks directly into the browser.

In fact, this article goes so far as to state that the days of OpenCV’s dominance are gone:

OpenCV […] supports C++, C, Python and Java interfaces. It has been designed to focus on real-time application and is widely used for sophisticated use cases (for example facial recognition).

With tracking.js, all those processings are happening on the client-side. In the browser. The days of server-side processing are gone.

Enter tracking.js, perhaps the most prominent library among those promising to get rid of server-side processing and to implement sophisticated computer vision algorithms natively into the browser.

Developed and maintained by Eduardo Lundgren, it weighs only ~7Kb and, according to its description, “enables you to do real-time color tracking, face detection and much more by using modern HTML5 specifications

So, are the days of OpenCV really over?
I do not think so. Although perfectly capable of face detection, for example, tracking.js can’t perform advanced tasks such as face recognition (…yet). Given its rapid pace of development and just how convenient it is to be able to work within the browser, tracking.js can definitely be a worthy alternative to and deserves to be mentioned and reviewed alongside its older cousin.

Tag cloud