google-cloud-vision 0.31.0 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -9
- data/LICENSE +1 -1
- data/README.md +94 -0
- data/lib/google/cloud/vision.rb +200 -535
- data/lib/google/cloud/vision/v1.rb +129 -55
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/image_annotator.rb +9 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search.rb +88 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search_service.rb +539 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/text_annotation.rb +3 -3
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/web_detection.rb +2 -1
- data/lib/google/cloud/vision/{version.rb → v1/doc/google/protobuf/empty.rb} +13 -6
- data/lib/google/cloud/vision/v1/doc/google/protobuf/field_mask.rb +230 -0
- data/lib/google/cloud/vision/v1/doc/google/protobuf/timestamp.rb +109 -0
- data/lib/google/cloud/vision/v1/geometry_pb.rb +1 -0
- data/lib/google/cloud/vision/v1/helpers.rb +972 -0
- data/lib/google/cloud/vision/v1/image_annotator_client.rb +4 -4
- data/lib/google/cloud/vision/v1/image_annotator_pb.rb +5 -0
- data/lib/google/cloud/vision/v1/image_annotator_services_pb.rb +2 -1
- data/lib/google/cloud/vision/v1/product_search_client.rb +1337 -0
- data/lib/google/cloud/vision/v1/product_search_client_config.json +116 -0
- data/lib/google/cloud/vision/v1/product_search_pb.rb +45 -0
- data/lib/google/cloud/vision/v1/product_search_service_pb.rb +191 -0
- data/lib/google/cloud/vision/v1/product_search_service_services_pb.rb +224 -0
- data/lib/google/cloud/vision/v1p3beta1.rb +233 -0
- data/lib/google/cloud/vision/v1p3beta1/credentials.rb +42 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/geometry.rb +72 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/image_annotator.rb +763 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search.rb +154 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search_service.rb +533 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/text_annotation.rb +254 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/web_detection.rb +101 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/longrunning/operations.rb +93 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/any.rb +130 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/field_mask.rb +230 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/timestamp.rb +109 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/wrappers.rb +90 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/rpc/status.rb +84 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/type/color.rb +156 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/type/latlng.rb +65 -0
- data/lib/google/cloud/vision/v1p3beta1/geometry_pb.rb +43 -0
- data/lib/google/cloud/vision/v1p3beta1/helpers.rb +972 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_client.rb +302 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_client_config.json +36 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_pb.rb +304 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_services_pb.rb +55 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_client.rb +1351 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_client_config.json +116 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_pb.rb +64 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_service_pb.rb +191 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_service_services_pb.rb +222 -0
- data/lib/google/cloud/vision/v1p3beta1/text_annotation_pb.rb +94 -0
- data/lib/google/cloud/vision/v1p3beta1/web_detection_pb.rb +51 -0
- metadata +53 -122
- data/AUTHENTICATION.md +0 -179
- data/CHANGELOG.md +0 -109
- data/CODE_OF_CONDUCT.md +0 -40
- data/CONTRIBUTING.md +0 -188
- data/LOGGING.md +0 -32
- data/OVERVIEW.md +0 -202
- data/TROUBLESHOOTING.md +0 -37
- data/lib/google-cloud-vision.rb +0 -146
- data/lib/google/cloud/vision/annotate.rb +0 -303
- data/lib/google/cloud/vision/annotation.rb +0 -553
- data/lib/google/cloud/vision/annotation/crop_hint.rb +0 -126
- data/lib/google/cloud/vision/annotation/entity.rb +0 -225
- data/lib/google/cloud/vision/annotation/face.rb +0 -1497
- data/lib/google/cloud/vision/annotation/normalized_vertex.rb +0 -76
- data/lib/google/cloud/vision/annotation/object_localization.rb +0 -115
- data/lib/google/cloud/vision/annotation/properties.rb +0 -220
- data/lib/google/cloud/vision/annotation/safe_search.rb +0 -153
- data/lib/google/cloud/vision/annotation/text.rb +0 -1015
- data/lib/google/cloud/vision/annotation/vertex.rb +0 -91
- data/lib/google/cloud/vision/annotation/web.rb +0 -420
- data/lib/google/cloud/vision/credentials.rb +0 -57
- data/lib/google/cloud/vision/image.rb +0 -832
- data/lib/google/cloud/vision/location.rb +0 -98
- data/lib/google/cloud/vision/project.rb +0 -367
- data/lib/google/cloud/vision/service.rb +0 -83
@@ -1,126 +0,0 @@
|
|
1
|
-
# Copyright 2017 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
require "google/cloud/vision/annotation/vertex"
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Cloud
|
20
|
-
module Vision
|
21
|
-
class Annotation
|
22
|
-
##
|
23
|
-
# # CropHint
|
24
|
-
#
|
25
|
-
# A single crop hint that is used to generate new crops when serving
|
26
|
-
# images.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# require "google/cloud/vision"
|
30
|
-
#
|
31
|
-
# vision = Google::Cloud::Vision.new
|
32
|
-
#
|
33
|
-
# image = vision.image "path/to/face.jpg"
|
34
|
-
#
|
35
|
-
# crop_hints = image.crop_hints
|
36
|
-
# crop_hints.count #=> 1
|
37
|
-
# crop_hint = crop_hints.first
|
38
|
-
#
|
39
|
-
# crop_hint.bounds.count #=> 4
|
40
|
-
# crop_hint.bounds[0].x #=> 1
|
41
|
-
# crop_hint.bounds[0].y #=> 0
|
42
|
-
# crop_hint.bounds[1].x #=> 511
|
43
|
-
# crop_hint.bounds[1].y #=> 0
|
44
|
-
# crop_hint.bounds[2].x #=> 511
|
45
|
-
# crop_hint.bounds[2].y #=> 383
|
46
|
-
# crop_hint.bounds[3].x #=> 0
|
47
|
-
# crop_hint.bounds[3].y #=> 383
|
48
|
-
#
|
49
|
-
# crop_hint.confidence #=> 1.0
|
50
|
-
# crop_hint.importance_fraction #=> 1.0399999618530273
|
51
|
-
#
|
52
|
-
class CropHint
|
53
|
-
##
|
54
|
-
# @private The Google::Cloud::Vision::V1::CropHint GRPC object.
|
55
|
-
attr_accessor :grpc
|
56
|
-
|
57
|
-
##
|
58
|
-
# @private Creates a new Entity instance.
|
59
|
-
def initialize
|
60
|
-
@grpc = nil
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# The bounding polygon for the crop region. The coordinates of the
|
65
|
-
# bounding box are in the original image's scale.
|
66
|
-
#
|
67
|
-
# @return [Array<Vertex>] An array of vertices.
|
68
|
-
#
|
69
|
-
def bounds
|
70
|
-
return [] unless @grpc.bounding_poly
|
71
|
-
@bounds ||= Array(@grpc.bounding_poly.vertices).map do |v|
|
72
|
-
Vertex.from_grpc v
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
##
|
77
|
-
# The confidence of this being a salient region.
|
78
|
-
#
|
79
|
-
# @return [Float] A value in the range [0, 1].
|
80
|
-
#
|
81
|
-
def confidence
|
82
|
-
@grpc.confidence
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# The fraction of importance of this salient region with respect to
|
87
|
-
# the original image.
|
88
|
-
#
|
89
|
-
# @return [Float]
|
90
|
-
#
|
91
|
-
def importance_fraction
|
92
|
-
@grpc.importance_fraction
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
97
|
-
#
|
98
|
-
# @return [Hash]
|
99
|
-
#
|
100
|
-
def to_h
|
101
|
-
{ bounds: bounds.map(&:to_h), confidence: confidence,
|
102
|
-
importance_fraction: importance_fraction }
|
103
|
-
end
|
104
|
-
|
105
|
-
# @private
|
106
|
-
def to_s
|
107
|
-
tmplt = "bounds: %i, confidence: %s, importance_fraction: %s"
|
108
|
-
format tmplt, bounds.count, confidence.inspect,
|
109
|
-
importance_fraction.inspect
|
110
|
-
end
|
111
|
-
|
112
|
-
# @private
|
113
|
-
def inspect
|
114
|
-
"#<#{self.class.name} #{self}>"
|
115
|
-
end
|
116
|
-
|
117
|
-
##
|
118
|
-
# @private New Annotation::Entity from a GRPC object.
|
119
|
-
def self.from_grpc grpc
|
120
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,225 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
require "google/cloud/vision/location"
|
17
|
-
require "google/cloud/vision/annotation/vertex"
|
18
|
-
|
19
|
-
module Google
|
20
|
-
module Cloud
|
21
|
-
module Vision
|
22
|
-
class Annotation
|
23
|
-
##
|
24
|
-
# # Entity
|
25
|
-
#
|
26
|
-
# Represents characteristics of an entity detected in an image. May
|
27
|
-
# describe a real-world entity such as a person, place, or thing. May be
|
28
|
-
# identified with an entity ID as an entity in the Knowledge Graph (KG).
|
29
|
-
#
|
30
|
-
# @see https://developers.google.com/knowledge-graph/ Knowledge Graph
|
31
|
-
#
|
32
|
-
# @example In landmark detection:
|
33
|
-
# require "google/cloud/vision"
|
34
|
-
#
|
35
|
-
# vision = Google::Cloud::Vision.new
|
36
|
-
#
|
37
|
-
# image = vision.image "path/to/landmark.jpg"
|
38
|
-
#
|
39
|
-
# landmark = image.landmark
|
40
|
-
# landmark.score #=> 0.9191226363182068
|
41
|
-
# landmark.description #=> "Mount Rushmore"
|
42
|
-
# landmark.mid #=> "/m/019dvv"
|
43
|
-
#
|
44
|
-
# @example In logo detection:
|
45
|
-
# require "google/cloud/vision"
|
46
|
-
#
|
47
|
-
# vision = Google::Cloud::Vision.new
|
48
|
-
#
|
49
|
-
# image = vision.image "path/to/logo.jpg"
|
50
|
-
#
|
51
|
-
# logo = image.logo
|
52
|
-
# logo.score #=> 0.7005731463432312
|
53
|
-
# logo.description #=> "Google"
|
54
|
-
# logo.mid #=> "/m/0b34hf"
|
55
|
-
#
|
56
|
-
# @example In label detection:
|
57
|
-
# require "google/cloud/vision"
|
58
|
-
#
|
59
|
-
# vision = Google::Cloud::Vision.new
|
60
|
-
#
|
61
|
-
# image = vision.image "path/to/landmark.jpg"
|
62
|
-
#
|
63
|
-
# labels = image.labels
|
64
|
-
# labels.count #=> 4
|
65
|
-
#
|
66
|
-
# label = labels.first
|
67
|
-
# label.score #=> 0.9481348991394043
|
68
|
-
# label.description #=> "stone carving"
|
69
|
-
# label.mid #=> "/m/02wtjj"
|
70
|
-
#
|
71
|
-
class Entity
|
72
|
-
##
|
73
|
-
# @private The EntityAnnotation GRPC object.
|
74
|
-
attr_accessor :grpc
|
75
|
-
|
76
|
-
##
|
77
|
-
# @private Creates a new Entity instance.
|
78
|
-
def initialize
|
79
|
-
@grpc = nil
|
80
|
-
end
|
81
|
-
|
82
|
-
##
|
83
|
-
# Opaque entity ID. Some IDs might be available in Knowledge Graph
|
84
|
-
# (KG).
|
85
|
-
#
|
86
|
-
# @see https://developers.google.com/knowledge-graph/ Knowledge Graph
|
87
|
-
#
|
88
|
-
# @return [String] The opaque entity ID.
|
89
|
-
#
|
90
|
-
def mid
|
91
|
-
@grpc.mid
|
92
|
-
end
|
93
|
-
|
94
|
-
##
|
95
|
-
# The language code for the locale in which the `description` is
|
96
|
-
# expressed.
|
97
|
-
#
|
98
|
-
# @return [String] The [ISO
|
99
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
100
|
-
# language code.
|
101
|
-
#
|
102
|
-
def locale
|
103
|
-
@grpc.locale
|
104
|
-
end
|
105
|
-
|
106
|
-
##
|
107
|
-
# Entity textual description, expressed in the {#locale} language.
|
108
|
-
#
|
109
|
-
# @return [String] A description of the entity.
|
110
|
-
#
|
111
|
-
def description
|
112
|
-
@grpc.description
|
113
|
-
end
|
114
|
-
|
115
|
-
##
|
116
|
-
# Overall score of the result.
|
117
|
-
#
|
118
|
-
# @return [Float] A value in the range [0, 1].
|
119
|
-
#
|
120
|
-
def score
|
121
|
-
@grpc.score
|
122
|
-
end
|
123
|
-
|
124
|
-
##
|
125
|
-
# The accuracy of the entity detection in an image. For example, for
|
126
|
-
# an image containing 'Eiffel Tower,' this field represents the
|
127
|
-
# confidence that there is a tower in the query image.
|
128
|
-
#
|
129
|
-
# @return [Float] A value in the range [0, 1].
|
130
|
-
#
|
131
|
-
def confidence
|
132
|
-
@grpc.confidence
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
# The relevancy of the ICA (Image Content Annotation) label to the
|
137
|
-
# image. For example, the relevancy of 'tower' to an image containing
|
138
|
-
# 'Eiffel Tower' is likely higher than an image containing a distant
|
139
|
-
# towering building, though the confidence that there is a tower may
|
140
|
-
# be the same.
|
141
|
-
#
|
142
|
-
# @return [Float] A value in the range [0, 1].
|
143
|
-
#
|
144
|
-
def topicality
|
145
|
-
@grpc.topicality
|
146
|
-
end
|
147
|
-
|
148
|
-
##
|
149
|
-
# Image region to which this entity belongs. Not filled currently for
|
150
|
-
# `labels` detection.
|
151
|
-
#
|
152
|
-
# @return [Array<Vertex>] An array of vertices.
|
153
|
-
#
|
154
|
-
def bounds
|
155
|
-
return [] unless @grpc.bounding_poly
|
156
|
-
@bounds ||= Array(@grpc.bounding_poly.vertices).map do |v|
|
157
|
-
Vertex.from_grpc v
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
##
|
162
|
-
# The location information for the detected entity. Multiple Location
|
163
|
-
# elements can be present since one location may indicate the location
|
164
|
-
# of the scene in the query image, and another the location of the
|
165
|
-
# place where the query image was taken. Location information is
|
166
|
-
# usually present for landmarks.
|
167
|
-
#
|
168
|
-
# @return [Array<Location>] An array of locations containing latitude
|
169
|
-
# and longitude.
|
170
|
-
#
|
171
|
-
def locations
|
172
|
-
@locations ||= Array(@grpc.locations).map do |l|
|
173
|
-
Location.from_grpc l.lat_lng
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
##
|
178
|
-
# Some entities can have additional optional Property fields. For
|
179
|
-
# example a different kind of score or string that qualifies the
|
180
|
-
# entity. present for landmarks.
|
181
|
-
#
|
182
|
-
# @return [Hash] A hash containing property names and values.
|
183
|
-
#
|
184
|
-
def properties
|
185
|
-
@properties ||=
|
186
|
-
Hash[Array(@grpc.properties).map { |p| [p.name, p.value] }]
|
187
|
-
end
|
188
|
-
|
189
|
-
##
|
190
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
191
|
-
#
|
192
|
-
# @return [Hash]
|
193
|
-
#
|
194
|
-
def to_h
|
195
|
-
{ mid: mid, locale: locale, description: description,
|
196
|
-
score: score, confidence: confidence, topicality: topicality,
|
197
|
-
bounds: bounds.map(&:to_h), locations: locations.map(&:to_h),
|
198
|
-
properties: properties }
|
199
|
-
end
|
200
|
-
|
201
|
-
# @private
|
202
|
-
def to_s
|
203
|
-
tmplt = "mid: %s, locale: %s, description: %s, score: %s, " \
|
204
|
-
"confidence: %s, topicality: %s, bounds: %i, " \
|
205
|
-
"locations: %i, properties: %s"
|
206
|
-
format tmplt, mid.inspect, locale.inspect, description.inspect,
|
207
|
-
score.inspect, confidence.inspect, topicality.inspect,
|
208
|
-
bounds.count, locations.count, properties.inspect
|
209
|
-
end
|
210
|
-
|
211
|
-
# @private
|
212
|
-
def inspect
|
213
|
-
"#<#{self.class.name} #{self}>"
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# @private New Annotation::Entity from a GRPC object.
|
218
|
-
def self.from_grpc grpc
|
219
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
@@ -1,1497 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
require "google/cloud/vision/annotation/vertex"
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Cloud
|
20
|
-
module Vision
|
21
|
-
class Annotation
|
22
|
-
##
|
23
|
-
# # Face
|
24
|
-
#
|
25
|
-
# The results of face detection.
|
26
|
-
#
|
27
|
-
# See {Annotation#faces} and {Annotation#face}.
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# require "google/cloud/vision"
|
31
|
-
#
|
32
|
-
# vision = Google::Cloud::Vision.new
|
33
|
-
#
|
34
|
-
# image = vision.image "path/to/face.jpg"
|
35
|
-
#
|
36
|
-
# face = image.face
|
37
|
-
# face.confidence #=> 0.8616237640380859
|
38
|
-
#
|
39
|
-
class Face
|
40
|
-
##
|
41
|
-
# @private The FaceAnnotation GRPC object.
|
42
|
-
attr_accessor :grpc
|
43
|
-
|
44
|
-
##
|
45
|
-
# @private Creates a new Face instance.
|
46
|
-
def initialize
|
47
|
-
@grpc = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# The angles of the face, including roll, yaw, and pitch.
|
52
|
-
#
|
53
|
-
# @return [Angles]
|
54
|
-
#
|
55
|
-
def angles
|
56
|
-
@angles ||= Angles.from_grpc @grpc
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# The bounds of the face, including the polygons for the head and
|
61
|
-
# face.
|
62
|
-
#
|
63
|
-
# @return [Bounds]
|
64
|
-
#
|
65
|
-
def bounds
|
66
|
-
@bounds ||= Bounds.from_grpc @grpc
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# The landmarks of the face, including the points for the eyes, ears,
|
71
|
-
# nose and mouth.
|
72
|
-
#
|
73
|
-
# @return [Features]
|
74
|
-
#
|
75
|
-
def features
|
76
|
-
@features ||= Features.from_grpc @grpc
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# The likelihood of the facial detection, including joy, sorrow,
|
81
|
-
# anger, surprise, under_exposed, blurred, and headwear.
|
82
|
-
#
|
83
|
-
# @return [Likelihood]
|
84
|
-
#
|
85
|
-
def likelihood
|
86
|
-
@likelihood ||= Likelihood.from_grpc @grpc
|
87
|
-
end
|
88
|
-
|
89
|
-
##
|
90
|
-
# The confidence of the facial detection.
|
91
|
-
#
|
92
|
-
# @return [Float] A value in the range [0, 1].
|
93
|
-
#
|
94
|
-
def confidence
|
95
|
-
@grpc.detection_confidence
|
96
|
-
end
|
97
|
-
|
98
|
-
##
|
99
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
100
|
-
#
|
101
|
-
# @return [Hash]
|
102
|
-
#
|
103
|
-
def to_h
|
104
|
-
{ angles: angles.to_h, bounds: bounds.to_h, features: features.to_h,
|
105
|
-
likelihood: likelihood.to_h }
|
106
|
-
end
|
107
|
-
|
108
|
-
# @private
|
109
|
-
def to_s
|
110
|
-
# Keep console output low by not showing all sub-objects.
|
111
|
-
"(angles, bounds, features, likelihood)"
|
112
|
-
end
|
113
|
-
|
114
|
-
# @private
|
115
|
-
def inspect
|
116
|
-
"#<#{self.class.name} #{self}>"
|
117
|
-
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# @private New Annotation::Face from a GRPC object.
|
121
|
-
def self.from_grpc grpc
|
122
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
123
|
-
end
|
124
|
-
|
125
|
-
##
|
126
|
-
# # Angles
|
127
|
-
#
|
128
|
-
# The orientation of the face relative to the image.
|
129
|
-
#
|
130
|
-
# See {Face}.
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# require "google/cloud/vision"
|
134
|
-
#
|
135
|
-
# vision = Google::Cloud::Vision.new
|
136
|
-
#
|
137
|
-
# image = vision.image "path/to/face.jpg"
|
138
|
-
# face = image.face
|
139
|
-
#
|
140
|
-
# face.angles.roll #=> -5.149211883544922
|
141
|
-
# face.angles.yaw #=> -4.069568157196045
|
142
|
-
# face.angles.pitch #=> -13.083284378051758
|
143
|
-
#
|
144
|
-
class Angles
|
145
|
-
##
|
146
|
-
# @private The FaceAnnotation GRPC object.
|
147
|
-
attr_accessor :grpc
|
148
|
-
|
149
|
-
##
|
150
|
-
# @private Creates a new Angles instance.
|
151
|
-
def initialize
|
152
|
-
@grpc = nil
|
153
|
-
end
|
154
|
-
|
155
|
-
##
|
156
|
-
# Roll angle. Indicates the amount of clockwise/anti-clockwise
|
157
|
-
# rotation of the face relative to the image vertical, about the
|
158
|
-
# axis perpendicular to the face.
|
159
|
-
#
|
160
|
-
# @return [Float] A value in the range [-180,180].
|
161
|
-
#
|
162
|
-
def roll
|
163
|
-
@grpc.roll_angle
|
164
|
-
end
|
165
|
-
|
166
|
-
##
|
167
|
-
# Yaw (pan) angle. Indicates the leftward/rightward angle that the
|
168
|
-
# face is pointing, relative to the vertical plane perpendicular to
|
169
|
-
# the image.
|
170
|
-
#
|
171
|
-
# @return [Float] A value in the range [-180,180].
|
172
|
-
#
|
173
|
-
def yaw
|
174
|
-
@grpc.pan_angle
|
175
|
-
end
|
176
|
-
alias pan yaw
|
177
|
-
|
178
|
-
##
|
179
|
-
# Pitch (tilt) angle. Indicates the upwards/downwards angle that the
|
180
|
-
# face is pointing relative to the image's horizontal plane.
|
181
|
-
#
|
182
|
-
# @return [Float] A value in the range [-180,180].
|
183
|
-
#
|
184
|
-
def pitch
|
185
|
-
@grpc.tilt_angle
|
186
|
-
end
|
187
|
-
alias tilt pitch
|
188
|
-
|
189
|
-
##
|
190
|
-
# Returns the object's property values as an array.
|
191
|
-
#
|
192
|
-
# @return [Array]
|
193
|
-
#
|
194
|
-
def to_a
|
195
|
-
[roll, yaw, pitch]
|
196
|
-
end
|
197
|
-
|
198
|
-
##
|
199
|
-
# Converts object to a hash. All keys will be symbolized.
|
200
|
-
#
|
201
|
-
# @return [Hash]
|
202
|
-
#
|
203
|
-
def to_h
|
204
|
-
{ roll: roll, yaw: yaw, pitch: pitch }
|
205
|
-
end
|
206
|
-
|
207
|
-
# @private
|
208
|
-
def to_s
|
209
|
-
format "(roll: %s, yaw: %s, pitch: %s)", roll.inspect,
|
210
|
-
yaw.inspect, pitch.inspect
|
211
|
-
end
|
212
|
-
|
213
|
-
# @private
|
214
|
-
def inspect
|
215
|
-
"#<Angles #{self}>"
|
216
|
-
end
|
217
|
-
|
218
|
-
##
|
219
|
-
# @private New Annotation::Face::Angles from a GRPC
|
220
|
-
# object.
|
221
|
-
def self.from_grpc grpc
|
222
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
##
|
227
|
-
# # Bounds
|
228
|
-
#
|
229
|
-
# Bounding polygons around the face.
|
230
|
-
#
|
231
|
-
# See {Face}.
|
232
|
-
#
|
233
|
-
# @example
|
234
|
-
# require "google/cloud/vision"
|
235
|
-
#
|
236
|
-
# vision = Google::Cloud::Vision.new
|
237
|
-
#
|
238
|
-
# image = vision.image "path/to/face.jpg"
|
239
|
-
# face = image.face
|
240
|
-
#
|
241
|
-
# face.bounds.face.count #=> 4
|
242
|
-
# vertex = face.bounds.face.first
|
243
|
-
# vertex.x #=> 28
|
244
|
-
# vertex.y #=> 40
|
245
|
-
#
|
246
|
-
class Bounds
|
247
|
-
##
|
248
|
-
# @private The FaceAnnotation GRPC object.
|
249
|
-
attr_accessor :grpc
|
250
|
-
|
251
|
-
##
|
252
|
-
# @private Creates a new Bounds instance.
|
253
|
-
def initialize
|
254
|
-
@grpc = nil
|
255
|
-
end
|
256
|
-
|
257
|
-
##
|
258
|
-
# The bounding polygon around the face. The coordinates of the
|
259
|
-
# bounding box are in the original image's scale, as returned in
|
260
|
-
# ImageParams. The bounding box is computed to "frame" the face in
|
261
|
-
# accordance with human expectations. It is based on the landmarker
|
262
|
-
# results. Note that one or more x and/or y coordinates may not be
|
263
|
-
# generated in the BoundingPoly (the polygon will be unbounded) if
|
264
|
-
# only a partial face appears in the image to be annotated.
|
265
|
-
def head
|
266
|
-
return [] unless @grpc.bounding_poly
|
267
|
-
@head ||= Array(@grpc.bounding_poly.vertices).map do |v|
|
268
|
-
Vertex.from_grpc v
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
##
|
273
|
-
# This bounding polygon is tighter than the {#head}, and encloses
|
274
|
-
# only the skin part of the face. Typically, it is used to eliminate
|
275
|
-
# the face from any image annotation that detects the "amount of
|
276
|
-
# skin" visible in an image. It is not based on the landmarks, only
|
277
|
-
# on the initial face detection.
|
278
|
-
def face
|
279
|
-
return [] unless @grpc.fd_bounding_poly
|
280
|
-
@face ||= Array(@grpc.fd_bounding_poly.vertices).map do |v|
|
281
|
-
Vertex.from_grpc v
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
##
|
286
|
-
# Returns the object's property values as an array.
|
287
|
-
#
|
288
|
-
# @return [Array]
|
289
|
-
#
|
290
|
-
def to_a
|
291
|
-
[head.map(&:to_a), face.map(&:to_a)]
|
292
|
-
end
|
293
|
-
|
294
|
-
##
|
295
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
296
|
-
#
|
297
|
-
# @return [Hash]
|
298
|
-
#
|
299
|
-
def to_h
|
300
|
-
{ head: head.map(&:to_h), face: face.map(&:to_h) }
|
301
|
-
end
|
302
|
-
|
303
|
-
# @private
|
304
|
-
def to_s
|
305
|
-
"(head: #{head.inspect}, face: #{face.inspect})"
|
306
|
-
end
|
307
|
-
|
308
|
-
# @private
|
309
|
-
def inspect
|
310
|
-
"#<Bounds #{self}>"
|
311
|
-
end
|
312
|
-
|
313
|
-
##
|
314
|
-
# @private New Annotation::Face::Angles from a GRPC
|
315
|
-
# object.
|
316
|
-
def self.from_grpc grpc
|
317
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
##
|
322
|
-
# # Features
|
323
|
-
#
|
324
|
-
# Represents facial landmarks or features. Left and right are defined
|
325
|
-
# from the vantage of the viewer of the image, without considering
|
326
|
-
# mirror projections typical of photos. So `face.features.eyes.left`
|
327
|
-
# typically is the person's right eye.
|
328
|
-
#
|
329
|
-
# See {Face}.
|
330
|
-
#
|
331
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
332
|
-
# images.annotate Type
|
333
|
-
#
|
334
|
-
# @example
|
335
|
-
# require "google/cloud/vision"
|
336
|
-
#
|
337
|
-
# vision = Google::Cloud::Vision.new
|
338
|
-
#
|
339
|
-
# image = vision.image "path/to/face.jpg"
|
340
|
-
# face = image.face
|
341
|
-
#
|
342
|
-
# face.features.to_h.count #=> 9
|
343
|
-
# face.features.eyes.left.pupil
|
344
|
-
# #<Landmark (x: 190.41544, y: 84.4557, z: -1.3682901)>
|
345
|
-
# face.features.chin.center
|
346
|
-
# #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>
|
347
|
-
#
|
348
|
-
class Features
|
349
|
-
##
|
350
|
-
# @private The FaceAnnotation GRPC object.
|
351
|
-
attr_accessor :grpc
|
352
|
-
|
353
|
-
##
|
354
|
-
# @private Creates a new Features instance.
|
355
|
-
def initialize
|
356
|
-
@grpc = nil
|
357
|
-
end
|
358
|
-
|
359
|
-
##
|
360
|
-
# The confidence of the facial landmarks detection.
|
361
|
-
#
|
362
|
-
# @return [Float] A value in the range [0,1].
|
363
|
-
#
|
364
|
-
def confidence
|
365
|
-
@grpc.landmarking_confidence
|
366
|
-
end
|
367
|
-
|
368
|
-
##
|
369
|
-
# Returns the facial landmark for the provided type code.
|
370
|
-
#
|
371
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
372
|
-
# images.annotate Type
|
373
|
-
#
|
374
|
-
# @param [String, Symbol] landmark_type An `images.annotate` type
|
375
|
-
# code from the [Vision
|
376
|
-
# API](https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1).
|
377
|
-
#
|
378
|
-
# @return [Landmark]
|
379
|
-
#
|
380
|
-
# @example
|
381
|
-
# require "google/cloud/vision"
|
382
|
-
#
|
383
|
-
# vision = Google::Cloud::Vision.new
|
384
|
-
#
|
385
|
-
# image = vision.image "path/to/face.jpg"
|
386
|
-
# face = image.face
|
387
|
-
#
|
388
|
-
# face.features["RIGHT_EAR_TRAGION"]
|
389
|
-
# #<Landmark (x: 303.81198, y: 88.5782, z: 77.719193)>
|
390
|
-
#
|
391
|
-
def [] landmark_type
|
392
|
-
landmark = Array(@grpc.landmarks).detect do |l|
|
393
|
-
l.type == landmark_type
|
394
|
-
end
|
395
|
-
return nil if landmark.nil?
|
396
|
-
Landmark.from_grpc landmark
|
397
|
-
end
|
398
|
-
|
399
|
-
##
|
400
|
-
# The landmarks of the chin.
|
401
|
-
#
|
402
|
-
# @return [Chin]
|
403
|
-
#
|
404
|
-
def chin
|
405
|
-
@chin ||= Chin.new self[:CHIN_LEFT_GONION],
|
406
|
-
self[:CHIN_GNATHION],
|
407
|
-
self[:CHIN_RIGHT_GONION]
|
408
|
-
end
|
409
|
-
|
410
|
-
##
|
411
|
-
# The landmarks of the ears.
|
412
|
-
#
|
413
|
-
# @return [Ears]
|
414
|
-
#
|
415
|
-
def ears
|
416
|
-
@ears ||= Ears.new self[:LEFT_EAR_TRAGION],
|
417
|
-
self[:RIGHT_EAR_TRAGION]
|
418
|
-
end
|
419
|
-
|
420
|
-
##
|
421
|
-
# The landmarks of the eyebrows.
|
422
|
-
#
|
423
|
-
# @return [Eyebrows]
|
424
|
-
#
|
425
|
-
def eyebrows
|
426
|
-
@eyebrows ||= begin
|
427
|
-
left = Eyebrow.new self[:LEFT_OF_LEFT_EYEBROW],
|
428
|
-
self[:LEFT_EYEBROW_UPPER_MIDPOINT],
|
429
|
-
self[:RIGHT_OF_LEFT_EYEBROW]
|
430
|
-
right = Eyebrow.new self[:LEFT_OF_RIGHT_EYEBROW],
|
431
|
-
self[:RIGHT_EYEBROW_UPPER_MIDPOINT],
|
432
|
-
self[:RIGHT_OF_RIGHT_EYEBROW]
|
433
|
-
Eyebrows.new left, right
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
##
|
438
|
-
# The landmarks of the eyes.
|
439
|
-
#
|
440
|
-
# @return [Eyes]
|
441
|
-
#
|
442
|
-
def eyes
|
443
|
-
@eyes ||= begin
|
444
|
-
left = Eye.new self[:LEFT_EYE_LEFT_CORNER],
|
445
|
-
self[:LEFT_EYE_BOTTOM_BOUNDARY],
|
446
|
-
self[:LEFT_EYE], self[:LEFT_EYE_PUPIL],
|
447
|
-
self[:LEFT_EYE_TOP_BOUNDARY],
|
448
|
-
self[:LEFT_EYE_RIGHT_CORNER]
|
449
|
-
right = Eye.new self[:RIGHT_EYE_LEFT_CORNER],
|
450
|
-
self[:RIGHT_EYE_BOTTOM_BOUNDARY],
|
451
|
-
self[:RIGHT_EYE], self[:RIGHT_EYE_PUPIL],
|
452
|
-
self[:RIGHT_EYE_TOP_BOUNDARY],
|
453
|
-
self[:RIGHT_EYE_RIGHT_CORNER]
|
454
|
-
Eyes.new left, right
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
##
|
459
|
-
# The landmark for the forehead glabella.
|
460
|
-
#
|
461
|
-
# @return [Landmark]
|
462
|
-
#
|
463
|
-
def forehead
|
464
|
-
@forehead ||= self[:FOREHEAD_GLABELLA]
|
465
|
-
end
|
466
|
-
|
467
|
-
##
|
468
|
-
# The landmarks of the lips.
|
469
|
-
#
|
470
|
-
# @return [Lips]
|
471
|
-
#
|
472
|
-
def lips
|
473
|
-
@lips ||= Lips.new self[:UPPER_LIP], self[:LOWER_LIP]
|
474
|
-
end
|
475
|
-
|
476
|
-
##
|
477
|
-
# The landmarks of the mouth.
|
478
|
-
#
|
479
|
-
# @return [Mouth]
|
480
|
-
#
|
481
|
-
def mouth
|
482
|
-
@mouth ||= Mouth.new self[:MOUTH_LEFT], self[:MOUTH_CENTER],
|
483
|
-
self[:MOUTH_RIGHT]
|
484
|
-
end
|
485
|
-
|
486
|
-
##
|
487
|
-
# The landmarks of the nose.
|
488
|
-
#
|
489
|
-
# @return [Nose]
|
490
|
-
#
|
491
|
-
def nose
|
492
|
-
@nose ||= Nose.new self[:NOSE_BOTTOM_LEFT],
|
493
|
-
self[:NOSE_BOTTOM_CENTER], self[:NOSE_TIP],
|
494
|
-
self[:MIDPOINT_BETWEEN_EYES],
|
495
|
-
self[:NOSE_BOTTOM_RIGHT]
|
496
|
-
end
|
497
|
-
|
498
|
-
##
|
499
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
500
|
-
#
|
501
|
-
# @return [Hash]
|
502
|
-
#
|
503
|
-
def to_h
|
504
|
-
{ confidence: confidence, chin: chin.to_h, ears: ears.to_h,
|
505
|
-
eyebrows: eyebrows.to_h, eyes: eyes.to_h,
|
506
|
-
forehead: forehead.to_h, lips: lips.to_h, mouth: mouth.to_h,
|
507
|
-
nose: nose.to_h }
|
508
|
-
end
|
509
|
-
|
510
|
-
# @private
|
511
|
-
def to_s
|
512
|
-
# Keep console output low by not showing all sub-objects.
|
513
|
-
"(confidence, chin, ears, eyebrows, eyes, " \
|
514
|
-
"forehead, lips, mouth, nose)"
|
515
|
-
end
|
516
|
-
|
517
|
-
# @private
|
518
|
-
def inspect
|
519
|
-
"#<Features #{self}>"
|
520
|
-
end
|
521
|
-
|
522
|
-
##
|
523
|
-
# @private New Annotation::Face::Features from a GRPC
|
524
|
-
# object.
|
525
|
-
def self.from_grpc grpc
|
526
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
527
|
-
end
|
528
|
-
|
529
|
-
##
|
530
|
-
# # Landmark
|
531
|
-
#
|
532
|
-
# A face-specific landmark (for example, a face feature). Landmark
|
533
|
-
# positions may fall outside the bounds of the image when the face
|
534
|
-
# is near one or more edges of the image. Therefore it is NOT
|
535
|
-
# guaranteed that `0 <= x < width` or `0 <= y < height`.
|
536
|
-
#
|
537
|
-
# See {Features} and {Face}.
|
538
|
-
#
|
539
|
-
# @example
|
540
|
-
# require "google/cloud/vision"
|
541
|
-
#
|
542
|
-
# vision = Google::Cloud::Vision.new
|
543
|
-
#
|
544
|
-
# image = vision.image "path/to/face.jpg"
|
545
|
-
# face = image.face
|
546
|
-
#
|
547
|
-
# face.features.to_h.count #=> 9
|
548
|
-
# face.features.eyes.left.pupil
|
549
|
-
# #<Landmark (x: 190.41544, y: 84.4557, z: -1.3682901)>
|
550
|
-
# face.features.chin.center
|
551
|
-
# #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>
|
552
|
-
#
|
553
|
-
class Landmark
|
554
|
-
##
|
555
|
-
# @private The Landmark GRPC object.
|
556
|
-
attr_accessor :grpc
|
557
|
-
|
558
|
-
##
|
559
|
-
# @private Creates a new Landmark instance.
|
560
|
-
def initialize
|
561
|
-
@grpc = nil
|
562
|
-
end
|
563
|
-
|
564
|
-
##
|
565
|
-
# The landmark type code.
|
566
|
-
#
|
567
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
568
|
-
# images.annotate Type
|
569
|
-
#
|
570
|
-
# @return [String]
|
571
|
-
#
|
572
|
-
# @example
|
573
|
-
# require "google/cloud/vision"
|
574
|
-
#
|
575
|
-
# vision = Google::Cloud::Vision.new
|
576
|
-
#
|
577
|
-
# image = vision.image "path/to/face.jpg"
|
578
|
-
# face = image.face
|
579
|
-
#
|
580
|
-
# face.features.forehead.type #=> :FOREHEAD_GLABELLA
|
581
|
-
#
|
582
|
-
def type
|
583
|
-
@grpc.type
|
584
|
-
end
|
585
|
-
|
586
|
-
##
|
587
|
-
# The X (horizontal) coordinate.
|
588
|
-
#
|
589
|
-
# @return [Float]
|
590
|
-
#
|
591
|
-
def x
|
592
|
-
return nil unless @grpc.position
|
593
|
-
@grpc.position.x
|
594
|
-
end
|
595
|
-
|
596
|
-
##
|
597
|
-
# The Y (vertical) coordinate.
|
598
|
-
#
|
599
|
-
# @return [Float]
|
600
|
-
#
|
601
|
-
def y
|
602
|
-
return nil unless @grpc.position
|
603
|
-
@grpc.position.y
|
604
|
-
end
|
605
|
-
|
606
|
-
##
|
607
|
-
# The Z (depth) coordinate.
|
608
|
-
#
|
609
|
-
# @return [Float]
|
610
|
-
#
|
611
|
-
def z
|
612
|
-
return nil unless @grpc.position
|
613
|
-
@grpc.position.z
|
614
|
-
end
|
615
|
-
|
616
|
-
##
|
617
|
-
# Returns the object's property values as an array.
|
618
|
-
#
|
619
|
-
# @return [Array]
|
620
|
-
#
|
621
|
-
def to_a
|
622
|
-
[x, y, z]
|
623
|
-
end
|
624
|
-
|
625
|
-
##
|
626
|
-
# Converts object to a hash. All keys will be symbolized.
|
627
|
-
#
|
628
|
-
# @return [Hash]
|
629
|
-
#
|
630
|
-
def to_h
|
631
|
-
{ x: x, y: y, z: z }
|
632
|
-
end
|
633
|
-
|
634
|
-
# @private
|
635
|
-
def to_s
|
636
|
-
"(x: #{x.inspect}, y: #{y.inspect}, z: #{z.inspect})"
|
637
|
-
end
|
638
|
-
|
639
|
-
# @private
|
640
|
-
def inspect
|
641
|
-
"#<Landmark #{self}>"
|
642
|
-
end
|
643
|
-
|
644
|
-
##
|
645
|
-
# @private New Annotation::Face::Features from a GRPC
|
646
|
-
# object.
|
647
|
-
def self.from_grpc grpc
|
648
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
649
|
-
end
|
650
|
-
end
|
651
|
-
|
652
|
-
##
|
653
|
-
# # Chin
|
654
|
-
#
|
655
|
-
# The landmarks of the chin in the features of a face.
|
656
|
-
#
|
657
|
-
# Left and right are defined from the vantage of the viewer of the
|
658
|
-
# image, without considering mirror projections typical of photos.
|
659
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
660
|
-
#
|
661
|
-
# See {Features} and {Face}.
|
662
|
-
#
|
663
|
-
# @attr_reader [Landmark] left The chin, left gonion.
|
664
|
-
# @attr_reader [Landmark] center The chin, gnathion.
|
665
|
-
# @attr_reader [Landmark] right The chin, right gonion.
|
666
|
-
#
|
667
|
-
# @example
|
668
|
-
# require "google/cloud/vision"
|
669
|
-
#
|
670
|
-
# vision = Google::Cloud::Vision.new
|
671
|
-
#
|
672
|
-
# image = vision.image "path/to/face.jpg"
|
673
|
-
# face = image.face
|
674
|
-
#
|
675
|
-
# chin = face.features.chin
|
676
|
-
#
|
677
|
-
# chin.center
|
678
|
-
# #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>
|
679
|
-
#
|
680
|
-
class Chin
|
681
|
-
attr_reader :left, :center, :right
|
682
|
-
|
683
|
-
##
|
684
|
-
# @private Creates a new Chin instance.
|
685
|
-
def initialize left, center, right
|
686
|
-
@left = left
|
687
|
-
@center = center
|
688
|
-
@right = right
|
689
|
-
end
|
690
|
-
|
691
|
-
##
|
692
|
-
# Returns the object's property values as an array.
|
693
|
-
#
|
694
|
-
# @return [Array]
|
695
|
-
#
|
696
|
-
def to_a
|
697
|
-
[left, center, right]
|
698
|
-
end
|
699
|
-
|
700
|
-
##
|
701
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
702
|
-
#
|
703
|
-
# @return [Hash]
|
704
|
-
#
|
705
|
-
def to_h
|
706
|
-
{ left: left.to_h, center: center.to_h, right: right.to_h }
|
707
|
-
end
|
708
|
-
|
709
|
-
# @private
|
710
|
-
def to_s
|
711
|
-
format "(left: %s, center: %s, right: %s)", left.inspect,
|
712
|
-
center.inspect, right.inspect
|
713
|
-
end
|
714
|
-
|
715
|
-
# @private
|
716
|
-
def inspect
|
717
|
-
"#<Chin #{self}>"
|
718
|
-
end
|
719
|
-
end
|
720
|
-
|
721
|
-
##
|
722
|
-
# # Ears
|
723
|
-
#
|
724
|
-
# The landmarks for the ear tragions.
|
725
|
-
#
|
726
|
-
# Left and right are defined from the vantage of the viewer of the
|
727
|
-
# image, without considering mirror projections typical of photos.
|
728
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
729
|
-
#
|
730
|
-
# See {Features} and {Face}.
|
731
|
-
#
|
732
|
-
# @attr_reader [Landmark] left The left ear tragion.
|
733
|
-
# @attr_reader [Landmark] right The right ear tragion.
|
734
|
-
#
|
735
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
736
|
-
# images.annotate Type
|
737
|
-
#
|
738
|
-
# @example
|
739
|
-
# require "google/cloud/vision"
|
740
|
-
#
|
741
|
-
# vision = Google::Cloud::Vision.new
|
742
|
-
#
|
743
|
-
# image = vision.image "path/to/face.jpg"
|
744
|
-
# face = image.face
|
745
|
-
#
|
746
|
-
# ears = face.features.ears
|
747
|
-
# ears.right
|
748
|
-
# #<Landmark (x: 303.81198, y: 88.5782, z: 77.719193)>
|
749
|
-
#
|
750
|
-
class Ears
|
751
|
-
attr_reader :left, :right
|
752
|
-
|
753
|
-
##
|
754
|
-
# @private Creates a new Ears instance.
|
755
|
-
def initialize left, right
|
756
|
-
@left = left
|
757
|
-
@right = right
|
758
|
-
end
|
759
|
-
|
760
|
-
##
|
761
|
-
# Returns the object's property values as an array.
|
762
|
-
#
|
763
|
-
# @return [Array]
|
764
|
-
#
|
765
|
-
def to_a
|
766
|
-
[left, right]
|
767
|
-
end
|
768
|
-
|
769
|
-
##
|
770
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
771
|
-
#
|
772
|
-
# @return [Hash]
|
773
|
-
#
|
774
|
-
def to_h
|
775
|
-
{ left: left.to_h, right: right.to_h }
|
776
|
-
end
|
777
|
-
|
778
|
-
# @private
|
779
|
-
def to_s
|
780
|
-
"(left: #{left.inspect}, right: #{right.inspect})"
|
781
|
-
end
|
782
|
-
|
783
|
-
# @private
|
784
|
-
def inspect
|
785
|
-
"#<Ears #{self}>"
|
786
|
-
end
|
787
|
-
end
|
788
|
-
|
789
|
-
##
|
790
|
-
# # Eyebrows
|
791
|
-
#
|
792
|
-
# The landmarks of the eyebrows in the features of a face.
|
793
|
-
#
|
794
|
-
# Left and right are defined from the vantage of the viewer of the
|
795
|
-
# image, without considering mirror projections typical of photos.
|
796
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
797
|
-
#
|
798
|
-
# See {Features} and {Face}.
|
799
|
-
#
|
800
|
-
# @attr_reader [Eyebrow] left The left eyebrow.
|
801
|
-
# @attr_reader [Eyebrow] right The right eyebrow.
|
802
|
-
#
|
803
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
804
|
-
# images.annotate Type
|
805
|
-
#
|
806
|
-
# @example
|
807
|
-
# require "google/cloud/vision"
|
808
|
-
#
|
809
|
-
# vision = Google::Cloud::Vision.new
|
810
|
-
#
|
811
|
-
# image = vision.image "path/to/face.jpg"
|
812
|
-
# face = image.face
|
813
|
-
#
|
814
|
-
# eyebrows = face.features.eyebrows
|
815
|
-
#
|
816
|
-
# right_eyebrow = eyebrows.right
|
817
|
-
# right_eyebrow.top
|
818
|
-
# #<Landmark (x: 256.3194, y: 58.222664, z: -17.299419)>
|
819
|
-
#
|
820
|
-
class Eyebrows
|
821
|
-
attr_reader :left, :right
|
822
|
-
|
823
|
-
##
|
824
|
-
# @private Creates a new Eyebrows instance.
|
825
|
-
def initialize left, right
|
826
|
-
@left = left
|
827
|
-
@right = right
|
828
|
-
end
|
829
|
-
|
830
|
-
##
|
831
|
-
# Returns the object's property values as an array.
|
832
|
-
#
|
833
|
-
# @return [Array]
|
834
|
-
#
|
835
|
-
def to_a
|
836
|
-
[left, right]
|
837
|
-
end
|
838
|
-
|
839
|
-
##
|
840
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
841
|
-
#
|
842
|
-
# @return [Hash]
|
843
|
-
#
|
844
|
-
def to_h
|
845
|
-
{ left: left.to_h, right: right.to_h }
|
846
|
-
end
|
847
|
-
|
848
|
-
# @private
|
849
|
-
def to_s
|
850
|
-
"(left: #{left.inspect}, right: #{right.inspect})"
|
851
|
-
end
|
852
|
-
|
853
|
-
# @private
|
854
|
-
def inspect
|
855
|
-
"#<Eyebrows #{self}>"
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
##
|
860
|
-
# # Eyebrow
|
861
|
-
#
|
862
|
-
# The landmarks of an eyebrow in the features of a face.
|
863
|
-
#
|
864
|
-
# Left and right are defined from the vantage of the viewer of the
|
865
|
-
# image, without considering mirror projections typical of photos.
|
866
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
867
|
-
#
|
868
|
-
# See {Eyebrows}, {Features} and {Face}.
|
869
|
-
#
|
870
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
871
|
-
# images.annotate Type
|
872
|
-
#
|
873
|
-
# @attr_reader [Landmark] left The eyebrow, left.
|
874
|
-
# @attr_reader [Landmark] top The eyebrow, upper midpoint.
|
875
|
-
# @attr_reader [Landmark] right The eyebrow, right.
|
876
|
-
#
|
877
|
-
# @example
|
878
|
-
# require "google/cloud/vision"
|
879
|
-
#
|
880
|
-
# vision = Google::Cloud::Vision.new
|
881
|
-
#
|
882
|
-
# image = vision.image "path/to/face.jpg"
|
883
|
-
# face = image.face
|
884
|
-
#
|
885
|
-
# eyebrows = face.features.eyebrows
|
886
|
-
#
|
887
|
-
# right_eyebrow = eyebrows.right
|
888
|
-
# right_eyebrow.top
|
889
|
-
# #<Landmark (x: 256.3194, y: 58.222664, z: -17.299419)>
|
890
|
-
#
|
891
|
-
class Eyebrow
|
892
|
-
attr_reader :left, :top, :right
|
893
|
-
|
894
|
-
##
|
895
|
-
# @private Creates a new Eyebrow instance.
|
896
|
-
def initialize left, top, right
|
897
|
-
@left = left
|
898
|
-
@top = top
|
899
|
-
@right = right
|
900
|
-
end
|
901
|
-
|
902
|
-
##
|
903
|
-
# Returns the object's property values as an array.
|
904
|
-
#
|
905
|
-
# @return [Array]
|
906
|
-
#
|
907
|
-
def to_a
|
908
|
-
[left, top, right]
|
909
|
-
end
|
910
|
-
|
911
|
-
##
|
912
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
913
|
-
#
|
914
|
-
# @return [Hash]
|
915
|
-
#
|
916
|
-
def to_h
|
917
|
-
{ left: left.to_h, top: top.to_h, right: right.to_h }
|
918
|
-
end
|
919
|
-
|
920
|
-
# @private
|
921
|
-
def to_s
|
922
|
-
format "(left: %s, top: %s, right: %s)", left.inspect,
|
923
|
-
top.inspect, right.inspect
|
924
|
-
end
|
925
|
-
|
926
|
-
# @private
|
927
|
-
def inspect
|
928
|
-
"#<Eyebrow #{self}>"
|
929
|
-
end
|
930
|
-
end
|
931
|
-
|
932
|
-
##
|
933
|
-
# # Eyes
|
934
|
-
#
|
935
|
-
# The landmarks of the eyes in the features of a face.
|
936
|
-
#
|
937
|
-
# Left and right are defined from the vantage of the viewer of the
|
938
|
-
# image, without considering mirror projections typical of photos.
|
939
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
940
|
-
#
|
941
|
-
# See {Features} and {Face}.
|
942
|
-
#
|
943
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
944
|
-
# images.annotate Type
|
945
|
-
#
|
946
|
-
# @attr_reader [Eye] left The left eye.
|
947
|
-
# @attr_reader [Eye] right The right eye.
|
948
|
-
#
|
949
|
-
# @example
|
950
|
-
# require "google/cloud/vision"
|
951
|
-
#
|
952
|
-
# vision = Google::Cloud::Vision.new
|
953
|
-
#
|
954
|
-
# image = vision.image "path/to/face.jpg"
|
955
|
-
# face = image.face
|
956
|
-
#
|
957
|
-
# eyes = face.features.eyes
|
958
|
-
#
|
959
|
-
# right_eye = eyes.right
|
960
|
-
# right_eye.pupil
|
961
|
-
# #<Landmark (x: 256.63464, y: 79.641411, z: -6.0731235)>
|
962
|
-
#
|
963
|
-
class Eyes
|
964
|
-
attr_reader :left, :right
|
965
|
-
|
966
|
-
##
|
967
|
-
# @private Creates a new Eyes instance.
|
968
|
-
def initialize left, right
|
969
|
-
@left = left
|
970
|
-
@right = right
|
971
|
-
end
|
972
|
-
|
973
|
-
##
|
974
|
-
# Returns the object's property values as an array.
|
975
|
-
#
|
976
|
-
# @return [Array]
|
977
|
-
#
|
978
|
-
def to_a
|
979
|
-
[left, right]
|
980
|
-
end
|
981
|
-
|
982
|
-
##
|
983
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
984
|
-
#
|
985
|
-
# @return [Hash]
|
986
|
-
#
|
987
|
-
def to_h
|
988
|
-
{ left: left.to_h, right: right.to_h }
|
989
|
-
end
|
990
|
-
|
991
|
-
# @private
|
992
|
-
def to_s
|
993
|
-
"(left: #{left.inspect}, right: #{right.inspect})"
|
994
|
-
end
|
995
|
-
|
996
|
-
# @private
|
997
|
-
def inspect
|
998
|
-
"#<Eyes #{self}>"
|
999
|
-
end
|
1000
|
-
end
|
1001
|
-
|
1002
|
-
##
|
1003
|
-
# # Eye
|
1004
|
-
#
|
1005
|
-
# The landmarks of an eye in the features of a face.
|
1006
|
-
#
|
1007
|
-
# Left and right are defined from the vantage of the viewer of the
|
1008
|
-
# image, without considering mirror projections typical of photos.
|
1009
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
1010
|
-
#
|
1011
|
-
# See {Eyes}, {Features} and {Face}.
|
1012
|
-
#
|
1013
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
1014
|
-
# images.annotate Type
|
1015
|
-
#
|
1016
|
-
# @attr_reader [Landmark] left The eye, left corner.
|
1017
|
-
# @attr_reader [Landmark] bottom The eye, bottom boundary.
|
1018
|
-
# @attr_reader [Landmark] center The eye, center.
|
1019
|
-
# @attr_reader [Landmark] pupil The eye pupil.
|
1020
|
-
# @attr_reader [Landmark] top The eye, top boundary.
|
1021
|
-
# @attr_reader [Landmark] right The eye, right corner.
|
1022
|
-
#
|
1023
|
-
# @example
|
1024
|
-
# require "google/cloud/vision"
|
1025
|
-
#
|
1026
|
-
# vision = Google::Cloud::Vision.new
|
1027
|
-
#
|
1028
|
-
# image = vision.image "path/to/face.jpg"
|
1029
|
-
# face = image.face
|
1030
|
-
#
|
1031
|
-
# right_eye = face.features.eyes.right
|
1032
|
-
#
|
1033
|
-
# right_eye.pupil
|
1034
|
-
# #<Landmark (x: 256.63464, y: 79.641411, z: -6.0731235)>
|
1035
|
-
#
|
1036
|
-
class Eye
|
1037
|
-
attr_reader :left, :bottom, :center, :pupil, :top, :right
|
1038
|
-
|
1039
|
-
##
|
1040
|
-
# @private Creates a new Eye instance.
|
1041
|
-
def initialize left, bottom, center, pupil, top, right
|
1042
|
-
@left = left
|
1043
|
-
@bottom = bottom
|
1044
|
-
@center = center
|
1045
|
-
@pupil = pupil
|
1046
|
-
@top = top
|
1047
|
-
@right = right
|
1048
|
-
end
|
1049
|
-
|
1050
|
-
##
|
1051
|
-
# Returns the object's property values as an array.
|
1052
|
-
#
|
1053
|
-
# @return [Array]
|
1054
|
-
#
|
1055
|
-
def to_a
|
1056
|
-
[left, top, right]
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
##
|
1060
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
1061
|
-
#
|
1062
|
-
# @return [Hash]
|
1063
|
-
#
|
1064
|
-
def to_h
|
1065
|
-
{ left: left.to_h, bottom: bottom.to_h, center: center.to_h,
|
1066
|
-
pupil: pupil.to_h, top: top.to_h, right: right.to_h }
|
1067
|
-
end
|
1068
|
-
|
1069
|
-
# @private
|
1070
|
-
def to_s
|
1071
|
-
tmplt = "(left: %s, bottom: %s, center: %s, " \
|
1072
|
-
"pupil: %s, top: %s, right: %s)"
|
1073
|
-
format tmplt, left.inspect, bottom.inspect, center.inspect,
|
1074
|
-
pupil.inspect, top.inspect, right.inspect
|
1075
|
-
end
|
1076
|
-
|
1077
|
-
# @private
|
1078
|
-
def inspect
|
1079
|
-
"#<Eye #{self}>"
|
1080
|
-
end
|
1081
|
-
end
|
1082
|
-
|
1083
|
-
##
|
1084
|
-
# # Lips
|
1085
|
-
#
|
1086
|
-
# The landmarks of the lips in the features of a face.
|
1087
|
-
#
|
1088
|
-
# See {Features} and {Face}.
|
1089
|
-
#
|
1090
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
1091
|
-
# images.annotate Type
|
1092
|
-
#
|
1093
|
-
# @attr_reader [Landmark] top The upper lip.
|
1094
|
-
# @attr_reader [Landmark] bottom The lower lip.
|
1095
|
-
#
|
1096
|
-
# @example
|
1097
|
-
# require "google/cloud/vision"
|
1098
|
-
#
|
1099
|
-
# vision = Google::Cloud::Vision.new
|
1100
|
-
#
|
1101
|
-
# image = vision.image "path/to/face.jpg"
|
1102
|
-
# face = image.face
|
1103
|
-
#
|
1104
|
-
# lips = face.features.lips
|
1105
|
-
#
|
1106
|
-
# lips.top
|
1107
|
-
# #<Landmark (x: 228.54768, y: 143.2952, z: -5.6550336)>
|
1108
|
-
#
|
1109
|
-
class Lips
|
1110
|
-
attr_reader :top, :bottom
|
1111
|
-
|
1112
|
-
alias upper top
|
1113
|
-
alias lower bottom
|
1114
|
-
|
1115
|
-
##
|
1116
|
-
# @private Creates a new Lips instance.
|
1117
|
-
def initialize top, bottom
|
1118
|
-
@top = top
|
1119
|
-
@bottom = bottom
|
1120
|
-
end
|
1121
|
-
|
1122
|
-
##
|
1123
|
-
# Returns the object's property values as an array.
|
1124
|
-
#
|
1125
|
-
# @return [Array]
|
1126
|
-
#
|
1127
|
-
def to_a
|
1128
|
-
[top, bottom]
|
1129
|
-
end
|
1130
|
-
|
1131
|
-
##
|
1132
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
1133
|
-
#
|
1134
|
-
# @return [Hash]
|
1135
|
-
#
|
1136
|
-
def to_h
|
1137
|
-
{ top: top.to_h, bottom: bottom.to_h }
|
1138
|
-
end
|
1139
|
-
|
1140
|
-
# @private
|
1141
|
-
def to_s
|
1142
|
-
"(top: #{top.inspect}, bottom: #{bottom.inspect})"
|
1143
|
-
end
|
1144
|
-
|
1145
|
-
# @private
|
1146
|
-
def inspect
|
1147
|
-
"#<Lips #{self}>"
|
1148
|
-
end
|
1149
|
-
end
|
1150
|
-
|
1151
|
-
##
|
1152
|
-
# # Mouth
|
1153
|
-
#
|
1154
|
-
# The landmarks of the mouth in the features of a face.
|
1155
|
-
#
|
1156
|
-
# Left and right are defined from the vantage of the viewer of the
|
1157
|
-
# image, without considering mirror projections typical of photos.
|
1158
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
1159
|
-
#
|
1160
|
-
# See {Features} and {Face}.
|
1161
|
-
#
|
1162
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
1163
|
-
# images.annotate Type
|
1164
|
-
#
|
1165
|
-
# @attr_reader [Landmark] left The mouth, left.
|
1166
|
-
# @attr_reader [Landmark] center The mouth, center.
|
1167
|
-
# @attr_reader [Landmark] right TThe mouth, right.
|
1168
|
-
#
|
1169
|
-
# @example
|
1170
|
-
# require "google/cloud/vision"
|
1171
|
-
#
|
1172
|
-
# vision = Google::Cloud::Vision.new
|
1173
|
-
#
|
1174
|
-
# image = vision.image "path/to/face.jpg"
|
1175
|
-
# face = image.face
|
1176
|
-
#
|
1177
|
-
# mouth = face.features.mouth
|
1178
|
-
#
|
1179
|
-
# mouth.center
|
1180
|
-
# #<Landmark (x: 228.53499, y: 150.29066, z: 1.1069832)>
|
1181
|
-
#
|
1182
|
-
class Mouth
|
1183
|
-
attr_reader :left, :center, :right
|
1184
|
-
|
1185
|
-
##
|
1186
|
-
# @private Creates a new Mouth instance.
|
1187
|
-
def initialize left, center, right
|
1188
|
-
@left = left
|
1189
|
-
@center = center
|
1190
|
-
@right = right
|
1191
|
-
end
|
1192
|
-
|
1193
|
-
##
|
1194
|
-
# Returns the object's property values as an array.
|
1195
|
-
#
|
1196
|
-
# @return [Array]
|
1197
|
-
#
|
1198
|
-
def to_a
|
1199
|
-
[left, center, right]
|
1200
|
-
end
|
1201
|
-
|
1202
|
-
##
|
1203
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
1204
|
-
#
|
1205
|
-
# @return [Hash]
|
1206
|
-
#
|
1207
|
-
def to_h
|
1208
|
-
{ left: left.to_h, center: center.to_h, right: right.to_h }
|
1209
|
-
end
|
1210
|
-
|
1211
|
-
# @private
|
1212
|
-
def to_s
|
1213
|
-
format "(left: %s, center: %s, right: %s)", left.inspect,
|
1214
|
-
center.inspect, right.inspect
|
1215
|
-
end
|
1216
|
-
|
1217
|
-
# @private
|
1218
|
-
def inspect
|
1219
|
-
"#<Mouth #{self}>"
|
1220
|
-
end
|
1221
|
-
end
|
1222
|
-
|
1223
|
-
##
|
1224
|
-
# # Nose
|
1225
|
-
#
|
1226
|
-
# The landmarks of the nose in the features of a face.
|
1227
|
-
#
|
1228
|
-
# Left and right are defined from the vantage of the viewer of the
|
1229
|
-
# image, without considering mirror projections typical of photos.
|
1230
|
-
# So `face.features.eyes.left` typically is the person's right eye.
|
1231
|
-
#
|
1232
|
-
# See {Features} and {Face}.
|
1233
|
-
#
|
1234
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Type_1
|
1235
|
-
# images.annotate Type
|
1236
|
-
#
|
1237
|
-
# @attr_reader [Landmark] left The nose, bottom left.
|
1238
|
-
# @attr_reader [Landmark] bottom The nose, bottom center.
|
1239
|
-
# @attr_reader [Landmark] tip The nose tip.
|
1240
|
-
# @attr_reader [Landmark] top The midpoint between the eyes.
|
1241
|
-
# @attr_reader [Landmark] right The nose, bottom right.
|
1242
|
-
#
|
1243
|
-
# @example
|
1244
|
-
# require "google/cloud/vision"
|
1245
|
-
#
|
1246
|
-
# vision = Google::Cloud::Vision.new
|
1247
|
-
#
|
1248
|
-
# image = vision.image "path/to/face.jpg"
|
1249
|
-
# face = image.face
|
1250
|
-
#
|
1251
|
-
# nose = face.features.nose
|
1252
|
-
#
|
1253
|
-
# nose.tip
|
1254
|
-
# #<Landmark (x: 225.23511, y: 122.47372, z: -25.817825)>
|
1255
|
-
#
|
1256
|
-
class Nose
|
1257
|
-
attr_reader :left, :bottom, :tip, :top, :right
|
1258
|
-
|
1259
|
-
##
|
1260
|
-
# @private Creates a new Nose instance.
|
1261
|
-
def initialize left, bottom, tip, top, right
|
1262
|
-
@left = left
|
1263
|
-
@bottom = bottom
|
1264
|
-
@tip = tip
|
1265
|
-
@top = top
|
1266
|
-
@right = right
|
1267
|
-
end
|
1268
|
-
|
1269
|
-
##
|
1270
|
-
# Returns the object's property values as an array.
|
1271
|
-
#
|
1272
|
-
# @return [Array]
|
1273
|
-
#
|
1274
|
-
def to_a
|
1275
|
-
[left, bottom, tip, top, right]
|
1276
|
-
end
|
1277
|
-
|
1278
|
-
##
|
1279
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
1280
|
-
#
|
1281
|
-
# @return [Hash]
|
1282
|
-
#
|
1283
|
-
def to_h
|
1284
|
-
{ left: left.to_h, bottom: bottom.to_h, tip: tip.to_h,
|
1285
|
-
top: top.to_h, right: right.to_h }
|
1286
|
-
end
|
1287
|
-
|
1288
|
-
# @private
|
1289
|
-
def to_s
|
1290
|
-
tmplt = "(left: %s, bottom: %s, tip: %s, " \
|
1291
|
-
"top: %s, right: %s)"
|
1292
|
-
format tmplt, left.inspect, bottom.inspect, tip.inspect,
|
1293
|
-
top.inspect, right.inspect
|
1294
|
-
end
|
1295
|
-
|
1296
|
-
# @private
|
1297
|
-
def inspect
|
1298
|
-
"#<Nose #{self}>"
|
1299
|
-
end
|
1300
|
-
end
|
1301
|
-
end
|
1302
|
-
|
1303
|
-
##
|
1304
|
-
# # Likelihood
|
1305
|
-
#
|
1306
|
-
# A bucketized representation of likelihood of various separate facial
|
1307
|
-
# characteristics, meant to give highly stable results across model
|
1308
|
-
# upgrades.
|
1309
|
-
#
|
1310
|
-
# See {Face}.
|
1311
|
-
#
|
1312
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#Likelihood
|
1313
|
-
# images.annotate Likelihood
|
1314
|
-
#
|
1315
|
-
# @example
|
1316
|
-
# require "google/cloud/vision"
|
1317
|
-
#
|
1318
|
-
# vision = Google::Cloud::Vision.new
|
1319
|
-
#
|
1320
|
-
# image = vision.image "path/to/face.jpg"
|
1321
|
-
# face = image.face
|
1322
|
-
#
|
1323
|
-
# face.likelihood.to_h.count #=> 7
|
1324
|
-
# face.likelihood.sorrow? #=> false
|
1325
|
-
# face.likelihood.sorrow #=> :VERY_UNLIKELY
|
1326
|
-
#
|
1327
|
-
class Likelihood
|
1328
|
-
POSITIVE_RATINGS = %i[POSSIBLE LIKELY VERY_LIKELY].freeze
|
1329
|
-
|
1330
|
-
##
|
1331
|
-
# @private The FaceAnnotation GRPC object.
|
1332
|
-
attr_accessor :grpc
|
1333
|
-
|
1334
|
-
##
|
1335
|
-
# @private Creates a new Likelihood instance.
|
1336
|
-
def initialize
|
1337
|
-
@grpc = nil
|
1338
|
-
end
|
1339
|
-
|
1340
|
-
##
|
1341
|
-
# Joy likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1342
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1343
|
-
def joy
|
1344
|
-
@grpc.joy_likelihood
|
1345
|
-
end
|
1346
|
-
|
1347
|
-
##
|
1348
|
-
# Joy likelihood. Returns `true` if {#joy} is `POSSIBLE`, `LIKELY`,
|
1349
|
-
# or `VERY_LIKELY`.
|
1350
|
-
#
|
1351
|
-
# @return [Boolean]
|
1352
|
-
#
|
1353
|
-
def joy?
|
1354
|
-
POSITIVE_RATINGS.include? joy
|
1355
|
-
end
|
1356
|
-
|
1357
|
-
##
|
1358
|
-
# Sorrow likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1359
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1360
|
-
def sorrow
|
1361
|
-
@grpc.sorrow_likelihood
|
1362
|
-
end
|
1363
|
-
|
1364
|
-
##
|
1365
|
-
# Sorrow likelihood. Returns `true` if {#sorrow} is `POSSIBLE`,
|
1366
|
-
# `LIKELY`, or `VERY_LIKELY`.
|
1367
|
-
#
|
1368
|
-
# @return [Boolean]
|
1369
|
-
#
|
1370
|
-
def sorrow?
|
1371
|
-
POSITIVE_RATINGS.include? sorrow
|
1372
|
-
end
|
1373
|
-
|
1374
|
-
##
|
1375
|
-
# Joy likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1376
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1377
|
-
def anger
|
1378
|
-
@grpc.anger_likelihood
|
1379
|
-
end
|
1380
|
-
|
1381
|
-
##
|
1382
|
-
# Anger likelihood. Returns `true` if {#anger} is `POSSIBLE`,
|
1383
|
-
# `LIKELY`, or `VERY_LIKELY`.
|
1384
|
-
#
|
1385
|
-
# @return [Boolean]
|
1386
|
-
#
|
1387
|
-
def anger?
|
1388
|
-
POSITIVE_RATINGS.include? anger
|
1389
|
-
end
|
1390
|
-
|
1391
|
-
##
|
1392
|
-
# Surprise likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1393
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1394
|
-
def surprise
|
1395
|
-
@grpc.surprise_likelihood
|
1396
|
-
end
|
1397
|
-
|
1398
|
-
##
|
1399
|
-
# Surprise likelihood. Returns `true` if {#surprise} is `POSSIBLE`,
|
1400
|
-
# `LIKELY`, or `VERY_LIKELY`.
|
1401
|
-
#
|
1402
|
-
# @return [Boolean]
|
1403
|
-
#
|
1404
|
-
def surprise?
|
1405
|
-
POSITIVE_RATINGS.include? surprise
|
1406
|
-
end
|
1407
|
-
|
1408
|
-
##
|
1409
|
-
# Under Exposed likelihood rating. Possible values are
|
1410
|
-
# `VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and
|
1411
|
-
# `VERY_LIKELY`.
|
1412
|
-
def under_exposed
|
1413
|
-
@grpc.under_exposed_likelihood
|
1414
|
-
end
|
1415
|
-
|
1416
|
-
##
|
1417
|
-
# Under Exposed likelihood. Returns `true` if {#under_exposed} is
|
1418
|
-
# `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.
|
1419
|
-
#
|
1420
|
-
# @return [Boolean]
|
1421
|
-
#
|
1422
|
-
def under_exposed?
|
1423
|
-
POSITIVE_RATINGS.include? under_exposed
|
1424
|
-
end
|
1425
|
-
|
1426
|
-
##
|
1427
|
-
# Blurred likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1428
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1429
|
-
def blurred
|
1430
|
-
@grpc.blurred_likelihood
|
1431
|
-
end
|
1432
|
-
|
1433
|
-
##
|
1434
|
-
# Blurred likelihood. Returns `true` if {#blurred} is `POSSIBLE`,
|
1435
|
-
# `LIKELY`, or `VERY_LIKELY`.
|
1436
|
-
#
|
1437
|
-
# @return [Boolean]
|
1438
|
-
#
|
1439
|
-
def blurred?
|
1440
|
-
POSITIVE_RATINGS.include? blurred
|
1441
|
-
end
|
1442
|
-
|
1443
|
-
##
|
1444
|
-
# Headwear likelihood rating. Possible values are `VERY_UNLIKELY`,
|
1445
|
-
# `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
|
1446
|
-
def headwear
|
1447
|
-
@grpc.headwear_likelihood
|
1448
|
-
end
|
1449
|
-
|
1450
|
-
##
|
1451
|
-
# Headwear likelihood. Returns `true` if {#headwear} is `POSSIBLE`,
|
1452
|
-
# `LIKELY`, or `VERY_LIKELY`.
|
1453
|
-
#
|
1454
|
-
# @return [Boolean]
|
1455
|
-
#
|
1456
|
-
def headwear?
|
1457
|
-
POSITIVE_RATINGS.include? headwear
|
1458
|
-
end
|
1459
|
-
|
1460
|
-
##
|
1461
|
-
# Converts object to a hash. All keys will be symbolized.
|
1462
|
-
#
|
1463
|
-
# @return [Hash]
|
1464
|
-
#
|
1465
|
-
def to_h
|
1466
|
-
{ joy: joy?, sorrow: sorrow?, anger: anger?, surprise: surprise?,
|
1467
|
-
under_exposed: under_exposed?, blurred: blurred?,
|
1468
|
-
headwear: headwear? }
|
1469
|
-
end
|
1470
|
-
|
1471
|
-
# @private
|
1472
|
-
def to_s
|
1473
|
-
tmplt = "(joy?: %s, sorrow?: %s, anger?: %s, " \
|
1474
|
-
"surprise?: %s, under_exposed?: %s, blurred?: %s, " \
|
1475
|
-
"headwear: %s)"
|
1476
|
-
format tmplt, joy?.inspect, sorrow?.inspect, anger?.inspect,
|
1477
|
-
surprise?.inspect, under_exposed?.inspect,
|
1478
|
-
blurred?.inspect, headwear?.inspect
|
1479
|
-
end
|
1480
|
-
|
1481
|
-
# @private
|
1482
|
-
def inspect
|
1483
|
-
"#<Likelihood #{self}>"
|
1484
|
-
end
|
1485
|
-
|
1486
|
-
##
|
1487
|
-
# @private New Annotation::Face::Likelihood from a GRPC
|
1488
|
-
# object.
|
1489
|
-
def self.from_grpc grpc
|
1490
|
-
new.tap { |f| f.instance_variable_set :@grpc, grpc }
|
1491
|
-
end
|
1492
|
-
end
|
1493
|
-
end
|
1494
|
-
end
|
1495
|
-
end
|
1496
|
-
end
|
1497
|
-
end
|