<!--:en-->Face Recognition with Ruby<!--:-->

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.

>>client.faces_detect(:urls => ['http://babybathreviews.com/wp-content/uploads/2011/01/How-to-choose-a-baby-bath.png'])

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

Detect Faces with Raw image data:

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

Detect and Recognize faces with user auth:

>> client.twitter_credentials = { :twitter_username => 'twitter_screen_name', :twitter_password => 'twitter_password' }
>> client.faces_recognize(:urls => ['http://test.com/1.jpg'], :uids => ['uiicor']) # will make request with twitter credentials

Hereby we are trying to recognize face with twitter credentials.

First we will have to initialize twitter credentials like this:

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

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.

Show Comments Hide Comments
  • http://mess110.myopenid.com/ Cristian

    Hi

    if you are interested in an open-source alternative, try http://detection.myvhost.de (sourcecode on github)

    To detect faces in image with the ruby gem at https://github.com/downloads/mess110/detection/rdetectionapi-0.0.1.gem

    [code]require 'rdetectionapi'
    puts RDetectionAPI::Detect.new("http://sphotos.ak.fbcdn.net/photos-ak-snc1/v272/12/29/1352704123/n1352704123_30009292_5638.jpg")[/code]

    Best regards,
    Cristian

  • http://twitter.com/joaomilho Juan Maiz

    is there any code samples with private namespaces, detect, train and recognize…?

  • Shanmukhakatta

    Thanks this article.Exactly I want this gem.

  • Honory

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

  • hjuskewycz

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