Azure Face-API and Logic App (Serverless)

Blogs , , , , , 0 Comments


Yeah! Playtime with Azure Face-API and Logic Apps! 🙂

Both are really cool stuff to build absolutly great things! In my opinion they are great toolboxes (especially Logic Apps) in which you can perform your crativity!
Just let me summarise what Logic App are:

Logic Apps provide a way to simplify and implement scalable integrations and workflows in the cloud. It provides a visual designer to model and automate your process as a series of steps known as a workflow. There are many connectors across the cloud and on-premises to quickly integrate across services and protocols. A logic app begins with a trigger (like ‘When an account is added to Dynamics CRM’) and after firing can begin many combinations actions, conversions, and condition logic.

^^Just a Copy-Paste from the Azure documentation site; I couldn’t explain it better. 😉

“Serverless” means that you, as a developer, do not have to worry about servers and their configuration or deployment. Azure will do all that and combines the bits and pieces!

With Logic Apps you will have tons of pre-defined ‘triggers’ and ‘actions’. Check all triggers and actions availible:
If you are already known with IFTTT or Microsoft Flow, Logic Apps are the same, but totally focused on interaction with Azure Resources (in terms of Triggers, Actions and Conditions). See example of a Logic App ‘Flow’:

So, and what is the Face-API all about? In short: It’s a API build by Microsoft and availible in Azure in which you can Detect and Indentify faces on Photos and/or (realtime) video!

Lets start! and create a ‘Serverless’ Face-detection-logic-app! WoW 🙂

The scenario:

I will show you how to create a simple Logic App which detects Face(s) on photo’s which are uploaded to a Azure Storage Account (blob). It will store the detection information (results) in a Azure SQL Database when Face(s) are detected by the Face-API.  All this, is build with the following Azure Resources:

  • 1x Azure Storage Account (LRS, Standard)
  • 1x Logic App
  • 1x Face-API
  • 1x Azure SQL Database

Logic App Flow:

  1. Trigger => ‘When new items are uploaded to a Azure Storage Account’, in a specified Container.
  2. Condition => Check if the new item (blob) has a content type which begins with: ‘image/*’ (so you will have all image content type blobs)
  3. Action => Face-API ‘Detect Face’
  4. Action => store Face-API detection information in a Azure SQL Database/table for each face detected. information stored is:
    • Age
    • Gender
    • Glasses
    • Smile
    • StorageAccount URL
    • Filename (Path)
    • FaceID

Let’s do IT!

First create a Standard Azure Storage Account with LRS. And create a Container to store the images in. For demo purpose only I have configured the Container with Public Blob Access. I have named the container: ‘images’

So, your Azure Storage Account is all set! Now create a Face-API:

Choose a pricing tier. For demo, the F0 (FREE) will be ok! 😉

When the Face-API is create, go into the settings and select ‘Keys’. Copy, or make note of the Keys. you will need them when creating the Logic App.

Now create a Logic App:

And finally create a Azure SQL Database:

For this demo I have created a small Database, a ‘Basic’ database with 5 DTU’s and max. 100MB will do just fine.
Now create a Table within the Database. I have used Visual Studio 2017 but you could also use a T-SQL Query within the Azure Portal (still in preview).

SQL Query:

SQL Query within the Azure Portal:

Visual Studio 2017:

Now all the resources are created! lets put it all together into a Logic App! Go to the Logic App Resource and open it:

Choose ‘Blank Logic App’, in the ‘Searchbar’ search for ‘Blob’ to create a Trigger ‘When one or more blobs are added or modified’

Select your Storage Account and give it a connection name:

Select the container you already had created and specify a Frequency interval.

Click on ‘New Step’ and select ‘Add a Condition’ so we can specify that we only want blobs with a content type of ‘Image’:

Notice the ‘Dynamic content’ which will Always be populated with the results (output) of the previous step(s). Select ‘MediaType’:

Select ‘Start with’ in the Pull-down menu and add ‘image/’ as the value:

Click ‘Add Action’ and search for ‘Face’. Choose ‘Face API – Detect Faces’:

Give it a connection name and paste your ‘API Key’ (The Access key from the Face-API resource):

Because the ‘Dynamic content’ does not provide the full URL to the storage blob but only the ‘Path’ (that is: Container + Folder + filename) we have to construct it with a string as shown below:

Click ‘Add Action’ and search for ‘SQL’. Choose ‘Insert row’ and fillin the details (Connection name, SQL Server/Database and username/password):

For each item select the corresponding ‘Dynamic content’ object.
Note: The ‘For Each’ action will be automatically create because a image could have more than one Face detected. So, just add those Dynamic content objects and the Logic App will notify you that it will create a ‘For Each’ loop.

Done! Now save the Logic app and RUN it! 🙂 Upload some images to the Blob container and check your SQL Database:
Note: To detect faces; the maximum size of a image is 4MB!! 


This was just a small example/demo to show you the possibilities of Azure Logic Apps, Face-API, Storage Account and a SQL Database. Now imagine what you can create/develop with all this ‘magic’ stuff!! 🙂

This example can be easly extended with a wide range of Azure services:

  • Create a Web Apps to extend it with a front-end website
  • Train your Face-API to be able to indentify the Faces
  • Create more actions and conditions to the Logic App
  • Azure functions
  • etc. etc. incl. lots of your own creativity! 😉




Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.