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,553 +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/face"
17
- require "google/cloud/vision/annotation/entity"
18
- require "google/cloud/vision/annotation/text"
19
- require "google/cloud/vision/annotation/safe_search"
20
- require "google/cloud/vision/annotation/properties"
21
- require "google/cloud/vision/annotation/crop_hint"
22
- require "google/cloud/vision/annotation/web"
23
- require "google/cloud/vision/annotation/object_localization"
24
-
25
- module Google
26
- module Cloud
27
- module Vision
28
- ##
29
- # # Annotation
30
- #
31
- # The results of all requested image annotations.
32
- #
33
- # See {Project#annotate} and {Image}.
34
- #
35
- # @example
36
- # require "google/cloud/vision"
37
- #
38
- # vision = Google::Cloud::Vision.new
39
- # image = vision.image "path/to/face.jpg"
40
- #
41
- # annotation = vision.annotate image, faces: true, labels: true
42
- # annotation.faces.count #=> 1
43
- # annotation.labels.count #=> 4
44
- # annotation.text #=> nil
45
- #
46
- class Annotation
47
- ##
48
- # @private The AnnotateImageResponse GRPC object.
49
- attr_accessor :grpc
50
-
51
- ##
52
- # @private Creates a new Annotation instance.
53
- def initialize
54
- @grpc = nil
55
- end
56
-
57
- ##
58
- # The results of face detection.
59
- #
60
- # @return [Array<Face>]
61
- #
62
- # @example
63
- # require "google/cloud/vision"
64
- #
65
- # vision = Google::Cloud::Vision.new
66
- # image = vision.image "path/to/face.jpg"
67
- #
68
- # annotation = vision.annotate image, faces: true
69
- # annotation.faces.count #=> 1
70
- # face = annotation.faces.first
71
- #
72
- def faces
73
- @faces ||= Array(@grpc.face_annotations).map do |fa|
74
- Face.from_grpc fa
75
- end
76
- end
77
-
78
- ##
79
- # The first face result, if there is one.
80
- #
81
- # @return [Face]
82
- #
83
- # @example
84
- # require "google/cloud/vision"
85
- #
86
- # vision = Google::Cloud::Vision.new
87
- # image = vision.image "path/to/face.jpg"
88
- #
89
- # annotation = vision.annotate image, faces: 1
90
- # face = annotation.face
91
- #
92
- def face
93
- faces.first
94
- end
95
-
96
- ##
97
- # Whether there is at least one result from face detection.
98
- #
99
- # @return [Boolean]
100
- #
101
- # @example
102
- # require "google/cloud/vision"
103
- #
104
- # vision = Google::Cloud::Vision.new
105
- # image = vision.image "path/to/face.jpg"
106
- #
107
- # annotation = vision.annotate image, faces: 1
108
- # annotation.face? #=> true
109
- #
110
- def face?
111
- faces.any?
112
- end
113
-
114
- ##
115
- # The results of landmark detection.
116
- #
117
- # @return [Array<Entity>]
118
- #
119
- # @example
120
- # require "google/cloud/vision"
121
- #
122
- # vision = Google::Cloud::Vision.new
123
- # image = vision.image "path/to/landmark.jpg"
124
- #
125
- # annotation = vision.annotate image, landmarks: 1
126
- # annotation.landmarks.count #=> 1
127
- # landmark = annotation.landmarks.first
128
- #
129
- def landmarks
130
- @landmarks ||= Array(@grpc.landmark_annotations).map do |lm|
131
- Entity.from_grpc lm
132
- end
133
- end
134
-
135
- ##
136
- # The first landmark result, if there is one.
137
- #
138
- # @return [Entity]
139
- #
140
- # @example
141
- # require "google/cloud/vision"
142
- #
143
- # vision = Google::Cloud::Vision.new
144
- # image = vision.image "path/to/landmark.jpg"
145
- #
146
- # annotation = vision.annotate image, landmarks: 1
147
- # landmark = annotation.landmark
148
- #
149
- def landmark
150
- landmarks.first
151
- end
152
-
153
- ##
154
- # Whether there is at least one result from landmark detection.
155
- # detection.
156
- #
157
- # @return [Boolean]
158
- #
159
- # @example
160
- # require "google/cloud/vision"
161
- #
162
- # vision = Google::Cloud::Vision.new
163
- # image = vision.image "path/to/landmark.jpg"
164
- #
165
- # annotation = vision.annotate image, landmarks: 1
166
- # annotation.landmark? #=> true
167
- #
168
- def landmark?
169
- landmarks.any?
170
- end
171
-
172
- ##
173
- # The results of logo detection.
174
- #
175
- # @return [Array<Entity>]
176
- #
177
- # @example
178
- # require "google/cloud/vision"
179
- #
180
- # vision = Google::Cloud::Vision.new
181
- # image = vision.image "path/to/logo.jpg"
182
- #
183
- # annotation = vision.annotate image, logos: 1
184
- # annotation.logos.count #=> 1
185
- # logo = annotation.logos.first
186
- #
187
- def logos
188
- @logos ||= Array(@grpc.logo_annotations).map do |lg|
189
- Entity.from_grpc lg
190
- end
191
- end
192
-
193
- ##
194
- # The first logo result, if there is one.
195
- #
196
- # @return [Entity]
197
- #
198
- # @example
199
- # require "google/cloud/vision"
200
- #
201
- # vision = Google::Cloud::Vision.new
202
- # image = vision.image "path/to/logo.jpg"
203
- #
204
- # annotation = vision.annotate image, logos: 1
205
- # logo = annotation.logo
206
- #
207
- def logo
208
- logos.first
209
- end
210
-
211
- ##
212
- # Whether there is at least one result from logo detection.
213
- # detection.
214
- #
215
- # @return [Boolean]
216
- #
217
- # @example
218
- # require "google/cloud/vision"
219
- #
220
- # vision = Google::Cloud::Vision.new
221
- # image = vision.image "path/to/logo.jpg"
222
- #
223
- # annotation = vision.annotate image, logos: 1
224
- # annotation.logo? #=> true
225
- #
226
- def logo?
227
- logos.any?
228
- end
229
-
230
- ##
231
- # The results of label detection.
232
- #
233
- # @return [Array<Entity>]
234
- #
235
- # @example
236
- # require "google/cloud/vision"
237
- #
238
- # vision = Google::Cloud::Vision.new
239
- # image = vision.image "path/to/face.jpg"
240
- #
241
- # annotation = vision.annotate image, labels: 1
242
- # annotation.labels.count #=> 1
243
- # label = annotation.labels.first
244
- #
245
- def labels
246
- @labels ||= Array(@grpc.label_annotations).map do |lb|
247
- Entity.from_grpc lb
248
- end
249
- end
250
-
251
- ##
252
- # The first label result, if there is one.
253
- #
254
- # @return [Entity]
255
- #
256
- # @example
257
- # require "google/cloud/vision"
258
- #
259
- # vision = Google::Cloud::Vision.new
260
- # image = vision.image "path/to/face.jpg"
261
- #
262
- # annotation = vision.annotate image, labels: 1
263
- # label = annotation.label
264
- #
265
- def label
266
- labels.first
267
- end
268
-
269
- ##
270
- # Whether there is at least one result from label detection.
271
- # detection.
272
- #
273
- # @return [Boolean]
274
- #
275
- # @example
276
- # require "google/cloud/vision"
277
- #
278
- # vision = Google::Cloud::Vision.new
279
- # image = vision.image "path/to/face.jpg"
280
- #
281
- # annotation = vision.annotate image, labels: 1
282
- # annotation.label? #=> true
283
- #
284
- def label?
285
- labels.any?
286
- end
287
-
288
- ##
289
- # The results of text (OCR) detection.
290
- #
291
- # @return [Text]
292
- #
293
- # @example
294
- # require "google/cloud/vision"
295
- #
296
- # vision = Google::Cloud::Vision.new
297
- # image = vision.image "path/to/text.png"
298
- #
299
- # annotation = vision.annotate image, text: true
300
- # text = annotation.text
301
- #
302
- def text
303
- @text ||= \
304
- Text.from_grpc(@grpc.text_annotations, @grpc.full_text_annotation)
305
- end
306
-
307
- ##
308
- # Whether there is a result from text (OCR) detection.
309
- #
310
- # @return [Boolean]
311
- #
312
- # @example
313
- # require "google/cloud/vision"
314
- #
315
- # vision = Google::Cloud::Vision.new
316
- # image = vision.image "path/to/text.png"
317
- #
318
- # annotation = vision.annotate image, text: true
319
- # annotation.text? #=> true
320
- #
321
- def text?
322
- !text.nil?
323
- end
324
-
325
- ##
326
- # The results of safe_search detection.
327
- #
328
- # @return [SafeSearch, nil]
329
- #
330
- # @example
331
- # require "google/cloud/vision"
332
- #
333
- # vision = Google::Cloud::Vision.new
334
- # image = vision.image "path/to/face.jpg"
335
- #
336
- # annotation = vision.annotate image, safe_search: true
337
- # safe_search = annotation.safe_search
338
- #
339
- def safe_search
340
- return nil unless @grpc.safe_search_annotation
341
- @safe_search ||= SafeSearch.from_grpc(@grpc.safe_search_annotation)
342
- end
343
-
344
- ##
345
- # Whether there is a result for safe_search detection.
346
- # detection.
347
- #
348
- # @return [Boolean]
349
- #
350
- # @example
351
- # require "google/cloud/vision"
352
- #
353
- # vision = Google::Cloud::Vision.new
354
- # image = vision.image "path/to/face.jpg"
355
- #
356
- # annotation = vision.annotate image, safe_search: true
357
- # annotation.safe_search? #=> true
358
- #
359
- def safe_search?
360
- !safe_search.nil?
361
- end
362
-
363
- ##
364
- # The results of properties detection.
365
- #
366
- # @return [Properties, nil]
367
- #
368
- # @example
369
- # require "google/cloud/vision"
370
- #
371
- # vision = Google::Cloud::Vision.new
372
- # image = vision.image "path/to/face.jpg"
373
- #
374
- # annotation = vision.annotate image, properties: true
375
- # properties = annotation.properties
376
- #
377
- def properties
378
- return nil unless @grpc.image_properties_annotation
379
- @properties ||= Properties.from_grpc(
380
- @grpc.image_properties_annotation
381
- )
382
- end
383
-
384
- ##
385
- # Whether there is a result for properties detection.
386
- #
387
- # @return [Boolean]
388
- #
389
- # @example
390
- # require "google/cloud/vision"
391
- #
392
- # vision = Google::Cloud::Vision.new
393
- # image = vision.image "path/to/face.jpg"
394
- #
395
- # annotation = vision.annotate image, properties: true
396
- # annotation.properties? #=> true
397
- #
398
- def properties?
399
- !properties.nil?
400
- end
401
-
402
- ##
403
- # The results of crop hints detection.
404
- #
405
- # @return [Array<CropHint>]
406
- #
407
- # @example
408
- # require "google/cloud/vision"
409
- #
410
- # vision = Google::Cloud::Vision.new
411
- # image = vision.image "path/to/face.jpg"
412
- #
413
- # annotation = vision.annotate image, crop_hints: true
414
- # crop_hints = annotation.crop_hints
415
- #
416
- def crop_hints
417
- return [] unless @grpc.crop_hints_annotation
418
- grpc_crop_hints = @grpc.crop_hints_annotation.crop_hints
419
- @crop_hints ||= Array(grpc_crop_hints).map do |ch|
420
- CropHint.from_grpc ch
421
- end
422
- end
423
-
424
- ##
425
- # Whether there is a result for crop hints detection.
426
- #
427
- # @return [Boolean]
428
- #
429
- # @example
430
- # require "google/cloud/vision"
431
- #
432
- # vision = Google::Cloud::Vision.new
433
- # image = vision.image "path/to/face.jpg"
434
- #
435
- # annotation = vision.annotate image, crop_hints: true
436
- # annotation.crop_hints? #=> true
437
- #
438
- def crop_hints?
439
- crop_hints.any?
440
- end
441
-
442
- ##
443
- # The results of web detection.
444
- #
445
- # @return [Web]
446
- #
447
- # @example
448
- # require "google/cloud/vision"
449
- #
450
- # vision = Google::Cloud::Vision.new
451
- # image = vision.image "path/to/face.jpg"
452
- #
453
- # annotation = vision.annotate image, web: true
454
- # web = annotation.web
455
- #
456
- def web
457
- return nil unless @grpc.web_detection
458
- @web ||= Web.from_grpc(@grpc.web_detection)
459
- end
460
-
461
- ##
462
- # Whether there is a result for web detection.
463
- #
464
- # @return [Boolean]
465
- #
466
- # @example
467
- # require "google/cloud/vision"
468
- #
469
- # vision = Google::Cloud::Vision.new
470
- # image = vision.image "path/to/face.jpg"
471
- #
472
- # annotation = vision.annotate image, web: true
473
- # annotation.web? #=> true
474
- #
475
- def web?
476
- !web.nil?
477
- end
478
-
479
- ##
480
- # The results of object localizations detection.
481
- #
482
- # @return [Array<ObjectLocalization>]
483
- #
484
- # @example
485
- # require "google/cloud/vision"
486
- #
487
- # vision = Google::Cloud::Vision.new
488
- # image = vision.image "path/to/face.jpg"
489
- #
490
- # annotation = vision.annotate image, object_localizations: true
491
- # object_localizations = annotation.object_localizations
492
- #
493
- def object_localizations
494
- @ol ||= @grpc.localized_object_annotations.map do |ol|
495
- ObjectLocalization.from_grpc ol
496
- end
497
- end
498
-
499
- ##
500
- # Whether there is a result for object localizations detection.
501
- #
502
- # @return [Boolean]
503
- #
504
- # @example
505
- # require "google/cloud/vision"
506
- #
507
- # vision = Google::Cloud::Vision.new
508
- # image = vision.image "path/to/face.jpg"
509
- #
510
- # annotation = vision.annotate image, object_localizations: true
511
- # annotation.object_localizations? #=> true
512
- #
513
- def object_localizations?
514
- !object_localizations.empty?
515
- end
516
-
517
- ##
518
- # Deeply converts object to a hash. All keys will be symbolized.
519
- #
520
- # @return [Hash]
521
- #
522
- def to_h
523
- { faces: faces.map(&:to_h), landmarks: landmarks.map(&:to_h),
524
- logos: logos.map(&:to_h), labels: labels.map(&:to_h),
525
- text: text.to_h, safe_search: safe_search.to_h,
526
- properties: properties.to_h, crop_hints: crop_hints.map(&:to_h),
527
- web: web.to_h, object_localizations: object_localizations.to_h }
528
- end
529
-
530
- # @private
531
- def to_s
532
- tmplt = "(faces: %i, landmarks: %i, logos: %i, labels: %i," \
533
- " text: %s, safe_search: %s, properties: %s," \
534
- " crop_hints: %s, web: %s, object_localizations: %i)"
535
- format tmplt, faces.count, landmarks.count, logos.count, labels.count,
536
- text?, safe_search?, properties?, crop_hints?, web?,
537
- object_localizations.count
538
- end
539
-
540
- # @private
541
- def inspect
542
- "#<#{self.class.name} #{self}>"
543
- end
544
-
545
- ##
546
- # @private New Annotation from a GRPC object.
547
- def self.from_grpc grpc
548
- new.tap { |a| a.instance_variable_set :@grpc, grpc }
549
- end
550
- end
551
- end
552
- end
553
- end