Last active
August 12, 2018 10:51
-
-
Save ghotz/eb4cab56d1b32a6d05609748592784ba to your computer and use it in GitHub Desktop.
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
# Analyze image by URL with Google Cloud Vision API in PowerShell | |
$CloudVisionAPIURL = "https://vision.googleapis.com/v1/images:annotate"; | |
$CloudVisionAPIKey = "YOUR_KEY_GOES_HERE"; | |
$CloudVisionAPIAnalyzeTemplateURL = ($CloudVisionAPIURL + "?key={0}") | |
# Note: the aspect ratios for crop hints are 1:1, 4:3, 3:2 and 16:9 | |
$AnnotateImageRequest = | |
@{ | |
requests = @{ | |
image = @{ | |
source = @{ | |
imageUri = "https://cloud.google.com/vision/images/rushmore.jpg" | |
} | |
} | |
features = @{type = "FACE_DETECTION"} ` | |
, @{type = "LANDMARK_DETECTION" } ` | |
, @{type = "LOGO_DETECTION" } ` | |
, @{type = "LABEL_DETECTION" } ` | |
, @{type = "SAFE_SEARCH_DETECTION" } ` | |
, @{type = "IMAGE_PROPERTIES" } ` | |
, @{type = "CROP_HINTS" } ` | |
, @{type = "WEB_DETECTION"; maxResults = 2} | |
imageContext = @{ | |
cropHintsParams = @{ aspectRatios = 1, 1.33333, 1.5, 1.77777 } | |
webDetectionParams = @{ includeGeoResults = "true" } | |
} | |
} | |
}; | |
$JSonAnnotateImageRequest = ConvertTo-Json $AnnotateImageRequest -Depth 10 | |
$Response = Invoke-WebRequest ` | |
-Uri ($CloudVisionAPIAnalyzeTemplateURL -f $CloudVisionAPIKey) ` | |
-Body $JSonAnnotateImageRequest ` | |
-ContentType "application/json" ` | |
-Method "Post" ` | |
-ErrorAction Stop ` | |
-UseBasicParsing; | |
$Response.Content | Out-File "C:\Temp\cognitive\rushmore.annotate.json" -Encoding UTF8; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment