Class: Google::Cloud::Vision::Annotation::Entity

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

Overview

Entity

Represents characteristics of an entity detected in an image. May describe a real-world entity such as a person, place, or thing. May be identified with an entity ID as an entity in the Knowledge Graph (KG).

Examples:

In landmark detection:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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

landmark = image.landmark
landmark.score #=> 0.9191226363182068
landmark.description #=> "Mount Rushmore"
landmark.mid #=> "/m/019dvv"

In logo detection:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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

 = image.
.score #=> 0.7005731463432312
.description #=> "Google"
.mid #=> "/m/0b34hf"

In label detection:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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

labels = image.labels
labels.count #=> 4

label = labels.first
label.score #=> 0.9481348991394043
label.description #=> "stone carving"
label.mid #=> "/m/02wtjj"

See Also:

Instance Method Summary collapse

Instance Method Details

#boundsArray<Vertex>

Image region to which this entity belongs. Not filled currently for labels detection.

Returns:

  • (Array<Vertex>)

    An array of vertices.



154
155
156
157
158
159
# File 'lib/google/cloud/vision/annotation/entity.rb', line 154

def bounds
  return [] unless @grpc.bounding_poly
  @bounds ||= Array(@grpc.bounding_poly.vertices).map do |v|
    Vertex.from_grpc v
  end
end

#confidenceFloat

The accuracy of the entity detection in an image. For example, for an image containing 'Eiffel Tower,' this field represents the confidence that there is a tower in the query image.

Returns:

  • (Float)

    A value in the range [0, 1].



131
132
133
# File 'lib/google/cloud/vision/annotation/entity.rb', line 131

def confidence
  @grpc.confidence
end

#descriptionString

Entity textual description, expressed in the #locale language.

Returns:

  • (String)

    A description of the entity.



111
112
113
# File 'lib/google/cloud/vision/annotation/entity.rb', line 111

def description
  @grpc.description
end

#localeString

The language code for the locale in which the description is expressed.

Returns:



102
103
104
# File 'lib/google/cloud/vision/annotation/entity.rb', line 102

def locale
  @grpc.locale
end

#locationsArray<Location>

The location information for the detected entity. Multiple Location elements can be present since one location may indicate the location of the scene in the query image, and another the location of the place where the query image was taken. Location information is usually present for landmarks.

Returns:

  • (Array<Location>)

    An array of locations containing latitude and longitude.



171
172
173
174
175
# File 'lib/google/cloud/vision/annotation/entity.rb', line 171

def locations
  @locations ||= Array(@grpc.locations).map do |l|
    Location.from_grpc l.lat_lng
  end
end

#midString

Opaque entity ID. Some IDs might be available in Knowledge Graph (KG).

Returns:

  • (String)

    The opaque entity ID.

See Also:



90
91
92
# File 'lib/google/cloud/vision/annotation/entity.rb', line 90

def mid
  @grpc.mid
end

#propertiesHash

Some entities can have additional optional Property fields. For example a different kind of score or string that qualifies the entity. present for landmarks.

Returns:

  • (Hash)

    A hash containing property names and values.



184
185
186
187
# File 'lib/google/cloud/vision/annotation/entity.rb', line 184

def properties
  @properties ||=
    Hash[Array(@grpc.properties).map { |p| [p.name, p.value] }]
end

#scoreFloat

Overall score of the result.

Returns:

  • (Float)

    A value in the range [0, 1].



120
121
122
# File 'lib/google/cloud/vision/annotation/entity.rb', line 120

def score
  @grpc.score
end

#to_hHash

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

Returns:

  • (Hash)


194
195
196
197
198
199
# File 'lib/google/cloud/vision/annotation/entity.rb', line 194

def to_h
  { mid: mid, locale: locale, description: description,
    score: score, confidence: confidence, topicality: topicality,
    bounds: bounds.map(&:to_h), locations: locations.map(&:to_h),
    properties: properties }
end

#topicalityFloat

The relevancy of the ICA (Image Content Annotation) label to the image. For example, the relevancy of 'tower' to an image containing 'Eiffel Tower' is likely higher than an image containing a distant towering building, though the confidence that there is a tower may be the same.

Returns:

  • (Float)

    A value in the range [0, 1].



144
145
146
# File 'lib/google/cloud/vision/annotation/entity.rb', line 144

def topicality
  @grpc.topicality
end