Class: Google::Cloud::Vision::Annotation::Face::Bounds

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

Overview

Bounds

Bounding polygons around the face.

See Google::Cloud::Vision::Annotation::Face.

Examples:

require "google/cloud"

gcloud = Google::Cloud.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 Method Summary collapse

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.



279
280
281
282
283
284
# File 'lib/google/cloud/vision/annotation/face.rb', line 279

def face
  return [] unless @gapi.fd_bounding_poly
  @face ||= Array(@gapi.fd_bounding_poly.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.



266
267
268
269
270
271
# File 'lib/google/cloud/vision/annotation/face.rb', line 266

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

#to_aArray

Returns the object's property values as an array.

Returns:

  • (Array)


291
292
293
# File 'lib/google/cloud/vision/annotation/face.rb', line 291

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

#to_hHash

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

Returns:

  • (Hash)


300
301
302
# File 'lib/google/cloud/vision/annotation/face.rb', line 300

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