———— 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.
- Detect Faces with Urls
- Detect Faces with Raw image data
- 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.
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:
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.
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.