Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created August 15, 2018 17:38
Show Gist options
  • Save ghotz/ca18b61d1f3a03438e1c80f71db2e3ea to your computer and use it in GitHub Desktop.
Save ghotz/ca18b61d1f3a03438e1c80f71db2e3ea to your computer and use it in GitHub Desktop.
Face detection by URL with Azure Cognitive Services Computer Vision API in PowerShell
$ComputerVisionAPILocation = "westeurope";
$ComputerVisionAPIURL = "https://$ComputerVisionAPILocation.api.cognitive.microsoft.com/face/v1.0";
$ComputerVisionAPIKey = "YOUR_KEY_GOES_HERE";
$ComputerVisionAPIAnalyzeTemplateURL = ($ComputerVisionAPIURL + "/detect?returnFaceId={0}&returnFaceLandmarks={1}&returnFaceAttributes={2}")
$returnFaceId = "true";
$returnFaceLandmarks = "true";
$returnFaceAttributes = "age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise";
$Param = @{"url"="https://cloud.google.com/vision/images/rushmore.jpg"}
$Response = Invoke-WebRequest `
-Uri ($ComputerVisionAPIAnalyzeTemplateURL -f $returnFaceId, $returnFaceLandmarks, $returnFaceAttributes) `
-Headers @{'Ocp-Apim-Subscription-Key' = $ComputerVisionAPIKey} `
-Body (ConvertTo-Json $Param) `
-ContentType "application/json" `
-Method "Post" `
-ErrorAction Stop `
-UseBasicParsing;
$Response.Content | Out-File "C:\Temp\cognitive\rushmore.face-detect.json" -Encoding UTF8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment