Created
August 12, 2018 10:50
-
-
Save ghotz/1e5439f6f748cc3d2602f9064595212b 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}") | |
| $ImageFilename = "C:\Temp\cognitive\20180805-120348-GH01C04-S00.jpg"; | |
| # Note: the aspect ratios for crop hints are 1:1, 4:3, 3:2 and 16:9 | |
| $AnnotateImageRequest = | |
| @{ | |
| requests = @{ | |
| image = @{ | |
| content = ([Convert]::ToBase64String([IO.File]::ReadAllBytes($ImageFilename))) | |
| } | |
| 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 = 5} | |
| 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 ([System.IO.Path]::ChangeExtension($ImageFilename, "annotate.json")) -Encoding UTF8; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment