Class: Gcloud::Vision::Annotation::Face::Bounds

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/vision/annotation/face.rb

Overview

# Bounds

Bounding polygons around the face.

See Gcloud::Vision::Annotation::Face.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

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

face.bounds.face.count #=> 4
face.bounds.face.first #=> #<Vertex (x: 153, y: 34)>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBounds

Returns a new instance of Bounds.



279
280
281
# File 'lib/gcloud/vision/annotation/face.rb', line 279

def initialize
  @gapi = {}
end

Instance Attribute Details

#gapiObject



275
276
277
# File 'lib/gcloud/vision/annotation/face.rb', line 275

def gapi
  @gapi
end

Class Method Details

.from_gapi(gapi) ⇒ Object

object.



360
361
362
# File 'lib/gcloud/vision/annotation/face.rb', line 360

def self.from_gapi gapi
  new.tap { |f| f.instance_variable_set :@gapi, gapi }
end

Instance Method Details

#faceObject

This bounding polygon is tighter than the #head, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any image annotation that detects the “amount of skin” visible in an image. It is not based on the landmarks, only on the initial face detection.



304
305
306
307
308
309
# File 'lib/gcloud/vision/annotation/face.rb', line 304

def face
  return [] unless @gapi["fdBoundingPoly"]
  @face ||= Array(@gapi["fdBoundingPoly"]["vertices"]).map do |v|
    Vertex.from_gapi v
  end
end

#headObject

The bounding polygon around the face. The coordinates of the bounding box are in the original image’s scale, as returned in ImageParams. The bounding box is computed to “frame” the face in accordance with human expectations. It is based on the landmarker results. Note that one or more x and/or y coordinates may not be generated in the BoundingPoly (the polygon will be unbounded) if only a partial face appears in the image to be annotated.



291
292
293
294
295
296
# File 'lib/gcloud/vision/annotation/face.rb', line 291

def head
  return [] unless @gapi["boundingPoly"]
  @head ||= Array(@gapi["boundingPoly"]["vertices"]).map do |v|
    Vertex.from_gapi v
  end
end

#inspectObject



353
354
355
# File 'lib/gcloud/vision/annotation/face.rb', line 353

def inspect
  "#<Bounds #{self}>"
end

#to_aArray

Returns the object’s property values as an array.

Returns:

  • (Array)


316
317
318
# File 'lib/gcloud/vision/annotation/face.rb', line 316

def to_a
  to_ary
end

#to_aryArray

Returns the object’s property values as an array.

Returns:

  • (Array)


325
326
327
# File 'lib/gcloud/vision/annotation/face.rb', line 325

def to_ary
  [head.map(&:to_a), face.map(&:to_a)]
end

#to_hHash

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

Returns:

  • (Hash)


334
335
336
# File 'lib/gcloud/vision/annotation/face.rb', line 334

def to_h
  to_hash
end

#to_hashHash

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

Returns:

  • (Hash)


343
344
345
# File 'lib/gcloud/vision/annotation/face.rb', line 343

def to_hash
  { head: head.map(&:to_h), face: face.map(&:to_h) }
end

#to_sObject



348
349
350
# File 'lib/gcloud/vision/annotation/face.rb', line 348

def to_s
  "(head: #{head.inspect}, face: #{face.inspect})"
end