Ukieweb

Diary

I write what I learn here

Face Recognition Using Microsoft Face Api

Face Recognition Using Microsoft Face Api

Have you wanted to create an application that uses face recognition and you did not know how to do it?

Microsoft has Face and Computer Vision APIs that will help you achieve this in a matter of minutes. Both of these APIs are cloud-based and provides the most advanced algorithms for face detection and recognition.Even better, there is a free version which allows 20 requests per minute.

NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using a free trial subscription key, you should not need to change this region.

Languages supported by Face Api include C#, cURL, Java, JavaScript, PHP, Pythonand Ruby. For online testing you can use Online Link.

In this post I describe how to use Face API with PHP

  1. First you need an Azure account Create one here. Create a new Cognitive Service resource (Make sure you choose West Central US as the resource location)

    Cognitive Service Resource

  2. Download your PHP sample code from here depending on the type of functionality you want (Face, Face List, Person, Person Group).

  3. Get your subscription keys from Microsoft here

  4. Enter your subscription key in the code and specify the parameters that you need to be returned by the API eg. age,gender . You must use the same region in your REST API call as you used to obtain your subscription For example, if you obtained your subscription keys from the westcentralus region, replace "westus" in the URI below with "westcentralus" https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect

  5. Ensure that you have Request2 installed and that your PHP server is running. Change the url that requires this file to point to the Request2 file. Set the body with the images you want to analyze. It should look like $request->setBody('{"url": "Link to Image.jpg"}'); If Request2 is not installed and you have Xampp and PHP installed, run the CMD as an administrator and run the command pear install http_request2

    Installing Reques2 Windows

  6. Your final code should look like this.

    Face API PHP Code

  7. Run your code on the browser. The response will be in **JSON **format

This can be implemented in other languages in applications that want to recognize peoples faces for the purpose of tagging them.

Leave your comments and questions below.

Happy coding!

0 Comments

To make a comment you have to login