Face Recognition with Ruby

———— DEPRECATED ————-

This post is no longer valid, since face.com was acquired by facebook and doesn’t provide an open API anymore.

We all know that we can search web pages for text, but there are services that go beyond a simple text search and use features like location and or image data. The hurdle relying on these features is that normally the end users have to enter manually the appropriate data. When was the last time you tagged people Facebook? Now think what if we have a system that helps us to automate the process of face recognition. Lets understand face recognition and how you can use it with Ruby.

What is Face Recognition?


Face Recognition uses feature extraction from facial points (like detecting where the eyes, nose, mouth etc are) within images or videos to recognize people. As you can image such a task isn’t trivial and requires a lot of know how. But the good news are that facial recognition just got a lot easier for developers to include in their applications. Face.com, a company that specializes in facial recognition, opened its platform APIs, allowing developers to integrate its facial recognition technology in third-party websites and applications.

Developers Get Facial Recognition API from Face.com

The face.com API uses REST-like interface. This means that all calls to the API are made over the Internet, using HTTP GET and POST requests to the face.com API server. Hence, any programming language that supports HTTP can be used to communicate with the service. Face.com has some common libraries to get you started.

How to use it with Ruby ?

Step 1: Get your API Key from http://developers.face.com/account. Don’t forget to add Facebook API and Secret Key as well as Twitter API Key And Secret Key. Keep them handy to use in your application.

Step 2: To use Face Recogonition API in Ruby we have to install the gem called face.
sudo gem install face

Step 3: Now using api_key and api_secret, you can access get_client method of API.
>> client = Face.get_client(:api_key => ‘your_api_key’, :api_secret => ‘your_api_secret’)

Face Detection using Face gem in Ruby

Face gem provides three different ways to detect faces in an image.

  1. Detect Faces with Urls
  2. Detect Faces with Raw image data
  3. Detect and Recognize faces with user auth

Lets understand with examples.

Detect Faces with Urls:

Suppose we want to detect face in the image located at this url. You will have to use faces_detect method as given below.

Could not embed GitHub Gist 865770: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

It will return photo detection output in the following way. Notice that you here you get face related information in a JSON format.

Could not embed GitHub Gist 865789: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Detect Faces with Raw image data:

To detect faces from Raw image data, you will have to use following.

Could not embed GitHub Gist 865790: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Detect and Recognize faces with user auth:

Could not embed GitHub Gist 865791: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Hereby we are trying to recognize face with twitter credentials.

First we will have to initialize twitter credentials like this:

Could not embed GitHub Gist 865796: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Step 2: To send the face recoginze request , write in the following way.

Could not embed GitHub Gist 865799: API rate limit exceeded for 178.79.134.61. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Note that uid is the id of the user on twitter.

Conclusion

The face gem provides facilty to detect faces from multi or single face images. Face gem is still under development. You can test it on face.com site. To get a feel for what is possible with the API you can browse some of the online examples, complete with source code, or play in the API sandbox. The face.com API has some decent documentation for those looking to dig deeper into the service, although the forums are fairly quiet at the moment.

5 thoughts on “Face Recognition with Ruby

  1. Any way you can deprecate this article, as face.com isn’t opening their service external anymore?

  2. I deprecated the article. thanks for pointing out that face.com doesn’t exist anymore

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>