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:

require "google/cloud"

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

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

landmark = image.landmark
landmark.score #=> 0.91912264
landmark.description #=> "Mount Rushmore"
landmark.mid #=> "/m/019dvv"
require "google/cloud"

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

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

 = image.
.score #=> 0.70057315
.description #=> "Google"
.mid #=> "/m/0b34hf"
require "google/cloud"

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

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

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

label = labels.first
label.score #=> 0.9481349
label.description #=> "person"
label.mid #=> "/m/01g317"

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.



157
158
159
160
161
162
# File 'lib/google/cloud/vision/annotation/entity.rb', line 157

def bounds
  return [] unless @gapi.bounding_poly
  @bounds ||= Array(@gapi.bounding_poly.vertices).map do |v|
    Vertex.from_gapi 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].



134
135
136
# File 'lib/google/cloud/vision/annotation/entity.rb', line 134

def confidence
  @gapi.confidence
end

#descriptionString

Entity textual description, expressed in the #locale language.

Returns:

  • (String)

    A description of the entity.



114
115
116
# File 'lib/google/cloud/vision/annotation/entity.rb', line 114

def description
  @gapi.description
end

#localeString

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

Returns:



105
106
107
# File 'lib/google/cloud/vision/annotation/entity.rb', line 105

def locale
  @gapi.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.



174
175
176
177
178
# File 'lib/google/cloud/vision/annotation/entity.rb', line 174

def locations
  @locations ||= Array(@gapi.locations).map do |l|
    Location.from_gapi 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:



93
94
95
# File 'lib/google/cloud/vision/annotation/entity.rb', line 93

def mid
  @gapi.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.



187
188
189
190
# File 'lib/google/cloud/vision/annotation/entity.rb', line 187

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

#scoreFloat

Overall score of the result.

Returns:

  • (Float)

    A value in the range [0, 1].



123
124
125
# File 'lib/google/cloud/vision/annotation/entity.rb', line 123

def score
  @gapi.score
end

#to_hHash

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

Returns:

  • (Hash)


197
198
199
200
201
202
# File 'lib/google/cloud/vision/annotation/entity.rb', line 197

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].



147
148
149
# File 'lib/google/cloud/vision/annotation/entity.rb', line 147

def topicality
  @gapi.topicality
end