Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created August 11, 2018 09:19
Show Gist options
  • Save ghotz/e75b65ad6e040cd6cb836462d30eee48 to your computer and use it in GitHub Desktop.
Save ghotz/e75b65ad6e040cd6cb836462d30eee48 to your computer and use it in GitHub Desktop.
Describe local image with Azure Cognitive Services Computer Vision API in PowerShell
# Describe local image with Azure Cognitive Services Computer Vision API in PowerShell
$ComputerVisionAPILocation = "westeurope";
$ComputerVisionAPIURL = "https://$ComputerVisionAPILocation.api.cognitive.microsoft.com/vision/v2.0";
$ComputerVisionAPIKey = "YOUR_KEY_GOES_HERE";
$ComputerVisionAPIAnalyzeTemplateURL = ($ComputerVisionAPIURL + "//describe?maxCandidates={0}")
$maxCandidates = 10;
$ImageFilename = "C:\Temp\cognitive\20180804-104929-GH01C12-S00.jpg";
$Response = Invoke-WebRequest `
-Uri ($ComputerVisionAPIAnalyzeTemplateURL -f $maxCandidates) `
-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, "describe.json")) -Encoding UTF8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment