Face Recognition with Xamarin

I am going to explain how to use Face Recognition API with mobile. We can detect, identify, analyze, organize, and tag faces in photos with this api.

I want to make sample with all Face API References but I start with Face Detect. Let’s see
https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237


You have to create Face Service in Marketplace then you can get keys at the resource management tab

I create a new Xamarin.Forms app with .netstandart library then I install Media nuget package.

You can check face api documentation and you can try in open api test console

Don’t forget to use your key in Ocp-Apim-Subscription-Key input

https://blogs.msdn.microsoft.com/kwill/2017/05/17/http-401-access-denied-when-calling-azure-cognitive-services-apis/

First of all I create my own VM architecture for our sample. If you have any question you can mail at me yigit@ozaksut.com.

I developed this project in 2 hours without Face API (XF architecture, plugins, etc..) but you know Azure Cognitive Services API implementation 5 min. max
  • Behaviors: BindableBehavior and Event To Command
  • Converters: Some usable converters and Event Converters
  • Helpers: Some usable helper classes
  • Models: API request and response classes and common classes
  • Pages: Pages
  • Provider: API Service Manager
  • Services: Dialog, Media, Navigation, etc..
  • ViewModels > Base: ViewModelBase and ViewModelLocator
  • ViewModels: ViewModels for Pages
  • Views: Popup Pages

Hint: If you want to create a new page, you need to know 3 rules

1-) Create Page in Pages folder
2-) Create ViewModel in ViewModels folder (Check RegisterDependencies method for it)
2.1-) If your page name MainPage, your ViewModel name should be MainPageViewModel (Check OnAutoWireViewModelChanged method for it)
3-) Add xmlns to you page
3.1-) xmlns:viewModelBase=”clr-namespace:FaceSample.ViewModels.Base;assembly=FaceSample”
viewModelBase:ViewModelLocator.AutoWireViewModel=”true”

You can check NavigationService class for Navigation architecture. I want to convert shell architecture this class with next push btw

You need to review FaceDetectRequest, FaceDetectResponse and FaceDetectUrlHelper classes for how to work with Face API. BaseAddress is https://westeurope.api.cognitive.microsoft.com/face/v1.0/

You have to select any attributes for api request. (select multiple if you want btw)

Buttons will appear in the attributes you selected

I chose age, gender, smile, glasses and emotion attributes in config page and I take my own picture with glasses

Source Code : https://github.com/ozaksuty/Face-Recognition-with-Xamarin

Have fun

Yiğit

Xamarin Developer, Consultant & Architect. Community Leader and Director of Xamarin Türkiye

Post A Reply