Class: Gcloud::Vision::Annotation::Face::Features::Landmark

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

Overview

# Landmark

A face-specific landmark (for example, a face feature). Landmark positions may fall outside the bounds of the image when the face is near one or more edges of the image. Therefore it is NOT guaranteed that ‘0 <= x < width` or `0 <= y < height`.

See Gcloud::Vision::Annotation::Face::Features and Gcloud::Vision::Annotation::Face.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

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

face.features.to_h.count #=> 9
face.features.eyes.left.pupil
#=> #<Landmark (x: 190.41544, y: 84.4557, z: -1.3682901)>
face.features.chin.center
#=> #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLandmark



614
615
616
# File 'lib/gcloud/vision/annotation/face.rb', line 614

def initialize
  @gapi = {}
end

Instance Attribute Details

#gapiObject



610
611
612
# File 'lib/gcloud/vision/annotation/face.rb', line 610

def gapi
  @gapi
end

Class Method Details

.from_gapi(gapi) ⇒ Object

object.



720
721
722
# File 'lib/gcloud/vision/annotation/face.rb', line 720

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

Instance Method Details

#inspectObject



713
714
715
# File 'lib/gcloud/vision/annotation/face.rb', line 713

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

#to_aArray

Returns the object’s property values as an array.



676
677
678
# File 'lib/gcloud/vision/annotation/face.rb', line 676

def to_a
  to_ary
end

#to_aryArray

Returns the object’s property values as an array.



685
686
687
# File 'lib/gcloud/vision/annotation/face.rb', line 685

def to_ary
  [x, y, z]
end

#to_hHash

Converts object to a hash. All keys will be symbolized.



694
695
696
# File 'lib/gcloud/vision/annotation/face.rb', line 694

def to_h
  to_hash
end

#to_hashHash

Converts object to a hash. All keys will be symbolized.



703
704
705
# File 'lib/gcloud/vision/annotation/face.rb', line 703

def to_hash
  { x: x, y: y, z: z }
end

#to_sObject



708
709
710
# File 'lib/gcloud/vision/annotation/face.rb', line 708

def to_s
  "(x: #{x.inspect}, y: #{y.inspect}, z: #{z.inspect})"
end

#typeString

The landmark type code.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

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

face.features.forehead.type #=> "FOREHEAD_GLABELLA"

See Also:



637
638
639
# File 'lib/gcloud/vision/annotation/face.rb', line 637

def type
  @gapi.type
end

#xFloat

The X (horizontal) coordinate.



646
647
648
649
# File 'lib/gcloud/vision/annotation/face.rb', line 646

def x
  return nil unless @gapi.position
  @gapi.position.x
end

#yFloat

The Y (vertical) coordinate.



656
657
658
659
# File 'lib/gcloud/vision/annotation/face.rb', line 656

def y
  return nil unless @gapi.position
  @gapi.position.y
end

#zFloat

The Z (depth) coordinate.



666
667
668
669
# File 'lib/gcloud/vision/annotation/face.rb', line 666

def z
  return nil unless @gapi.position
  @gapi.position.z
end