Using Face API in C# provides an face recognition API that offers the developers and publishers to automatically detect and recognise faces in photos using robust , free REST API .

This was one of the API that we used during the Yahoo OpenHack India 2011 for our App called “Face the Music” . The application developed captures the human emotion (facial expression) via the webcam and plays the music based on the emotion. The emotion can be happy, frustrated, sad, surprised, scary, dreamy etc.

The API allows the third party developers to create Applications that use the’s Face Recognition technology.

The officially supports the following Client Libraries

  • PHP Client Library

Interestingly , there are community Client Libraries too which includes C# which was developed by Daren Willman


To use this C# Client Library is also easier . Just include the .cs file to your project .

The C# API has the classes FaceRestAPI and FaceRestAPI.FaceAPI which can be used to retreive the attributes of the picture .

Make sure that your register and get your API Keys

Once you get your API Key , you can then include the following code to get the attributes

FaceRestAPI obj = new FaceRestAPI(apikey,secretkey, "", true, "xml", "", "");
string userid = "" // registeredemailID;
List<string> str = new List<string>();

List<string> urls = new List<string>();
urls.Add(UrlFile); // http location of the picture
FaceRestAPI.FaceAPI objFaces = obj.faces_detect(urls, string.Empty, null, null);

The faces_detect will return the FaceAPI Object which includes a property rawdata .This is the Data for whcih the format was supplied for . In the above example , we use xml , so the FaceAPI.RawData will contain the XML string . It is also possible to get the data in Json format .

Just Load the Data in to the XmlDocument Object and you can retreive all the necessary properties .

To retreive the mood of the person , retreive the attribute “mood” from the XML string

XmlDocument xml = new XmlDocument();

XmlNodeList xnList = xml.SelectNodes(@"response/photos/photo/tags/tag/attributes/mood");
foreach (XmlNode xn in xnList)
   mood = xn["value"].InnerText;
   confidence = xn["confidence"].InnerText;

To check if the person in the picture is wearing the Glasses , use the Glasses node

XmlDocument xml = new XmlDocument();
XmlNodeList xnList3 = xml.SelectNodes(@"response/photos/photo/tags/tag/attributes/glasses");
foreach (XmlNode xn in xnList3)
   lblGlasses.Text = lblGlasses.Text + xn["value"].InnerText;

Similarly , to find the gender , use the gender tag of the XML data

XmlDocument xml = new XmlDocument();
XmlNodeList xnList1 = xml.SelectNodes(@"response/photos/photo/tags/tag/attributes/gender");
foreach (XmlNode xn in xnList1)
   lblGender.Text =lblGender.Text+ xn["value"].InnerText;

The also includes some samples and examples which can be found in the below location

  • Tagger-Widget
  • Tools
  • Poster Yourself
  • CelebrityFindr
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.


  1. Using Face API in C# | ProgramInDotnet August 8, 2011 Reply
    • Mario Fraiß November 16, 2012 Reply
  2. Teodora R. MS July 5, 2014 Reply

Leave a Reply to Mario Fraiß Cancel reply


Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Introduction to Dataset API Meetup
Bangalore Apache Spark Meetup is hosting an event on Introduction to Dataset API on February 13 , 20...