Google Cloud Vision API - newapplesho/google-api-smalltalk-client GitHub Wiki

https://cloud.google.com/vision

Installation

Metacello new
    baseline: 'GoogleAPI';
    repository: 'github://newapplesho/google-api-smalltalk-client:v0.1/pharo-repository';
    load.

Set up an API key

Create browser API key. https://cloud.google.com/vision/docs/auth-template/cloud-api-auth

CloudVisionSettings default apiKey:'Your browser API key'.

Optical Character Recognition

cvImage := CloudVisionImage new. 
cvImage url: 'http://www.seaside.st/files/3d/7g2rn53ickp4mxkfjn32kwgx8xpgmm/seaside-s.png'.
cvFeature := CloudVisionFeature textDetection.
cvFeature maxResults: 5.
imageRequest := CloudVisionAnnotateImageRequest new.
imageRequest image: cvImage.
imageRequest features: {cvFeature}.
CloudVisionService new annotate: imageRequest. "print it"

Example Response.

{"responses":[{"textAnnotations":[{"locale":"en","boundingPoly":{"vertices":[{"y":4},{"x":196,"y":4},{"x":196,"y":93},{"y":93}]},"description":"Seaside\nseaside*\n"},{"boundingPoly":{"vertices":[{"x":1,"y":52},{"x":150,"y":12},{"x":160,"y":52},{"x":12,"y":92}]},"description":"Seaside"},{"boundingPoly":{"vertices":[{"x":3,"y":22},{"x":162,"y":22},{"x":162,"y":93},{"x":3,"y":93}]},"description":"seaside"},{"boundingPoly":{"vertices":[{"x":162,"y":4},{"x":197,"y":4},{"x":197,"y":37},{"x":162,"y":37}]},"description":"*"}]}]}

Label Detection

cvImage := CloudVisionImage new. 
cvImage url: 'https://avatars3.githubusercontent.com/u/5142851?v=3&s=460'.
cvFeature := CloudVisionFeature labelDetection.
cvFeature maxResults: 5.
imageRequest := CloudVisionAnnotateImageRequest new.
imageRequest image: cvImage.
imageRequest features: {cvFeature}.
CloudVisionService new annotate: imageRequest. "print it"

Example Response.

{"responses":[{"labelAnnotations":[{"score":0.91715133,"mid":"/m/05vyk","description":"pianist"},{"score":0.91508633,"mid":"/m/09jwl","description":"musician"},{"score":0.91025084,"mid":"/m/01g317","description":"person"},{"score":0.90466952,"mid":"/m/04szw","description":"musical instrument"},{"score":0.88851243,"mid":"/m/05r5c","description":"piano"}]}]}