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

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

Overview

# Face

The results of face detection.

See #faces and #face.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

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

face = image.face
face.confidence #=> 0.86162376

Defined Under Namespace

Classes: Angles, Bounds, Features, Likelihood

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFace

Returns a new instance of Face.



46
47
48
# File 'lib/gcloud/vision/annotation/face.rb', line 46

def initialize
  @gapi = {}
end

Instance Attribute Details

#gapiObject



42
43
44
# File 'lib/gcloud/vision/annotation/face.rb', line 42

def gapi
  @gapi
end

Class Method Details

.from_gapi(gapi) ⇒ Object



129
130
131
# File 'lib/gcloud/vision/annotation/face.rb', line 129

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

Instance Method Details

#anglesAngles

The angles of the face, including roll, yaw, and pitch.

Returns:



55
56
57
# File 'lib/gcloud/vision/annotation/face.rb', line 55

def angles
  @angles ||= Angles.from_gapi @gapi
end

#boundsBounds

The bounds of the face, including the polygons for the head and face.

Returns:



64
65
66
# File 'lib/gcloud/vision/annotation/face.rb', line 64

def bounds
  @bounds ||= Bounds.from_gapi @gapi
end

#confidenceFloat

The confidence of the facial detection.

Returns:

  • (Float)

    A value in the range [0, 1].



93
94
95
# File 'lib/gcloud/vision/annotation/face.rb', line 93

def confidence
  @gapi.detection_confidence
end

#featuresFeatures

The landmarks of the face, including the points for the eyes, ears, nose and mouth.

Returns:



74
75
76
# File 'lib/gcloud/vision/annotation/face.rb', line 74

def features
  @features ||= Features.from_gapi @gapi
end

#inspectObject



123
124
125
# File 'lib/gcloud/vision/annotation/face.rb', line 123

def inspect
  "#<#{self.class.name} #{self}>"
end

#likelihoodLikelihood

The likelihood of the facial detection, including joy, sorrow, anger, surprise, under_exposed, blurred, and headwear.

Returns:



84
85
86
# File 'lib/gcloud/vision/annotation/face.rb', line 84

def likelihood
  @likelihood ||= Likelihood.from_gapi @gapi
end

#to_hHash

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

Returns:

  • (Hash)


102
103
104
# File 'lib/gcloud/vision/annotation/face.rb', line 102

def to_h
  to_hash
end

#to_hashHash

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

Returns:

  • (Hash)


111
112
113
114
# File 'lib/gcloud/vision/annotation/face.rb', line 111

def to_hash
  { angles: angles.to_h, bounds: bounds.to_h, features: features.to_h,
    likelihood: likelihood.to_h }
end

#to_sObject



117
118
119
120
# File 'lib/gcloud/vision/annotation/face.rb', line 117

def to_s
  # Keep console output low by not showing all sub-objects.
  "(angles, bounds, features, likelihood)"
end