Search code examples
ruby-on-railsrubygoogle-cloud-vision

uninitialized constant Google::Cloud::Vision::ImageAnnotator


Running this example https://cloud.google.com/vision/docs/face-tutorial?hl=zh-tw

by rails on 'google-cloud-vision', '~> 0.31.0'

got the error

uninitialized constant Google::Cloud::Vision::ImageAnnotator

here's the code

require "google/cloud/vision"


project_id = 'xxxxxx'


vision = Google::Cloud::Vision.new project: project_id


image_annotator = Google::Cloud::Vision::ImageAnnotator.new

Solution

  • It turns out that the error was caused because I haven't use the latest version of gcloud-vision(0.32.x)

    the way to do what I wanna do in gcloud-vision(0.31.0) is

    image = vision.image "path/to/face.jpg"
    
    face = image.face
    

    instead of using class

    Google::Cloud::Vision::ImageAnnotator