Class: Google::Cloud::Vision::Annotation::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/vision/annotation/properties.rb

Overview

Properties

A set of properties about an image, such as the image's dominant colors.

See Image#properties.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
vision = gcloud.vision

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

properties = image.properties
properties.colors.count #=> 10

Defined Under Namespace

Classes: Color

Instance Method Summary collapse

Instance Method Details

#colorsArray<Color>

The image's dominant colors, including their corresponding scores.

Returns:

  • (Array<Color>)

    An array of the image's dominant colors.



55
56
57
58
59
60
# File 'lib/google/cloud/vision/annotation/properties.rb', line 55

def colors
  return [] unless @gapi.dominant_colors
  @colors ||= Array(@gapi.dominant_colors.colors).map do |c|
    Color.from_gapi c
  end
end

#to_aArray

Returns the object's property values as an array.

Returns:

  • (Array)


67
68
69
# File 'lib/google/cloud/vision/annotation/properties.rb', line 67

def to_a
  colors.map(&:rgb)
end

#to_hHash

Deeply converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


76
77
78
# File 'lib/google/cloud/vision/annotation/properties.rb', line 76

def to_h
  { colors: colors.map(&:to_h) }
end