INSPIRIT
  • About us
  • Consulting
  • Support
  • Training
  • Join us
  • News
  • Contact
  • On Focus
  • EN
    • EN
    • BG
  • Menu Menu

How to use the Microsoft Face API in PowerBI

June 18, 2019/by adm1n
Using Cognitive Services as part of PowerBI dataflows has been made really easy, as long as you have Premium or Embedded capacity. But if you have only Pro/Free account or you need the Face Recognition API, then you need to work some magic to get through. In this post I’ll describe the steps to import data, returned as JSON from the Microsoft Face API and extract facial features into a nice little report. So let’s start with the setup – I have an Azure Blob container, where I have all my pictures and a deployed Face API, using the free tier. Then:

  • Import in PowerBI the contents of your Azure blob to get the full image path (hint: you’ll need to do some column merging to get the full path)
  • Make sure you’ve set proper permissions on the blob container
  • Open the Face API testing console and build your call to the Face API (hint: you need to use your API KEY from Azure Face deployment and a full path to an image, that the face API can access – I’ve done it with a sample image, uploaded in the Azure Blob folder). You API call should look like this:
  • Make sure you add/adjust all the properties you want from the API to detect i.e. “returnFaceAttributes = age,gender,smile,facialHair,glasses,emotion,makeup“
  • Now comes the difficult part – constructing the API call in PowerQuery and then transforming the input to meaningful data. The first step here is to open a Blank Query in Query Editor:
  • Then add the following text, where you need to replace the Ocp-Apim-Subscription-Key value with your API key:

let DataOutput = (ImageURL as text) =>
let
url = “https://northeurope.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,smile,facialHair,glasses,emotion,makeup&recognitionModel=recognition_02&returnRecognitionModel=false”,
body = “{ “”url””: “”” & ImageURL & “””}”,
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
Source = Json.Document(Web.Contents(url,[Headers = [#”Content-Type”=”application/json”,#”Ocp-Apim-Subscription-Key”=”XXXXXXXXXX YOUR API KEY HERE XXXXXXXXXXX”], Content = Text.ToBinary(body) ] )),
#”Converted to Table1″ = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#”Expanded Column1″ = Table.ExpandRecordColumn(#”Converted to Table1″, “Column1”, {“faceId”, “faceRectangle”, “faceAttributes”}, {“faceId”, “faceRectangle”, “faceAttributes”})
in
#”Expanded Column1″
in DataOutput

This creates a function, that accepts an image path and sends it to the Face API, which in turn provides a JSON result with all the faces, recognized on the picture.

  • Next step is to remove the Errors from the Data column (right click on the column -> Remove Errors) and then Expand the sub-tables (using the expand column in the top right corner of the Data column)
  • Result should be something like this:

And that’s it. Enjoy!

https://inspirit.bg/wp-content/uploads/2019/10/microsoft-face-03.jpg 1076 1614 adm1n https://inspirit.bg/wp-content/uploads/2025/01/Logo-new-2.png adm1n2019-06-18 10:23:002019-12-03 10:32:37How to use the Microsoft Face API in PowerBI
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You must be logged in to post a comment.

LATEST NEWS

  • 2020 – Година изпълнена с предизвикателстваDecember 10, 2020 - 11:00 am
  • Маргарита Наумова с MVP награда от Майкрософт за 10-та поредна годинаJuly 2, 2020 - 9:54 am
  • NEW: Expert Help as a Service – Consulting, advices and Help for BI, Reporting, Advanced Analytics, SQL Server On Premise and in AzureMay 14, 2020 - 9:17 am
  • SQL Server 2020 Discovery Day се отлагаApril 9, 2020 - 2:08 pm
  • Обученията на SQL Master Academy по време на извънредно положение въведено в страната във връзка с Covid-19March 16, 2020 - 4:04 pm

Follow us on Facebook

Bulgarian office

Sofia Park

Building 93,

ap. 2.1

Sofia, Bulgaria

0888 81 89 78

Norwegian office

12 Brynsveien Str.

Floor 2

0667 Oslo, Norway

+47 919 299 12

SQL Server 2019 Discovery Day wrap-upExciting data platform announcements at Microsoft Ignite 2019
Scroll to top