Last active
August 15, 2018 17:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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