google-cloud-vision-v1p4beta1 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +12 -0
  3. data/AUTHENTICATION.md +169 -0
  4. data/LICENSE.md +201 -0
  5. data/README.md +139 -0
  6. data/lib/google/cloud/vision/v1p4beta1/face_pb.rb +35 -0
  7. data/lib/google/cloud/vision/v1p4beta1/geometry_pb.rb +40 -0
  8. data/lib/google/cloud/vision/v1p4beta1/image_annotator/client.rb +629 -0
  9. data/lib/google/cloud/vision/v1p4beta1/image_annotator/credentials.rb +52 -0
  10. data/lib/google/cloud/vision/v1p4beta1/image_annotator/helpers.rb +1228 -0
  11. data/lib/google/cloud/vision/v1p4beta1/image_annotator/operations.rb +664 -0
  12. data/lib/google/cloud/vision/v1p4beta1/image_annotator/paths.rb +52 -0
  13. data/lib/google/cloud/vision/v1p4beta1/image_annotator.rb +52 -0
  14. data/lib/google/cloud/vision/v1p4beta1/image_annotator_pb.rb +343 -0
  15. data/lib/google/cloud/vision/v1p4beta1/image_annotator_services_pb.rb +73 -0
  16. data/lib/google/cloud/vision/v1p4beta1/product_search/client.rb +2106 -0
  17. data/lib/google/cloud/vision/v1p4beta1/product_search/credentials.rb +52 -0
  18. data/lib/google/cloud/vision/v1p4beta1/product_search/operations.rb +664 -0
  19. data/lib/google/cloud/vision/v1p4beta1/product_search/paths.rb +109 -0
  20. data/lib/google/cloud/vision/v1p4beta1/product_search.rb +67 -0
  21. data/lib/google/cloud/vision/v1p4beta1/product_search_pb.rb +55 -0
  22. data/lib/google/cloud/vision/v1p4beta1/product_search_service_pb.rb +208 -0
  23. data/lib/google/cloud/vision/v1p4beta1/product_search_service_services_pb.rb +236 -0
  24. data/lib/google/cloud/vision/v1p4beta1/text_annotation_pb.rb +95 -0
  25. data/lib/google/cloud/vision/v1p4beta1/version.rb +28 -0
  26. data/lib/google/cloud/vision/v1p4beta1/web_detection_pb.rb +52 -0
  27. data/lib/google/cloud/vision/v1p4beta1.rb +39 -0
  28. data/lib/google-cloud-vision-v1p4beta1.rb +21 -0
  29. data/proto_docs/README.md +4 -0
  30. data/proto_docs/google/api/field_behavior.rb +71 -0
  31. data/proto_docs/google/api/resource.rb +283 -0
  32. data/proto_docs/google/cloud/vision/v1p4beta1/face.rb +68 -0
  33. data/proto_docs/google/cloud/vision/v1p4beta1/geometry.rb +82 -0
  34. data/proto_docs/google/cloud/vision/v1p4beta1/image_annotator.rb +989 -0
  35. data/proto_docs/google/cloud/vision/v1p4beta1/product_search.rb +136 -0
  36. data/proto_docs/google/cloud/vision/v1p4beta1/product_search_service.rb +676 -0
  37. data/proto_docs/google/cloud/vision/v1p4beta1/text_annotation.rb +286 -0
  38. data/proto_docs/google/cloud/vision/v1p4beta1/web_detection.rb +121 -0
  39. data/proto_docs/google/longrunning/operations.rb +164 -0
  40. data/proto_docs/google/protobuf/any.rb +141 -0
  41. data/proto_docs/google/protobuf/duration.rb +98 -0
  42. data/proto_docs/google/protobuf/empty.rb +36 -0
  43. data/proto_docs/google/protobuf/field_mask.rb +229 -0
  44. data/proto_docs/google/protobuf/timestamp.rb +129 -0
  45. data/proto_docs/google/protobuf/wrappers.rb +121 -0
  46. data/proto_docs/google/rpc/status.rb +46 -0
  47. data/proto_docs/google/type/color.rb +173 -0
  48. data/proto_docs/google/type/latlng.rb +38 -0
  49. metadata +240 -0
@@ -0,0 +1,1228 @@
1
+ # Copyright 2020 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
+ # rubocop:disable Style/Documentation
16
+
17
+ require "uri"
18
+
19
+ module Google
20
+ module Cloud
21
+ module Vision
22
+ module V1p4beta1
23
+ module ImageAnnotator
24
+ class Client
25
+ ##
26
+ # Detect features of type CROP_HINTS.
27
+ #
28
+ # @param images [Array<String>, Array<File>]
29
+ # An array containing files, file paths, io objects, image urls, or
30
+ # Google Cloud Storage urls. Can be used with or instead of image.
31
+ # @param image [File, String]
32
+ # A file, file path, io object, url pointing to an image, or Google
33
+ # Cloud Storage url. Can be used with or instead of images.
34
+ # @param max_results [Integer]
35
+ # Optional. Defaults to 10.
36
+ # @param options [Gapic::CallOptions]
37
+ # Optional. Overrides the default settings for this call, e.g,
38
+ # timeout, retries, etc.
39
+ # @param async [Boolean]
40
+ # Optional. Defaults to `false`. If `false`, performs the request
41
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
42
+ # performs the request asynchronously, returning a `Gapic::Operation`.
43
+ # @param mime_type [String]
44
+ # Required only if async is `true`.
45
+ # @param batch_size [Integer]
46
+ # Optional. Defaults to 10. When async is `true`, this specifies the
47
+ # number of input files per output json.
48
+ # @param destination [String]
49
+ # A Google Cloud Storage location for storing the output. Required
50
+ # only if async is `true`.
51
+ # @param image_context [Hash]
52
+ # Optional. Image context and/or feature-specific parameters.
53
+ #
54
+ # @yield [result, operation] Access the result along with the RPC operation
55
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
56
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
57
+ #
58
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
59
+ # @return [Gapic::Operation] if async is `true`.
60
+ #
61
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
62
+ #
63
+ # @example
64
+ # require "google/cloud/vision/v1p4beta1"
65
+ #
66
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
67
+ #
68
+ # response = image_annotator_client.crop_hints_detection image: "path/to/image.png"
69
+ # response.responses.each do |res|
70
+ # puts res
71
+ # end
72
+ #
73
+ def crop_hints_detection \
74
+ images: [],
75
+ image: nil,
76
+ max_results: 10,
77
+ options: nil,
78
+ async: false,
79
+ mime_type: nil,
80
+ batch_size: 10,
81
+ destination: nil,
82
+ image_context: nil,
83
+ &block
84
+
85
+ feature = { type: :CROP_HINTS, max_results: max_results }
86
+ images << image if image
87
+ formatted_images = images.map do |img|
88
+ formatted_image = normalize_image img
89
+ formatted_image[:mime_type] = mime_type if mime_type
90
+ formatted_image
91
+ end
92
+ requests = formatted_images.map do |img|
93
+ request = { image: img, features: [feature] }
94
+ request[:image_context] = image_context if image_context
95
+ request
96
+ end
97
+ batch_request = { requests: requests }
98
+
99
+ if async
100
+ requests.map! do |request|
101
+ {
102
+ input_config: {
103
+ gcs_source: {
104
+ uri: request[:image][:source][:gcs_image_uri]
105
+ },
106
+ mime_type: mime_type
107
+ },
108
+ features: request[:features],
109
+ output_config: {
110
+ gcs_destination: {
111
+ uri: destination
112
+ },
113
+ batch_size: batch_size
114
+ }
115
+ }
116
+ end
117
+ async_batch_annotate_files batch_request, options, &block
118
+ else
119
+ batch_annotate_images batch_request, options, &block
120
+ end
121
+ end
122
+
123
+ ##
124
+ # Detect features of type DOCUMENT_TEXT_DETECTION.
125
+ #
126
+ # @param images [Array<String>, Array<File>]
127
+ # An array containing files, file paths, io objects, image urls, or
128
+ # Google Cloud Storage urls. Can be used with or instead of image.
129
+ # @param image [File, String]
130
+ # A file, file path, io object, url pointing to an image, or Google
131
+ # Cloud Storage url. Can be used with or instead of images.
132
+ # @param max_results [Integer]
133
+ # Optional. Defaults to 10.
134
+ # @param options [Gapic::CallOptions]
135
+ # Optional. Overrides the default settings for this call, e.g,
136
+ # timeout, retries, etc.
137
+ # @param async [Boolean]
138
+ # Optional. Defaults to `false`. If `false`, performs the request
139
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
140
+ # performs the request asynchronously, returning a `Gapic::Operation`.
141
+ # @param mime_type [String]
142
+ # Required only if async is `true`.
143
+ # @param batch_size [Integer]
144
+ # Optional. Defaults to 10. When async is `true`, this specifies the
145
+ # number of input files per output json.
146
+ # @param destination [String]
147
+ # A Google Cloud Storage location for storing the output. Required
148
+ # only if async is `true`.
149
+ # @param image_context [Hash]
150
+ # Optional. Image context and/or feature-specific parameters.
151
+ #
152
+ # @yield [result, operation] Access the result along with the RPC operation
153
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
154
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
155
+ #
156
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
157
+ # @return [Gapic::Operation] if async is `true`.
158
+ #
159
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
160
+ #
161
+ # @example
162
+ # require "google/cloud/vision/v1p4beta1"
163
+ #
164
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
165
+ #
166
+ # response = image_annotator_client.document_text_detection image: "path/to/image.png"
167
+ # response.responses.each do |res|
168
+ # puts res
169
+ # end
170
+ #
171
+ def document_text_detection \
172
+ images: [],
173
+ image: nil,
174
+ max_results: 10,
175
+ options: nil,
176
+ async: false,
177
+ mime_type: nil,
178
+ batch_size: 10,
179
+ destination: nil,
180
+ image_context: nil,
181
+ &block
182
+
183
+ feature = { type: :DOCUMENT_TEXT_DETECTION, max_results: max_results }
184
+ images << image if image
185
+ formatted_images = images.map do |img|
186
+ formatted_image = normalize_image img
187
+ formatted_image[:mime_type] = mime_type if mime_type
188
+ formatted_image
189
+ end
190
+ requests = formatted_images.map do |img|
191
+ request = { image: img, features: [feature] }
192
+ request[:image_context] = image_context if image_context
193
+ request
194
+ end
195
+ batch_request = { requests: requests }
196
+
197
+ if async
198
+ requests.map! do |request|
199
+ {
200
+ input_config: {
201
+ gcs_source: {
202
+ uri: request[:image][:source][:gcs_image_uri]
203
+ },
204
+ mime_type: mime_type
205
+ },
206
+ features: request[:features],
207
+ output_config: {
208
+ gcs_destination: {
209
+ uri: destination
210
+ },
211
+ batch_size: batch_size
212
+ }
213
+ }
214
+ end
215
+ async_batch_annotate_files batch_request, options, &block
216
+ else
217
+ batch_annotate_images batch_request, options, &block
218
+ end
219
+ end
220
+
221
+ ##
222
+ # Detect features of type FACE_DETECTION.
223
+ #
224
+ # @param images [Array<String>, Array<File>]
225
+ # An array containing files, file paths, io objects, image urls, or
226
+ # Google Cloud Storage urls. Can be used with or instead of image.
227
+ # @param image [File, String]
228
+ # A file, file path, io object, url pointing to an image, or Google
229
+ # Cloud Storage url. Can be used with or instead of images.
230
+ # @param max_results [Integer]
231
+ # Optional. Defaults to 10.
232
+ # @param options [Gapic::CallOptions]
233
+ # Optional. Overrides the default settings for this call, e.g,
234
+ # timeout, retries, etc.
235
+ # @param async [Boolean]
236
+ # Optional. Defaults to `false`. If `false`, performs the request
237
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
238
+ # performs the request asynchronously, returning a `Gapic::Operation`.
239
+ # @param mime_type [String]
240
+ # Required only if async is `true`.
241
+ # @param batch_size [Integer]
242
+ # Optional. Defaults to 10. When async is `true`, this specifies the
243
+ # number of input files per output json.
244
+ # @param destination [String]
245
+ # A Google Cloud Storage location for storing the output. Required
246
+ # only if async is `true`.
247
+ # @param image_context [Hash]
248
+ # Optional. Image context and/or feature-specific parameters.
249
+ #
250
+ # @yield [result, operation] Access the result along with the RPC operation
251
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
252
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
253
+ #
254
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
255
+ # @return [Gapic::Operation] if async is `true`.
256
+ #
257
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
258
+ #
259
+ # @example
260
+ # require "google/cloud/vision/v1p4beta1"
261
+ #
262
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
263
+ #
264
+ # response = image_annotator_client.face_detection image: "path/to/image.png"
265
+ # response.responses.each do |res|
266
+ # puts res
267
+ # end
268
+ #
269
+ def face_detection \
270
+ images: [],
271
+ image: nil,
272
+ max_results: 10,
273
+ options: nil,
274
+ async: false,
275
+ mime_type: nil,
276
+ batch_size: 10,
277
+ destination: nil,
278
+ image_context: nil,
279
+ &block
280
+
281
+ feature = { type: :FACE_DETECTION, max_results: max_results }
282
+ images << image if image
283
+ formatted_images = images.map do |img|
284
+ formatted_image = normalize_image img
285
+ formatted_image[:mime_type] = mime_type if mime_type
286
+ formatted_image
287
+ end
288
+ requests = formatted_images.map do |img|
289
+ request = { image: img, features: [feature] }
290
+ request[:image_context] = image_context if image_context
291
+ request
292
+ end
293
+ batch_request = { requests: requests }
294
+
295
+ if async
296
+ requests.map! do |request|
297
+ {
298
+ input_config: {
299
+ gcs_source: {
300
+ uri: request[:image][:source][:gcs_image_uri]
301
+ },
302
+ mime_type: mime_type
303
+ },
304
+ features: request[:features],
305
+ output_config: {
306
+ gcs_destination: {
307
+ uri: destination
308
+ },
309
+ batch_size: batch_size
310
+ }
311
+ }
312
+ end
313
+ async_batch_annotate_files batch_request, options, &block
314
+ else
315
+ batch_annotate_images batch_request, options, &block
316
+ end
317
+ end
318
+
319
+ ##
320
+ # Detect features of type IMAGE_PROPERTIES.
321
+ #
322
+ # @param images [Array<String>, Array<File>]
323
+ # An array containing files, file paths, io objects, image urls, or
324
+ # Google Cloud Storage urls. Can be used with or instead of image.
325
+ # @param image [File, String]
326
+ # A file, file path, io object, url pointing to an image, or Google
327
+ # Cloud Storage url. Can be used with or instead of images.
328
+ # @param max_results [Integer]
329
+ # Optional. Defaults to 10.
330
+ # @param options [Gapic::CallOptions]
331
+ # Optional. Overrides the default settings for this call, e.g,
332
+ # timeout, retries, etc.
333
+ # @param async [Boolean]
334
+ # Optional. Defaults to `false`. If `false`, performs the request
335
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
336
+ # performs the request asynchronously, returning a `Gapic::Operation`.
337
+ # @param mime_type [String]
338
+ # Required only if async is `true`.
339
+ # @param batch_size [Integer]
340
+ # Optional. Defaults to 10. When async is `true`, this specifies the
341
+ # number of input files per output json.
342
+ # @param destination [String]
343
+ # A Google Cloud Storage location for storing the output. Required
344
+ # only if async is `true`.
345
+ # @param image_context [Hash]
346
+ # Optional. Image context and/or feature-specific parameters.
347
+ #
348
+ # @yield [result, operation] Access the result along with the RPC operation
349
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
350
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
351
+ #
352
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
353
+ # @return [Gapic::Operation] if async is `true`.
354
+ #
355
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
356
+ #
357
+ # @example
358
+ # require "google/cloud/vision/v1p4beta1"
359
+ #
360
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
361
+ #
362
+ # response = image_annotator_client.image_properties_detection image: "path/to/image.png"
363
+ # response.responses.each do |res|
364
+ # puts res
365
+ # end
366
+ #
367
+ def image_properties_detection \
368
+ images: [],
369
+ image: nil,
370
+ max_results: 10,
371
+ options: nil,
372
+ async: false,
373
+ mime_type: nil,
374
+ batch_size: 10,
375
+ destination: nil,
376
+ image_context: nil,
377
+ &block
378
+
379
+ feature = { type: :IMAGE_PROPERTIES, max_results: max_results }
380
+ images << image if image
381
+ formatted_images = images.map do |img|
382
+ formatted_image = normalize_image img
383
+ formatted_image[:mime_type] = mime_type if mime_type
384
+ formatted_image
385
+ end
386
+ requests = formatted_images.map do |img|
387
+ request = { image: img, features: [feature] }
388
+ request[:image_context] = image_context if image_context
389
+ request
390
+ end
391
+ batch_request = { requests: requests }
392
+
393
+ if async
394
+ requests.map! do |request|
395
+ {
396
+ input_config: {
397
+ gcs_source: {
398
+ uri: request[:image][:source][:gcs_image_uri]
399
+ },
400
+ mime_type: mime_type
401
+ },
402
+ features: request[:features],
403
+ output_config: {
404
+ gcs_destination: {
405
+ uri: destination
406
+ },
407
+ batch_size: batch_size
408
+ }
409
+ }
410
+ end
411
+ async_batch_annotate_files batch_request, options, &block
412
+ else
413
+ batch_annotate_images batch_request, options, &block
414
+ end
415
+ end
416
+
417
+ ##
418
+ # Detect features of type LABEL_DETECTION.
419
+ #
420
+ # @param images [Array<String>, Array<File>]
421
+ # An array containing files, file paths, io objects, image urls, or
422
+ # Google Cloud Storage urls. Can be used with or instead of image.
423
+ # @param image [File, String]
424
+ # A file, file path, io object, url pointing to an image, or Google
425
+ # Cloud Storage url. Can be used with or instead of images.
426
+ # @param max_results [Integer]
427
+ # Optional. Defaults to 10.
428
+ # @param options [Gapic::CallOptions]
429
+ # Optional. Overrides the default settings for this call, e.g,
430
+ # timeout, retries, etc.
431
+ # @param async [Boolean]
432
+ # Optional. Defaults to `false`. If `false`, performs the request
433
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
434
+ # performs the request asynchronously, returning a `Gapic::Operation`.
435
+ # @param mime_type [String]
436
+ # Required only if async is `true`.
437
+ # @param batch_size [Integer]
438
+ # Optional. Defaults to 10. When async is `true`, this specifies the
439
+ # number of input files per output json.
440
+ # @param destination [String]
441
+ # A Google Cloud Storage location for storing the output. Required
442
+ # only if async is `true`.
443
+ # @param image_context [Hash]
444
+ # Optional. Image context and/or feature-specific parameters.
445
+ #
446
+ # @yield [result, operation] Access the result along with the RPC operation
447
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
448
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
449
+ #
450
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
451
+ # @return [Gapic::Operation] if async is `true`.
452
+ #
453
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
454
+ #
455
+ # @example
456
+ # require "google/cloud/vision/v1p4beta1"
457
+ #
458
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
459
+ #
460
+ # response = image_annotator_client.label_detection image: "path/to/image.png"
461
+ # response.responses.each do |res|
462
+ # puts res
463
+ # end
464
+ #
465
+ def label_detection \
466
+ images: [],
467
+ image: nil,
468
+ max_results: 10,
469
+ options: nil,
470
+ async: false,
471
+ mime_type: nil,
472
+ batch_size: 10,
473
+ destination: nil,
474
+ image_context: nil,
475
+ &block
476
+
477
+ feature = { type: :LABEL_DETECTION, max_results: max_results }
478
+ images << image if image
479
+ formatted_images = images.map do |img|
480
+ formatted_image = normalize_image img
481
+ formatted_image[:mime_type] = mime_type if mime_type
482
+ formatted_image
483
+ end
484
+ requests = formatted_images.map do |img|
485
+ request = { image: img, features: [feature] }
486
+ request[:image_context] = image_context if image_context
487
+ request
488
+ end
489
+ batch_request = { requests: requests }
490
+
491
+ if async
492
+ requests.map! do |request|
493
+ {
494
+ input_config: {
495
+ gcs_source: {
496
+ uri: request[:image][:source][:gcs_image_uri]
497
+ },
498
+ mime_type: mime_type
499
+ },
500
+ features: request[:features],
501
+ output_config: {
502
+ gcs_destination: {
503
+ uri: destination
504
+ },
505
+ batch_size: batch_size
506
+ }
507
+ }
508
+ end
509
+ async_batch_annotate_files batch_request, options, &block
510
+ else
511
+ batch_annotate_images batch_request, options, &block
512
+ end
513
+ end
514
+
515
+ ##
516
+ # Detect features of type LANDMARK_DETECTION.
517
+ #
518
+ # @param images [Array<String>, Array<File>]
519
+ # An array containing files, file paths, io objects, image urls, or
520
+ # Google Cloud Storage urls. Can be used with or instead of image.
521
+ # @param image [File, String]
522
+ # A file, file path, io object, url pointing to an image, or Google
523
+ # Cloud Storage url. Can be used with or instead of images.
524
+ # @param max_results [Integer]
525
+ # Optional. Defaults to 10.
526
+ # @param options [Gapic::CallOptions]
527
+ # Optional. Overrides the default settings for this call, e.g,
528
+ # timeout, retries, etc.
529
+ # @param async [Boolean]
530
+ # Optional. Defaults to `false`. If `false`, performs the request
531
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
532
+ # performs the request asynchronously, returning a `Gapic::Operation`.
533
+ # @param mime_type [String]
534
+ # Required only if async is `true`.
535
+ # @param batch_size [Integer]
536
+ # Optional. Defaults to 10. When async is `true`, this specifies the
537
+ # number of input files per output json.
538
+ # @param destination [String]
539
+ # A Google Cloud Storage location for storing the output. Required
540
+ # only if async is `true`.
541
+ # @param image_context [Hash]
542
+ # Optional. Image context and/or feature-specific parameters.
543
+ #
544
+ # @yield [result, operation] Access the result along with the RPC operation
545
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
546
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
547
+ #
548
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
549
+ # @return [Gapic::Operation] if async is `true`.
550
+ #
551
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
552
+ #
553
+ # @example
554
+ # require "google/cloud/vision/v1p4beta1"
555
+ #
556
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
557
+ #
558
+ # response = image_annotator_client.landmark_detection image: "path/to/image.png"
559
+ # response.responses.each do |res|
560
+ # puts res
561
+ # end
562
+ #
563
+ def landmark_detection \
564
+ images: [],
565
+ image: nil,
566
+ max_results: 10,
567
+ options: nil,
568
+ async: false,
569
+ mime_type: nil,
570
+ batch_size: 10,
571
+ destination: nil,
572
+ image_context: nil,
573
+ &block
574
+
575
+ feature = { type: :LANDMARK_DETECTION, max_results: max_results }
576
+ images << image if image
577
+ formatted_images = images.map do |img|
578
+ formatted_image = normalize_image img
579
+ formatted_image[:mime_type] = mime_type if mime_type
580
+ formatted_image
581
+ end
582
+ requests = formatted_images.map do |img|
583
+ request = { image: img, features: [feature] }
584
+ request[:image_context] = image_context if image_context
585
+ request
586
+ end
587
+ batch_request = { requests: requests }
588
+
589
+ if async
590
+ requests.map! do |request|
591
+ {
592
+ input_config: {
593
+ gcs_source: {
594
+ uri: request[:image][:source][:gcs_image_uri]
595
+ },
596
+ mime_type: mime_type
597
+ },
598
+ features: request[:features],
599
+ output_config: {
600
+ gcs_destination: {
601
+ uri: destination
602
+ },
603
+ batch_size: batch_size
604
+ }
605
+ }
606
+ end
607
+ async_batch_annotate_files batch_request, options, &block
608
+ else
609
+ batch_annotate_images batch_request, options, &block
610
+ end
611
+ end
612
+
613
+ ##
614
+ # Detect features of type LOGO_DETECTION.
615
+ #
616
+ # @param images [Array<String>, Array<File>]
617
+ # An array containing files, file paths, io objects, image urls, or
618
+ # Google Cloud Storage urls. Can be used with or instead of image.
619
+ # @param image [File, String]
620
+ # A file, file path, io object, url pointing to an image, or Google
621
+ # Cloud Storage url. Can be used with or instead of images.
622
+ # @param max_results [Integer]
623
+ # Optional. Defaults to 10.
624
+ # @param options [Gapic::CallOptions]
625
+ # Optional. Overrides the default settings for this call, e.g,
626
+ # timeout, retries, etc.
627
+ # @param async [Boolean]
628
+ # Optional. Defaults to `false`. If `false`, performs the request
629
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
630
+ # performs the request asynchronously, returning a `Gapic::Operation`.
631
+ # @param mime_type [String]
632
+ # Required only if async is `true`.
633
+ # @param batch_size [Integer]
634
+ # Optional. Defaults to 10. When async is `true`, this specifies the
635
+ # number of input files per output json.
636
+ # @param destination [String]
637
+ # A Google Cloud Storage location for storing the output. Required
638
+ # only if async is `true`.
639
+ # @param image_context [Hash]
640
+ # Optional. Image context and/or feature-specific parameters.
641
+ #
642
+ # @yield [result, operation] Access the result along with the RPC operation
643
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
644
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
645
+ #
646
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
647
+ # @return [Gapic::Operation] if async is `true`.
648
+ #
649
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
650
+ #
651
+ # @example
652
+ # require "google/cloud/vision/v1p4beta1"
653
+ #
654
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
655
+ #
656
+ # response = image_annotator_client.logo_detection image: "path/to/image.png"
657
+ # response.responses.each do |res|
658
+ # puts res
659
+ # end
660
+ #
661
+ def logo_detection \
662
+ images: [],
663
+ image: nil,
664
+ max_results: 10,
665
+ options: nil,
666
+ async: false,
667
+ mime_type: nil,
668
+ batch_size: 10,
669
+ destination: nil,
670
+ image_context: nil,
671
+ &block
672
+
673
+ feature = { type: :LOGO_DETECTION, max_results: max_results }
674
+ images << image if image
675
+ formatted_images = images.map do |img|
676
+ formatted_image = normalize_image img
677
+ formatted_image[:mime_type] = mime_type if mime_type
678
+ formatted_image
679
+ end
680
+ requests = formatted_images.map do |img|
681
+ request = { image: img, features: [feature] }
682
+ request[:image_context] = image_context if image_context
683
+ request
684
+ end
685
+ batch_request = { requests: requests }
686
+
687
+ if async
688
+ requests.map! do |request|
689
+ {
690
+ input_config: {
691
+ gcs_source: {
692
+ uri: request[:image][:source][:gcs_image_uri]
693
+ },
694
+ mime_type: mime_type
695
+ },
696
+ features: request[:features],
697
+ output_config: {
698
+ gcs_destination: {
699
+ uri: destination
700
+ },
701
+ batch_size: batch_size
702
+ }
703
+ }
704
+ end
705
+ async_batch_annotate_files batch_request, options, &block
706
+ else
707
+ batch_annotate_images batch_request, options, &block
708
+ end
709
+ end
710
+
711
+ ##
712
+ # Detect features of type OBJECT_LOCALIZATION.
713
+ #
714
+ # @param images [Array<String>, Array<File>]
715
+ # An array containing files, file paths, io objects, image urls, or
716
+ # Google Cloud Storage urls. Can be used with or instead of image.
717
+ # @param image [File, String]
718
+ # A file, file path, io object, url pointing to an image, or Google
719
+ # Cloud Storage url. Can be used with or instead of images.
720
+ # @param max_results [Integer]
721
+ # Optional. Defaults to 10.
722
+ # @param options [Gapic::CallOptions]
723
+ # Optional. Overrides the default settings for this call, e.g,
724
+ # timeout, retries, etc.
725
+ # @param async [Boolean]
726
+ # Optional. Defaults to `false`. If `false`, performs the request
727
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
728
+ # performs the request asynchronously, returning a `Gapic::Operation`.
729
+ # @param mime_type [String]
730
+ # Required only if async is `true`.
731
+ # @param batch_size [Integer]
732
+ # Optional. Defaults to 10. When async is `true`, this specifies the
733
+ # number of input files per output json.
734
+ # @param destination [String]
735
+ # A Google Cloud Storage location for storing the output. Required
736
+ # only if async is `true`.
737
+ # @param image_context [Hash]
738
+ # Optional. Image context and/or feature-specific parameters.
739
+ #
740
+ # @yield [result, operation] Access the result along with the RPC operation
741
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
742
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
743
+ #
744
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
745
+ # @return [Gapic::Operation] if async is `true`.
746
+ #
747
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
748
+ #
749
+ # @example
750
+ # require "google/cloud/vision/v1p4beta1"
751
+ #
752
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
753
+ #
754
+ # response = image_annotator_client.object_localization_detection image: "path/to/image.png"
755
+ # response.responses.each do |res|
756
+ # puts res
757
+ # end
758
+ #
759
+ def object_localization_detection \
760
+ images: [],
761
+ image: nil,
762
+ max_results: 10,
763
+ options: nil,
764
+ async: false,
765
+ mime_type: nil,
766
+ batch_size: 10,
767
+ destination: nil,
768
+ image_context: nil,
769
+ &block
770
+
771
+ feature = { type: :OBJECT_LOCALIZATION, max_results: max_results }
772
+ images << image if image
773
+ formatted_images = images.map do |img|
774
+ formatted_image = normalize_image img
775
+ formatted_image[:mime_type] = mime_type if mime_type
776
+ formatted_image
777
+ end
778
+ requests = formatted_images.map do |img|
779
+ request = { image: img, features: [feature] }
780
+ request[:image_context] = image_context if image_context
781
+ request
782
+ end
783
+ batch_request = { requests: requests }
784
+
785
+ if async
786
+ requests.map! do |request|
787
+ {
788
+ input_config: {
789
+ gcs_source: {
790
+ uri: request[:image][:source][:gcs_image_uri]
791
+ },
792
+ mime_type: mime_type
793
+ },
794
+ features: request[:features],
795
+ output_config: {
796
+ gcs_destination: {
797
+ uri: destination
798
+ },
799
+ batch_size: batch_size
800
+ }
801
+ }
802
+ end
803
+ async_batch_annotate_files batch_request, options, &block
804
+ else
805
+ batch_annotate_images batch_request, options, &block
806
+ end
807
+ end
808
+
809
+ ##
810
+ # Detect features of type PRODUCT_SEARCH.
811
+ #
812
+ # @param images [Array<String>, Array<File>]
813
+ # An array containing files, file paths, io objects, image urls, or
814
+ # Google Cloud Storage urls. Can be used with or instead of image.
815
+ # @param image [File, String]
816
+ # A file, file path, io object, url pointing to an image, or Google
817
+ # Cloud Storage url. Can be used with or instead of images.
818
+ # @param max_results [Integer]
819
+ # Optional. Defaults to 10.
820
+ # @param options [Gapic::CallOptions]
821
+ # Optional. Overrides the default settings for this call, e.g,
822
+ # timeout, retries, etc.
823
+ # @param async [Boolean]
824
+ # Optional. Defaults to `false`. If `false`, performs the request
825
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
826
+ # performs the request asynchronously, returning a `Gapic::Operation`.
827
+ # @param mime_type [String]
828
+ # Required only if async is `true`.
829
+ # @param batch_size [Integer]
830
+ # Optional. Defaults to 10. When async is `true`, this specifies the
831
+ # number of input files per output json.
832
+ # @param destination [String]
833
+ # A Google Cloud Storage location for storing the output. Required
834
+ # only if async is `true`.
835
+ # @param image_context [Hash]
836
+ # Optional. Image context and/or feature-specific parameters.
837
+ #
838
+ # @yield [result, operation] Access the result along with the RPC operation
839
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
840
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
841
+ #
842
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
843
+ # @return [Gapic::Operation] if async is `true`.
844
+ #
845
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
846
+ #
847
+ # @example
848
+ # require "google/cloud/vision/v1p4beta1"
849
+ #
850
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
851
+ #
852
+ # response = image_annotator_client.product_search_detection image: "path/to/image.png"
853
+ # response.responses.each do |res|
854
+ # puts res
855
+ # end
856
+ #
857
+ def product_search_detection \
858
+ images: [],
859
+ image: nil,
860
+ max_results: 10,
861
+ options: nil,
862
+ async: false,
863
+ mime_type: nil,
864
+ batch_size: 10,
865
+ destination: nil,
866
+ image_context: nil,
867
+ &block
868
+
869
+ feature = { type: :PRODUCT_SEARCH, max_results: max_results }
870
+ images << image if image
871
+ formatted_images = images.map do |img|
872
+ formatted_image = normalize_image img
873
+ formatted_image[:mime_type] = mime_type if mime_type
874
+ formatted_image
875
+ end
876
+ requests = formatted_images.map do |img|
877
+ request = { image: img, features: [feature] }
878
+ request[:image_context] = image_context if image_context
879
+ request
880
+ end
881
+ batch_request = { requests: requests }
882
+
883
+ if async
884
+ requests.map! do |request|
885
+ {
886
+ input_config: {
887
+ gcs_source: {
888
+ uri: request[:image][:source][:gcs_image_uri]
889
+ },
890
+ mime_type: mime_type
891
+ },
892
+ features: request[:features],
893
+ output_config: {
894
+ gcs_destination: {
895
+ uri: destination
896
+ },
897
+ batch_size: batch_size
898
+ }
899
+ }
900
+ end
901
+ async_batch_annotate_files batch_request, options, &block
902
+ else
903
+ batch_annotate_images batch_request, options, &block
904
+ end
905
+ end
906
+
907
+ ##
908
+ # Detect features of type SAFE_SEARCH_DETECTION.
909
+ #
910
+ # @param images [Array<String>, Array<File>]
911
+ # An array containing files, file paths, io objects, image urls, or
912
+ # Google Cloud Storage urls. Can be used with or instead of image.
913
+ # @param image [File, String]
914
+ # A file, file path, io object, url pointing to an image, or Google
915
+ # Cloud Storage url. Can be used with or instead of images.
916
+ # @param max_results [Integer]
917
+ # Optional. Defaults to 10.
918
+ # @param options [Gapic::CallOptions]
919
+ # Optional. Overrides the default settings for this call, e.g,
920
+ # timeout, retries, etc.
921
+ # @param async [Boolean]
922
+ # Optional. Defaults to `false`. If `false`, performs the request
923
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
924
+ # performs the request asynchronously, returning a `Gapic::Operation`.
925
+ # @param mime_type [String]
926
+ # Required only if async is `true`.
927
+ # @param batch_size [Integer]
928
+ # Optional. Defaults to 10. When async is `true`, this specifies the
929
+ # number of input files per output json.
930
+ # @param destination [String]
931
+ # A Google Cloud Storage location for storing the output. Required
932
+ # only if async is `true`.
933
+ # @param image_context [Hash]
934
+ # Optional. Image context and/or feature-specific parameters.
935
+ #
936
+ # @yield [result, operation] Access the result along with the RPC operation
937
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
938
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
939
+ #
940
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
941
+ # @return [Gapic::Operation] if async is `true`.
942
+ #
943
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
944
+ #
945
+ # @example
946
+ # require "google/cloud/vision/v1p4beta1"
947
+ #
948
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
949
+ #
950
+ # response = image_annotator_client.safe_search_detection image: "path/to/image.png"
951
+ # response.responses.each do |res|
952
+ # puts res
953
+ # end
954
+ #
955
+ def safe_search_detection \
956
+ images: [],
957
+ image: nil,
958
+ max_results: 10,
959
+ options: nil,
960
+ async: false,
961
+ mime_type: nil,
962
+ batch_size: 10,
963
+ destination: nil,
964
+ image_context: nil,
965
+ &block
966
+
967
+ feature = { type: :SAFE_SEARCH_DETECTION, max_results: max_results }
968
+ images << image if image
969
+ formatted_images = images.map do |img|
970
+ formatted_image = normalize_image img
971
+ formatted_image[:mime_type] = mime_type if mime_type
972
+ formatted_image
973
+ end
974
+ requests = formatted_images.map do |img|
975
+ request = { image: img, features: [feature] }
976
+ request[:image_context] = image_context if image_context
977
+ request
978
+ end
979
+ batch_request = { requests: requests }
980
+
981
+ if async
982
+ requests.map! do |request|
983
+ {
984
+ input_config: {
985
+ gcs_source: {
986
+ uri: request[:image][:source][:gcs_image_uri]
987
+ },
988
+ mime_type: mime_type
989
+ },
990
+ features: request[:features],
991
+ output_config: {
992
+ gcs_destination: {
993
+ uri: destination
994
+ },
995
+ batch_size: batch_size
996
+ }
997
+ }
998
+ end
999
+ async_batch_annotate_files batch_request, options, &block
1000
+ else
1001
+ batch_annotate_images batch_request, options, &block
1002
+ end
1003
+ end
1004
+
1005
+ ##
1006
+ # Detect features of type TEXT_DETECTION.
1007
+ #
1008
+ # @param images [Array<String>, Array<File>]
1009
+ # An array containing files, file paths, io objects, image urls, or
1010
+ # Google Cloud Storage urls. Can be used with or instead of image.
1011
+ # @param image [File, String]
1012
+ # A file, file path, io object, url pointing to an image, or Google
1013
+ # Cloud Storage url. Can be used with or instead of images.
1014
+ # @param max_results [Integer]
1015
+ # Optional. Defaults to 10.
1016
+ # @param options [Gapic::CallOptions]
1017
+ # Optional. Overrides the default settings for this call, e.g,
1018
+ # timeout, retries, etc.
1019
+ # @param async [Boolean]
1020
+ # Optional. Defaults to `false`. If `false`, performs the request
1021
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
1022
+ # performs the request asynchronously, returning a `Gapic::Operation`.
1023
+ # @param mime_type [String]
1024
+ # Required only if async is `true`.
1025
+ # @param batch_size [Integer]
1026
+ # Optional. Defaults to 10. When async is `true`, this specifies the
1027
+ # number of input files per output json.
1028
+ # @param destination [String]
1029
+ # A Google Cloud Storage location for storing the output. Required
1030
+ # only if async is `true`.
1031
+ # @param image_context [Hash]
1032
+ # Optional. Image context and/or feature-specific parameters.
1033
+ #
1034
+ # @yield [result, operation] Access the result along with the RPC operation
1035
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
1036
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1037
+ #
1038
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
1039
+ # @return [Gapic::Operation] if async is `true`.
1040
+ #
1041
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
1042
+ #
1043
+ # @example
1044
+ # require "google/cloud/vision/v1p4beta1"
1045
+ #
1046
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
1047
+ #
1048
+ # response = image_annotator_client.text_detection image: "path/to/image.png"
1049
+ # response.responses.each do |res|
1050
+ # puts res
1051
+ # end
1052
+ #
1053
+ def text_detection \
1054
+ images: [],
1055
+ image: nil,
1056
+ max_results: 10,
1057
+ options: nil,
1058
+ async: false,
1059
+ mime_type: nil,
1060
+ batch_size: 10,
1061
+ destination: nil,
1062
+ image_context: nil,
1063
+ &block
1064
+
1065
+ feature = { type: :TEXT_DETECTION, max_results: max_results }
1066
+ images << image if image
1067
+ formatted_images = images.map do |img|
1068
+ formatted_image = normalize_image img
1069
+ formatted_image[:mime_type] = mime_type if mime_type
1070
+ formatted_image
1071
+ end
1072
+ requests = formatted_images.map do |img|
1073
+ request = { image: img, features: [feature] }
1074
+ request[:image_context] = image_context if image_context
1075
+ request
1076
+ end
1077
+ batch_request = { requests: requests }
1078
+
1079
+ if async
1080
+ requests.map! do |request|
1081
+ {
1082
+ input_config: {
1083
+ gcs_source: {
1084
+ uri: request[:image][:source][:gcs_image_uri]
1085
+ },
1086
+ mime_type: mime_type
1087
+ },
1088
+ features: request[:features],
1089
+ output_config: {
1090
+ gcs_destination: {
1091
+ uri: destination
1092
+ },
1093
+ batch_size: batch_size
1094
+ }
1095
+ }
1096
+ end
1097
+ async_batch_annotate_files batch_request, options, &block
1098
+ else
1099
+ batch_annotate_images batch_request, options, &block
1100
+ end
1101
+ end
1102
+
1103
+ ##
1104
+ # Detect features of type WEB_DETECTION.
1105
+ #
1106
+ # @param images [Array<String>, Array<File>]
1107
+ # An array containing files, file paths, io objects, image urls, or
1108
+ # Google Cloud Storage urls. Can be used with or instead of image.
1109
+ # @param image [File, String]
1110
+ # A file, file path, io object, url pointing to an image, or Google
1111
+ # Cloud Storage url. Can be used with or instead of images.
1112
+ # @param max_results [Integer]
1113
+ # Optional. Defaults to 10.
1114
+ # @param options [Gapic::CallOptions]
1115
+ # Optional. Overrides the default settings for this call, e.g,
1116
+ # timeout, retries, etc.
1117
+ # @param async [Boolean]
1118
+ # Optional. Defaults to `false`. If `false`, performs the request
1119
+ # synchronously, returning a `BatchAnnotateImagesResponse`. If `true`,
1120
+ # performs the request asynchronously, returning a `Gapic::Operation`.
1121
+ # @param mime_type [String]
1122
+ # Required only if async is `true`.
1123
+ # @param batch_size [Integer]
1124
+ # Optional. Defaults to 10. When async is `true`, this specifies the
1125
+ # number of input files per output json.
1126
+ # @param destination [String]
1127
+ # A Google Cloud Storage location for storing the output. Required
1128
+ # only if async is `true`.
1129
+ # @param image_context [Hash]
1130
+ # Optional. Image context and/or feature-specific parameters.
1131
+ #
1132
+ # @yield [result, operation] Access the result along with the RPC operation
1133
+ # @yieldparam result [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse, Gapic::Operation]
1134
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1135
+ #
1136
+ # @return [Google::Cloud::Vision::V1p4beta1::BatchAnnotateImagesResponse] if async is `false`.
1137
+ # @return [Gapic::Operation] if async is `true`.
1138
+ #
1139
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
1140
+ #
1141
+ # @example
1142
+ # require "google/cloud/vision/v1p4beta1"
1143
+ #
1144
+ # image_annotator_client = Google::Cloud::Vision::V1p4beta1::ImageAnnotator::Client.new
1145
+ #
1146
+ # response = image_annotator_client.web_detection image: "path/to/image.png"
1147
+ # response.responses.each do |res|
1148
+ # puts res
1149
+ # end
1150
+ #
1151
+ def web_detection \
1152
+ images: [],
1153
+ image: nil,
1154
+ max_results: 10,
1155
+ options: nil,
1156
+ async: false,
1157
+ mime_type: nil,
1158
+ batch_size: 10,
1159
+ destination: nil,
1160
+ image_context: nil,
1161
+ &block
1162
+
1163
+ feature = { type: :WEB_DETECTION, max_results: max_results }
1164
+ images << image if image
1165
+ formatted_images = images.map do |img|
1166
+ formatted_image = normalize_image img
1167
+ formatted_image[:mime_type] = mime_type if mime_type
1168
+ formatted_image
1169
+ end
1170
+ requests = formatted_images.map do |img|
1171
+ request = { image: img, features: [feature] }
1172
+ request[:image_context] = image_context if image_context
1173
+ request
1174
+ end
1175
+ batch_request = { requests: requests }
1176
+
1177
+ if async
1178
+ requests.map! do |request|
1179
+ {
1180
+ input_config: {
1181
+ gcs_source: {
1182
+ uri: request[:image][:source][:gcs_image_uri]
1183
+ },
1184
+ mime_type: mime_type
1185
+ },
1186
+ features: request[:features],
1187
+ output_config: {
1188
+ gcs_destination: {
1189
+ uri: destination
1190
+ },
1191
+ batch_size: batch_size
1192
+ }
1193
+ }
1194
+ end
1195
+ async_batch_annotate_files batch_request, options, &block
1196
+ else
1197
+ batch_annotate_images batch_request, options, &block
1198
+ end
1199
+ end
1200
+
1201
+ private
1202
+
1203
+ def normalize_image image
1204
+ formatted_image =
1205
+ if image.respond_to? :binmode
1206
+ { content: image.binmode.read }
1207
+ elsif image.is_a? String
1208
+ if File.file? image
1209
+ { content: File.binread(image) }
1210
+ elsif image =~ URI::DEFAULT_PARSER.make_regexp
1211
+ if URI(image).scheme == "gs"
1212
+ { source: { gcs_image_uri: image } }
1213
+ else
1214
+ { source: { image_uri: image } }
1215
+ end
1216
+ end
1217
+ end
1218
+ raise TypeError, "Image must be a filepath, url, or IO object" unless formatted_image
1219
+ formatted_image
1220
+ end
1221
+ end
1222
+ end
1223
+ end
1224
+ end
1225
+ end
1226
+ end
1227
+
1228
+ # rubocop:enable Style/Documentation