Skip to content

Instantly share code, notes, and snippets.

@ghotz
Last active August 15, 2018 17:39
Show Gist options
  • Save ghotz/eaa26c86f864721a3c69105b4be9720c to your computer and use it in GitHub Desktop.
Save ghotz/eaa26c86f864721a3c69105b4be9720c to your computer and use it in GitHub Desktop.
Face dection of local image 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";
$ImageFilename = "C:\Temp\cognitive\20180804-104929-GH01C12-S00.jpg";
$Response = Invoke-WebRequest `
-Uri ($ComputerVisionAPIAnalyzeTemplateURL -f $returnFaceId, $returnFaceLandmarks, $returnFaceAttributes) `
-Headers @{'Ocp-Apim-Subscription-Key' = $ComputerVisionAPIKey} `
-Body ([System.IO.File]::ReadAllBytes($ImageFilename)) `
-ContentType "application/octet-stream" `
-Method "Post" `
-ErrorAction Stop `
-UseBasicParsing;
$Response.Content | Out-File ([System.IO.Path]::ChangeExtension($ImageFilename, "face-detect.json")) -Encoding UTF8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment