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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -9
  3. data/LICENSE +1 -1
  4. data/README.md +94 -0
  5. data/lib/google/cloud/vision.rb +200 -535
  6. data/lib/google/cloud/vision/v1.rb +129 -55
  7. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/image_annotator.rb +9 -0
  8. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search.rb +88 -0
  9. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search_service.rb +539 -0
  10. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/text_annotation.rb +3 -3
  11. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/web_detection.rb +2 -1
  12. data/lib/google/cloud/vision/{version.rb → v1/doc/google/protobuf/empty.rb} +13 -6
  13. data/lib/google/cloud/vision/v1/doc/google/protobuf/field_mask.rb +230 -0
  14. data/lib/google/cloud/vision/v1/doc/google/protobuf/timestamp.rb +109 -0
  15. data/lib/google/cloud/vision/v1/geometry_pb.rb +1 -0
  16. data/lib/google/cloud/vision/v1/helpers.rb +972 -0
  17. data/lib/google/cloud/vision/v1/image_annotator_client.rb +4 -4
  18. data/lib/google/cloud/vision/v1/image_annotator_pb.rb +5 -0
  19. data/lib/google/cloud/vision/v1/image_annotator_services_pb.rb +2 -1
  20. data/lib/google/cloud/vision/v1/product_search_client.rb +1337 -0
  21. data/lib/google/cloud/vision/v1/product_search_client_config.json +116 -0
  22. data/lib/google/cloud/vision/v1/product_search_pb.rb +45 -0
  23. data/lib/google/cloud/vision/v1/product_search_service_pb.rb +191 -0
  24. data/lib/google/cloud/vision/v1/product_search_service_services_pb.rb +224 -0
  25. data/lib/google/cloud/vision/v1p3beta1.rb +233 -0
  26. data/lib/google/cloud/vision/v1p3beta1/credentials.rb +42 -0
  27. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/geometry.rb +72 -0
  28. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/image_annotator.rb +763 -0
  29. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search.rb +154 -0
  30. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search_service.rb +533 -0
  31. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/text_annotation.rb +254 -0
  32. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/web_detection.rb +101 -0
  33. data/lib/google/cloud/vision/v1p3beta1/doc/google/longrunning/operations.rb +93 -0
  34. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/any.rb +130 -0
  35. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/empty.rb +29 -0
  36. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/field_mask.rb +230 -0
  37. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/timestamp.rb +109 -0
  38. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/wrappers.rb +90 -0
  39. data/lib/google/cloud/vision/v1p3beta1/doc/google/rpc/status.rb +84 -0
  40. data/lib/google/cloud/vision/v1p3beta1/doc/google/type/color.rb +156 -0
  41. data/lib/google/cloud/vision/v1p3beta1/doc/google/type/latlng.rb +65 -0
  42. data/lib/google/cloud/vision/v1p3beta1/geometry_pb.rb +43 -0
  43. data/lib/google/cloud/vision/v1p3beta1/helpers.rb +972 -0
  44. data/lib/google/cloud/vision/v1p3beta1/image_annotator_client.rb +302 -0
  45. data/lib/google/cloud/vision/v1p3beta1/image_annotator_client_config.json +36 -0
  46. data/lib/google/cloud/vision/v1p3beta1/image_annotator_pb.rb +304 -0
  47. data/lib/google/cloud/vision/v1p3beta1/image_annotator_services_pb.rb +55 -0
  48. data/lib/google/cloud/vision/v1p3beta1/product_search_client.rb +1351 -0
  49. data/lib/google/cloud/vision/v1p3beta1/product_search_client_config.json +116 -0
  50. data/lib/google/cloud/vision/v1p3beta1/product_search_pb.rb +64 -0
  51. data/lib/google/cloud/vision/v1p3beta1/product_search_service_pb.rb +191 -0
  52. data/lib/google/cloud/vision/v1p3beta1/product_search_service_services_pb.rb +222 -0
  53. data/lib/google/cloud/vision/v1p3beta1/text_annotation_pb.rb +94 -0
  54. data/lib/google/cloud/vision/v1p3beta1/web_detection_pb.rb +51 -0
  55. metadata +53 -122
  56. data/AUTHENTICATION.md +0 -179
  57. data/CHANGELOG.md +0 -109
  58. data/CODE_OF_CONDUCT.md +0 -40
  59. data/CONTRIBUTING.md +0 -188
  60. data/LOGGING.md +0 -32
  61. data/OVERVIEW.md +0 -202
  62. data/TROUBLESHOOTING.md +0 -37
  63. data/lib/google-cloud-vision.rb +0 -146
  64. data/lib/google/cloud/vision/annotate.rb +0 -303
  65. data/lib/google/cloud/vision/annotation.rb +0 -553
  66. data/lib/google/cloud/vision/annotation/crop_hint.rb +0 -126
  67. data/lib/google/cloud/vision/annotation/entity.rb +0 -225
  68. data/lib/google/cloud/vision/annotation/face.rb +0 -1497
  69. data/lib/google/cloud/vision/annotation/normalized_vertex.rb +0 -76
  70. data/lib/google/cloud/vision/annotation/object_localization.rb +0 -115
  71. data/lib/google/cloud/vision/annotation/properties.rb +0 -220
  72. data/lib/google/cloud/vision/annotation/safe_search.rb +0 -153
  73. data/lib/google/cloud/vision/annotation/text.rb +0 -1015
  74. data/lib/google/cloud/vision/annotation/vertex.rb +0 -91
  75. data/lib/google/cloud/vision/annotation/web.rb +0 -420
  76. data/lib/google/cloud/vision/credentials.rb +0 -57
  77. data/lib/google/cloud/vision/image.rb +0 -832
  78. data/lib/google/cloud/vision/location.rb +0 -98
  79. data/lib/google/cloud/vision/project.rb +0 -367
  80. data/lib/google/cloud/vision/service.rb +0 -83
@@ -1,76 +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
- module Google
17
- module Cloud
18
- module Vision
19
- class Annotation
20
- ##
21
- # # NormalizedVertex
22
- #
23
- # A normalized vertex in a set of bounding polygon vertices.
24
- #
25
- # @attr_reader [Float] x The X coordinate.
26
- # @attr_reader [Float] y The Y coordinate.
27
- #
28
- class NormalizedVertex
29
- attr_reader :x, :y
30
-
31
- ##
32
- # @private Creates a new NormalizedVertex instance.
33
- def initialize x, y
34
- @x = x
35
- @y = y
36
- end
37
-
38
- ##
39
- # Returns the object's property values as an array.
40
- #
41
- # @return [Array]
42
- #
43
- def to_a
44
- [x, y]
45
- end
46
-
47
- ##
48
- # Converts object to a hash. All keys will be symbolized.
49
- #
50
- # @return [Hash]
51
- #
52
- def to_h
53
- { x: x, y: y }
54
- end
55
-
56
- # @private
57
- def to_s
58
- "(x: #{x.inspect}, y: #{y.inspect})"
59
- end
60
-
61
- # @private
62
- def inspect
63
- "#<NormalizedVertex #{self}>"
64
- end
65
-
66
- ##
67
- # @private New Annotation::Entity::Bounds::Vertex from a Google API
68
- # Client object.
69
- def self.from_grpc grpc
70
- new grpc.x, grpc.y
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,115 +0,0 @@
1
- # Copyright 2018 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/normalized_vertex"
17
-
18
- module Google
19
- module Cloud
20
- module Vision
21
- class Annotation
22
- class ObjectLocalization
23
- ##
24
- # @private The LocalizedObjectAnnotation GRPC object.
25
- attr_accessor :grpc
26
-
27
- ##
28
- # @private Creates a new Web instance.
29
- def initialize
30
- @grpc = nil
31
- end
32
-
33
- ##
34
- # Opaque entity ID. Should align with {Entity#mid}.
35
- #
36
- # @return [String] The opaque entity ID.
37
- #
38
- def mid
39
- @grpc.mid
40
- end
41
-
42
- ##
43
- # The BCP-47 language code, such as "en-US" or "sr-Latn".
44
- #
45
- # @see http://www.unicode.org/reports/tr35/#Unicode_locale_identifier
46
- #
47
- # @return [String] The language code.
48
- #
49
- def code
50
- @grpc.language_code
51
- end
52
-
53
- ##
54
- # Object name, expressed in its {#code} language.
55
- #
56
- # @return [String] The object name.
57
- #
58
- def name
59
- @grpc.name
60
- end
61
-
62
- ##
63
- # The score of the result. Range [0, 1].
64
- #
65
- # @return [Float] A value in the range [0, 1].
66
- #
67
- def score
68
- @grpc.score
69
- end
70
-
71
- ##
72
- # Image region to which this entity belongs.
73
- #
74
- # @return [Array<NormalizedVertex>] An array of normalized vertices.
75
- #
76
- def bounds
77
- return [] unless @grpc.bounding_poly
78
- @bounds ||= @grpc.bounding_poly.normalized_vertices.map do |v|
79
- NormalizedVertex.from_grpc v
80
- end
81
- end
82
-
83
- ##
84
- # Deeply converts object to a hash. All keys will be symbolized.
85
- #
86
- # @return [Hash]
87
- #
88
- def to_h
89
- { mid: mid, code: code, name: name, score: score,
90
- bounds: bounds.map(&:to_h) }
91
- end
92
-
93
- # @private
94
- def to_s
95
- tmplt = "mid: %s, code: %s, name: %s, score: %s, " \
96
- " bounds: %i"
97
- format tmplt, mid.inspect, code.inspect, name.inspect,
98
- score.inspect, bounds.count
99
- end
100
-
101
- # @private
102
- def inspect
103
- "#<#{self.class.name} #{self}>"
104
- end
105
-
106
- ##
107
- # @private New Annotation::Face from a GRPC object.
108
- def self.from_grpc grpc
109
- new.tap { |ol| ol.instance_variable_set :@grpc, grpc }
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,220 +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
- module Google
17
- module Cloud
18
- module Vision
19
- class Annotation
20
- ##
21
- # # Properties
22
- #
23
- # A set of properties about an image, such as the image's dominant
24
- # colors.
25
- #
26
- # See {Google::Cloud::Vision::Image#properties}.
27
- #
28
- # @example
29
- # require "google/cloud/vision"
30
- #
31
- # vision = Google::Cloud::Vision.new
32
- #
33
- # image = vision.image "path/to/logo.jpg"
34
- #
35
- # properties = image.properties
36
- # properties.colors.count #=> 10
37
- #
38
- class Properties
39
- ##
40
- # @private The ImageProperties GRPC object.
41
- attr_accessor :grpc
42
-
43
- ##
44
- # @private Creates a new Properties instance.
45
- def initialize
46
- @grpc = nil
47
- end
48
-
49
- ##
50
- # The image's dominant colors, including their corresponding scores.
51
- #
52
- # @return [Array<Color>] An array of the image's dominant colors.
53
- #
54
- def colors
55
- return [] unless @grpc.dominant_colors
56
- @colors ||= Array(@grpc.dominant_colors.colors).map do |c|
57
- Color.from_grpc c
58
- end
59
- end
60
-
61
- ##
62
- # Returns the object's property values as an array.
63
- #
64
- # @return [Array]
65
- #
66
- def to_a
67
- colors.map(&:rgb)
68
- end
69
-
70
- ##
71
- # Deeply converts object to a hash. All keys will be symbolized.
72
- #
73
- # @return [Hash]
74
- #
75
- def to_h
76
- { colors: colors.map(&:to_h) }
77
- end
78
-
79
- # @private
80
- def to_s
81
- "(colors: #{colors.count})"
82
- end
83
-
84
- # @private
85
- def inspect
86
- "#<Properties #{self}>"
87
- end
88
-
89
- ##
90
- # @private New Annotation::Properties from a GRPC object.
91
- def self.from_grpc grpc
92
- new.tap { |f| f.instance_variable_set :@grpc, grpc }
93
- end
94
-
95
- ##
96
- # # Color
97
- #
98
- # Color information consisting of RGB channels, score, and fraction of
99
- # image the color occupies in the image.
100
- #
101
- # @example
102
- # require "google/cloud/vision"
103
- #
104
- # vision = Google::Cloud::Vision.new
105
- #
106
- # image = vision.image "path/to/logo.jpg"
107
- # properties = image.properties
108
- #
109
- # color = properties.colors.first
110
- # color.red #=> 247.0
111
- # color.green #=> 236.0
112
- # color.blue #=> 20.0
113
- # color.rgb #=> "f7ec14"
114
- # color.alpha #=> 1.0
115
- # color.score #=> 0.20301803946495056
116
- # color.pixel_fraction #=> 0.007264957297593355
117
- #
118
- class Color
119
- ##
120
- # @private The ColorInfo GRPC object.
121
- attr_accessor :grpc
122
-
123
- ##
124
- # @private Creates a new Color instance.
125
- def initialize
126
- @grpc = nil
127
- end
128
-
129
- ##
130
- # The amount of red in the color.
131
- #
132
- # @return [Float] A value in the interval [0, 255].
133
- #
134
- def red
135
- @grpc.color.red
136
- end
137
-
138
- ##
139
- # The amount of green in the color.
140
- #
141
- # @return [Float] A value in the interval [0, 255].
142
- #
143
- def green
144
- @grpc.color.green
145
- end
146
-
147
- ##
148
- # The amount of blue in the color.
149
- #
150
- # @return [Float] A value in the interval [0, 255].
151
- #
152
- def blue
153
- @grpc.color.blue
154
- end
155
-
156
- ##
157
- # The amount this color that should be applied to the pixel. A value
158
- # of 1.0 corresponds to a solid color, whereas a value of 0.0
159
- # corresponds to a completely transparent color.
160
- #
161
- # @return [Float] A value in the range [0, 1].
162
- #
163
- def alpha
164
- @grpc.color.alpha || 1.0
165
- end
166
-
167
- def rgb
168
- red.to_i.to_s(16).rjust(2, "0") +
169
- green.to_i.to_s(16).rjust(2, "0") +
170
- blue.to_i.to_s(16).rjust(2, "0")
171
- end
172
-
173
- ##
174
- # Image-specific score for this color.
175
- #
176
- # @return [Float] A value in the range [0, 1].
177
- #
178
- def score
179
- @grpc.score
180
- end
181
-
182
- ##
183
- # Stores the fraction of pixels the color occupies in the image.
184
- #
185
- # @return [Float] A value in the range [0, 1].
186
- #
187
- def pixel_fraction
188
- @grpc.pixel_fraction
189
- end
190
-
191
- ##
192
- # Converts object to a hash. All keys will be symbolized.
193
- #
194
- # @return [Hash]
195
- #
196
- def to_h
197
- { red: red, green: green, blue: blue, alpha: alpha, rgb: rgb,
198
- score: score, pixel_fraction: pixel_fraction }
199
- end
200
-
201
- def to_s
202
- "(colors: #{rgb})"
203
- end
204
-
205
- def inspect
206
- "#<Color #{self}>"
207
- end
208
-
209
- ##
210
- # @private New Annotation::Properties from a GRPC
211
- # object.
212
- def self.from_grpc grpc
213
- new.tap { |f| f.instance_variable_set :@grpc, grpc }
214
- end
215
- end
216
- end
217
- end
218
- end
219
- end
220
- end
@@ -1,153 +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
- # # SafeSearch
24
- #
25
- # A set of features pertaining to the image, computed by various
26
- # computer vision methods over safe-search verticals (for example,
27
- # adult, spoof, medical, violence).
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
- # safe_search = image.safe_search
37
- # safe_search.spoof? #=> false
38
- # safe_search.spoof #=> :VERY_UNLIKELY
39
- #
40
- class SafeSearch
41
- POSITIVE_RATINGS = %i[POSSIBLE LIKELY VERY_LIKELY].freeze
42
-
43
- ##
44
- # @private The SafeSearchAnnotation GRPC object.
45
- attr_accessor :grpc
46
-
47
- ##
48
- # @private Creates a new SafeSearch instance.
49
- def initialize
50
- @grpc = nil
51
- end
52
-
53
- ##
54
- # Adult likelihood rating. Possible values are `VERY_UNLIKELY`,
55
- # `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
56
- def adult
57
- @grpc.adult
58
- end
59
-
60
- ##
61
- # Adult likelihood. Returns `true` if {#adult} is `POSSIBLE`,
62
- # `LIKELY`, or `VERY_LIKELY`.
63
- #
64
- # @return [Boolean]
65
- #
66
- def adult?
67
- POSITIVE_RATINGS.include? adult
68
- end
69
-
70
- ##
71
- # Spoof likelihood rating. Possible values are `VERY_UNLIKELY`,
72
- # `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
73
- def spoof
74
- @grpc.spoof
75
- end
76
-
77
- ##
78
- # Spoof likelihood. Returns `true` if {#spoof} is `POSSIBLE`,
79
- # `LIKELY`, or `VERY_LIKELY`.
80
- #
81
- # @return [Boolean]
82
- #
83
- def spoof?
84
- POSITIVE_RATINGS.include? spoof
85
- end
86
-
87
- ##
88
- # Medical likelihood rating. Possible values are `VERY_UNLIKELY`,
89
- # `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
90
- def medical
91
- @grpc.medical
92
- end
93
-
94
- ##
95
- # Medical likelihood. Returns `true` if {#medical} is `POSSIBLE`,
96
- # `LIKELY`, or `VERY_LIKELY`.
97
- #
98
- # @return [Boolean]
99
- #
100
- def medical?
101
- POSITIVE_RATINGS.include? medical
102
- end
103
-
104
- ##
105
- # Violence likelihood rating. Possible values are `VERY_UNLIKELY`,
106
- # `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.
107
- def violence
108
- @grpc.violence
109
- end
110
-
111
- ##
112
- # Violence likelihood. Returns `true` if {#violence} is `POSSIBLE`,
113
- # `LIKELY`, or `VERY_LIKELY`.
114
- #
115
- # @return [Boolean]
116
- #
117
- def violence?
118
- POSITIVE_RATINGS.include? violence
119
- end
120
-
121
- ##
122
- # Converts object to a hash. All keys will be symbolized.
123
- #
124
- # @return [Hash]
125
- #
126
- def to_h
127
- { adult: adult?, spoof: spoof?, medical: medical?,
128
- violence: violence? }
129
- end
130
-
131
- # @private
132
- def to_s
133
- tmplt = "(adult?: %s, spoof?: %s, medical?: %s, " \
134
- "violence?: %s)"
135
- format tmplt, adult?.inspect, spoof?.inspect, medical?.inspect,
136
- violence?.inspect
137
- end
138
-
139
- # @private
140
- def inspect
141
- "#<SafeSearch #{self}>"
142
- end
143
-
144
- ##
145
- # @private New Annotation::SafeSearch from a GRPC object.
146
- def self.from_grpc grpc
147
- new.tap { |f| f.instance_variable_set :@grpc, grpc }
148
- end
149
- end
150
- end
151
- end
152
- end
153
- end