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
@@ -128,7 +128,7 @@ module Google
128
128
  # | |
129
129
  # 1----0
130
130
  #
131
- # and the vertice order will still be (0, 1, 2, 3).
131
+ # and the vertex order will still be (0, 1, 2, 3).
132
132
  # @!attribute [rw] paragraphs
133
133
  # @return [Array<Google::Cloud::Vision::V1::Paragraph>]
134
134
  # List of paragraphs in this block (if this blocks is of type text).
@@ -181,7 +181,7 @@ module Google
181
181
  # 2----3
182
182
  # | |
183
183
  # 1----0
184
- # and the vertice order will still be (0, 1, 2, 3).
184
+ # and the vertex order will still be (0, 1, 2, 3).
185
185
  # @!attribute [rw] words
186
186
  # @return [Array<Google::Cloud::Vision::V1::Word>]
187
187
  # List of words in this paragraph.
@@ -210,7 +210,7 @@ module Google
210
210
  # 2----3
211
211
  # | |
212
212
  # 1----0
213
- # and the vertice order will still be (0, 1, 2, 3).
213
+ # and the vertex order will still be (0, 1, 2, 3).
214
214
  # @!attribute [rw] symbols
215
215
  # @return [Array<Google::Cloud::Vision::V1::Symbol>]
216
216
  # List of symbols in the word.
@@ -38,7 +38,8 @@ module Google
38
38
  # The visually similar image results.
39
39
  # @!attribute [rw] best_guess_labels
40
40
  # @return [Array<Google::Cloud::Vision::V1::WebDetection::WebLabel>]
41
- # Best guess text labels for the request image.
41
+ # The service's best guess as to the topic of the request image.
42
+ # Inferred from similar images on the open web.
42
43
  class WebDetection
43
44
  # Entity deduced from similar images on the Internet.
44
45
  # @!attribute [rw] entity_id
@@ -1,4 +1,4 @@
1
- # Copyright 2016 Google LLC
1
+ # Copyright 2018 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,9 +14,16 @@
14
14
 
15
15
 
16
16
  module Google
17
- module Cloud
18
- module Vision
19
- VERSION = "0.31.0".freeze
20
- end
17
+ module Protobuf
18
+ # A generic empty message that you can re-use to avoid defining duplicated
19
+ # empty messages in your APIs. A typical example is to use it as the request
20
+ # or the response type of an API method. For instance:
21
+ #
22
+ # service Foo {
23
+ # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
24
+ # }
25
+ #
26
+ # The JSON representation for `Empty` is empty JSON object `{}`.
27
+ class Empty; end
21
28
  end
22
- end
29
+ end
@@ -0,0 +1,230 @@
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
+ module Google
17
+ module Protobuf
18
+ # `FieldMask` represents a set of symbolic field paths, for example:
19
+ #
20
+ # paths: "f.a"
21
+ # paths: "f.b.d"
22
+ #
23
+ # Here `f` represents a field in some root message, `a` and `b`
24
+ # fields in the message found in `f`, and `d` a field found in the
25
+ # message in `f.b`.
26
+ #
27
+ # Field masks are used to specify a subset of fields that should be
28
+ # returned by a get operation or modified by an update operation.
29
+ # Field masks also have a custom JSON encoding (see below).
30
+ #
31
+ # = Field Masks in Projections
32
+ #
33
+ # When used in the context of a projection, a response message or
34
+ # sub-message is filtered by the API to only contain those fields as
35
+ # specified in the mask. For example, if the mask in the previous
36
+ # example is applied to a response message as follows:
37
+ #
38
+ # f {
39
+ # a : 22
40
+ # b {
41
+ # d : 1
42
+ # x : 2
43
+ # }
44
+ # y : 13
45
+ # }
46
+ # z: 8
47
+ #
48
+ # The result will not contain specific values for fields x,y and z
49
+ # (their value will be set to the default, and omitted in proto text
50
+ # output):
51
+ #
52
+ #
53
+ # f {
54
+ # a : 22
55
+ # b {
56
+ # d : 1
57
+ # }
58
+ # }
59
+ #
60
+ # A repeated field is not allowed except at the last position of a
61
+ # paths string.
62
+ #
63
+ # If a FieldMask object is not present in a get operation, the
64
+ # operation applies to all fields (as if a FieldMask of all fields
65
+ # had been specified).
66
+ #
67
+ # Note that a field mask does not necessarily apply to the
68
+ # top-level response message. In case of a REST get operation, the
69
+ # field mask applies directly to the response, but in case of a REST
70
+ # list operation, the mask instead applies to each individual message
71
+ # in the returned resource list. In case of a REST custom method,
72
+ # other definitions may be used. Where the mask applies will be
73
+ # clearly documented together with its declaration in the API. In
74
+ # any case, the effect on the returned resource/resources is required
75
+ # behavior for APIs.
76
+ #
77
+ # = Field Masks in Update Operations
78
+ #
79
+ # A field mask in update operations specifies which fields of the
80
+ # targeted resource are going to be updated. The API is required
81
+ # to only change the values of the fields as specified in the mask
82
+ # and leave the others untouched. If a resource is passed in to
83
+ # describe the updated values, the API ignores the values of all
84
+ # fields not covered by the mask.
85
+ #
86
+ # If a repeated field is specified for an update operation, the existing
87
+ # repeated values in the target resource will be overwritten by the new values.
88
+ # Note that a repeated field is only allowed in the last position of a `paths`
89
+ # string.
90
+ #
91
+ # If a sub-message is specified in the last position of the field mask for an
92
+ # update operation, then the existing sub-message in the target resource is
93
+ # overwritten. Given the target message:
94
+ #
95
+ # f {
96
+ # b {
97
+ # d : 1
98
+ # x : 2
99
+ # }
100
+ # c : 1
101
+ # }
102
+ #
103
+ # And an update message:
104
+ #
105
+ # f {
106
+ # b {
107
+ # d : 10
108
+ # }
109
+ # }
110
+ #
111
+ # then if the field mask is:
112
+ #
113
+ # paths: "f.b"
114
+ #
115
+ # then the result will be:
116
+ #
117
+ # f {
118
+ # b {
119
+ # d : 10
120
+ # }
121
+ # c : 1
122
+ # }
123
+ #
124
+ # However, if the update mask was:
125
+ #
126
+ # paths: "f.b.d"
127
+ #
128
+ # then the result would be:
129
+ #
130
+ # f {
131
+ # b {
132
+ # d : 10
133
+ # x : 2
134
+ # }
135
+ # c : 1
136
+ # }
137
+ #
138
+ # In order to reset a field's value to the default, the field must
139
+ # be in the mask and set to the default value in the provided resource.
140
+ # Hence, in order to reset all fields of a resource, provide a default
141
+ # instance of the resource and set all fields in the mask, or do
142
+ # not provide a mask as described below.
143
+ #
144
+ # If a field mask is not present on update, the operation applies to
145
+ # all fields (as if a field mask of all fields has been specified).
146
+ # Note that in the presence of schema evolution, this may mean that
147
+ # fields the client does not know and has therefore not filled into
148
+ # the request will be reset to their default. If this is unwanted
149
+ # behavior, a specific service may require a client to always specify
150
+ # a field mask, producing an error if not.
151
+ #
152
+ # As with get operations, the location of the resource which
153
+ # describes the updated values in the request message depends on the
154
+ # operation kind. In any case, the effect of the field mask is
155
+ # required to be honored by the API.
156
+ #
157
+ # == Considerations for HTTP REST
158
+ #
159
+ # The HTTP kind of an update operation which uses a field mask must
160
+ # be set to PATCH instead of PUT in order to satisfy HTTP semantics
161
+ # (PUT must only be used for full updates).
162
+ #
163
+ # = JSON Encoding of Field Masks
164
+ #
165
+ # In JSON, a field mask is encoded as a single string where paths are
166
+ # separated by a comma. Fields name in each path are converted
167
+ # to/from lower-camel naming conventions.
168
+ #
169
+ # As an example, consider the following message declarations:
170
+ #
171
+ # message Profile {
172
+ # User user = 1;
173
+ # Photo photo = 2;
174
+ # }
175
+ # message User {
176
+ # string display_name = 1;
177
+ # string address = 2;
178
+ # }
179
+ #
180
+ # In proto a field mask for `Profile` may look as such:
181
+ #
182
+ # mask {
183
+ # paths: "user.display_name"
184
+ # paths: "photo"
185
+ # }
186
+ #
187
+ # In JSON, the same mask is represented as below:
188
+ #
189
+ # {
190
+ # mask: "user.displayName,photo"
191
+ # }
192
+ #
193
+ # = Field Masks and Oneof Fields
194
+ #
195
+ # Field masks treat fields in oneofs just as regular fields. Consider the
196
+ # following message:
197
+ #
198
+ # message SampleMessage {
199
+ # oneof test_oneof {
200
+ # string name = 4;
201
+ # SubMessage sub_message = 9;
202
+ # }
203
+ # }
204
+ #
205
+ # The field mask can be:
206
+ #
207
+ # mask {
208
+ # paths: "name"
209
+ # }
210
+ #
211
+ # Or:
212
+ #
213
+ # mask {
214
+ # paths: "sub_message"
215
+ # }
216
+ #
217
+ # Note that oneof type names ("test_oneof" in this case) cannot be used in
218
+ # paths.
219
+ #
220
+ # == Field Mask Verification
221
+ #
222
+ # The implementation of any API method which has a FieldMask type field in the
223
+ # request should verify the included field paths, and return an
224
+ # `INVALID_ARGUMENT` error if any path is duplicated or unmappable.
225
+ # @!attribute [rw] paths
226
+ # @return [Array<String>]
227
+ # The set of field mask paths.
228
+ class FieldMask; end
229
+ end
230
+ end
@@ -0,0 +1,109 @@
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
+ module Google
17
+ module Protobuf
18
+ # A Timestamp represents a point in time independent of any time zone
19
+ # or calendar, represented as seconds and fractions of seconds at
20
+ # nanosecond resolution in UTC Epoch time. It is encoded using the
21
+ # Proleptic Gregorian Calendar which extends the Gregorian calendar
22
+ # backwards to year one. It is encoded assuming all minutes are 60
23
+ # seconds long, i.e. leap seconds are "smeared" so that no leap second
24
+ # table is needed for interpretation. Range is from
25
+ # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
26
+ # By restricting to that range, we ensure that we can convert to
27
+ # and from RFC 3339 date strings.
28
+ # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
29
+ #
30
+ # = Examples
31
+ #
32
+ # Example 1: Compute Timestamp from POSIX `time()`.
33
+ #
34
+ # Timestamp timestamp;
35
+ # timestamp.set_seconds(time(NULL));
36
+ # timestamp.set_nanos(0);
37
+ #
38
+ # Example 2: Compute Timestamp from POSIX `gettimeofday()`.
39
+ #
40
+ # struct timeval tv;
41
+ # gettimeofday(&tv, NULL);
42
+ #
43
+ # Timestamp timestamp;
44
+ # timestamp.set_seconds(tv.tv_sec);
45
+ # timestamp.set_nanos(tv.tv_usec * 1000);
46
+ #
47
+ # Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
48
+ #
49
+ # FILETIME ft;
50
+ # GetSystemTimeAsFileTime(&ft);
51
+ # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
52
+ #
53
+ # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
54
+ # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
55
+ # Timestamp timestamp;
56
+ # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
57
+ # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
58
+ #
59
+ # Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
60
+ #
61
+ # long millis = System.currentTimeMillis();
62
+ #
63
+ # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
64
+ # .setNanos((int) ((millis % 1000) * 1000000)).build();
65
+ #
66
+ #
67
+ # Example 5: Compute Timestamp from current time in Python.
68
+ #
69
+ # timestamp = Timestamp()
70
+ # timestamp.GetCurrentTime()
71
+ #
72
+ # = JSON Mapping
73
+ #
74
+ # In JSON format, the Timestamp type is encoded as a string in the
75
+ # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
76
+ # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
77
+ # where {year} is always expressed using four digits while {month}, {day},
78
+ # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
79
+ # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
80
+ # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
81
+ # is required. A proto3 JSON serializer should always use UTC (as indicated by
82
+ # "Z") when printing the Timestamp type and a proto3 JSON parser should be
83
+ # able to accept both UTC and other timezones (as indicated by an offset).
84
+ #
85
+ # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
86
+ # 01:30 UTC on January 15, 2017.
87
+ #
88
+ # In JavaScript, one can convert a Date object to this format using the
89
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
90
+ # method. In Python, a standard `datetime.datetime` object can be converted
91
+ # to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
92
+ # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
93
+ # can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
94
+ # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
95
+ # ) to obtain a formatter capable of generating timestamps in this format.
96
+ # @!attribute [rw] seconds
97
+ # @return [Integer]
98
+ # Represents seconds of UTC time since Unix epoch
99
+ # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
100
+ # 9999-12-31T23:59:59Z inclusive.
101
+ # @!attribute [rw] nanos
102
+ # @return [Integer]
103
+ # Non-negative fractions of a second at nanosecond resolution. Negative
104
+ # second values with fractions must still have non-negative nanos values
105
+ # that count forward in time. Must be from 0 to 999,999,999
106
+ # inclusive.
107
+ class Timestamp; end
108
+ end
109
+ end
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'google/protobuf'
6
6
 
7
+ require 'google/api/annotations_pb'
7
8
  Google::Protobuf::DescriptorPool.generated_pool.build do
8
9
  add_message "google.cloud.vision.v1.Vertex" do
9
10
  optional :x, :int32, 1
@@ -0,0 +1,972 @@
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 "uri"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Vision
21
+ module V1
22
+ class ImageAnnotatorClient
23
+
24
+ # @param images [Array<String>, Array<File>]
25
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
26
+ # @param image [File, String]
27
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
28
+ # @param max_results [Integer]
29
+ # Optional. Defaults to 10.
30
+ # @param options [Google::Gax::CallOptions]
31
+ # Optional. Overrides the default settings for this call, e.g, timeout,
32
+ # retries, etc.
33
+ # @param async [Boolean]
34
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
35
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
36
+ # @param mime_type [String]
37
+ # Required only if async is true.
38
+ # @param batch_size [Integer]
39
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
40
+ # @param destination [String]
41
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
42
+ # @yield [result, operation] Access the result along with the RPC operation
43
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
44
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
45
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
46
+ # @example
47
+ # require "google/cloud/vision"
48
+ #
49
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
50
+ #
51
+ # response = image_annotator_client.face_detection image: "path\to\image.png"
52
+ # response.responses.each do |res|
53
+ # puts res
54
+ # end
55
+
56
+ def face_detection \
57
+ images: [],
58
+ image: nil,
59
+ max_results: 10,
60
+ options: nil,
61
+ async: false,
62
+ mime_type: nil,
63
+ batch_size: 10,
64
+ destination: nil,
65
+ &blk
66
+
67
+ feature = { type: :FACE_DETECTION }
68
+ feature[:max_results] = max_results
69
+ images << image if image
70
+
71
+ formatted_images = images.map do |img|
72
+ formatted_image = normalize_image img
73
+ formatted_image[:mime_type] = mime_type if mime_type
74
+ formatted_image
75
+ end
76
+
77
+ requests = formatted_images.map do |img|
78
+ {
79
+ image: img,
80
+ features: [feature]
81
+ }
82
+ end
83
+
84
+ if async
85
+ requests.map! do |request|
86
+ {
87
+ input_config: request[:image],
88
+ features: request[:features],
89
+ output_config: {
90
+ gcs_destination: destination,
91
+ batch_size: batch_size
92
+ }
93
+ }
94
+ end
95
+ async_batch_annotate_files requests, options
96
+ else
97
+ batch_annotate_images requests, options, &blk
98
+ end
99
+ end
100
+
101
+ # @param images [Array<String>, Array<File>]
102
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
103
+ # @param image [File, String]
104
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
105
+ # @param max_results [Integer]
106
+ # Optional. Defaults to 10.
107
+ # @param options [Google::Gax::CallOptions]
108
+ # Optional. Overrides the default settings for this call, e.g, timeout,
109
+ # retries, etc.
110
+ # @param async [Boolean]
111
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
112
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
113
+ # @param mime_type [String]
114
+ # Required only if async is true.
115
+ # @param batch_size [Integer]
116
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
117
+ # @param destination [String]
118
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
119
+ # @yield [result, operation] Access the result along with the RPC operation
120
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
121
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
122
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
123
+ # @example
124
+ # require "google/cloud/vision"
125
+ #
126
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
127
+ #
128
+ # response = image_annotator_client.landmark_detection image: "path\to\image.png"
129
+ # response.responses.each do |res|
130
+ # puts res
131
+ # end
132
+
133
+ def landmark_detection \
134
+ images: [],
135
+ image: nil,
136
+ max_results: 10,
137
+ options: nil,
138
+ async: false,
139
+ mime_type: nil,
140
+ batch_size: 10,
141
+ destination: nil,
142
+ &blk
143
+
144
+ feature = { type: :LANDMARK_DETECTION }
145
+ feature[:max_results] = max_results
146
+ images << image if image
147
+
148
+ formatted_images = images.map do |img|
149
+ formatted_image = normalize_image img
150
+ formatted_image[:mime_type] = mime_type if mime_type
151
+ formatted_image
152
+ end
153
+
154
+ requests = formatted_images.map do |img|
155
+ {
156
+ image: img,
157
+ features: [feature]
158
+ }
159
+ end
160
+
161
+ if async
162
+ requests.map! do |request|
163
+ {
164
+ input_config: request[:image],
165
+ features: request[:features],
166
+ output_config: {
167
+ gcs_destination: destination,
168
+ batch_size: batch_size
169
+ }
170
+ }
171
+ end
172
+ async_batch_annotate_files requests, options
173
+ else
174
+ batch_annotate_images requests, options, &blk
175
+ end
176
+ end
177
+
178
+ # @param images [Array<String>, Array<File>]
179
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
180
+ # @param image [File, String]
181
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
182
+ # @param max_results [Integer]
183
+ # Optional. Defaults to 10.
184
+ # @param options [Google::Gax::CallOptions]
185
+ # Optional. Overrides the default settings for this call, e.g, timeout,
186
+ # retries, etc.
187
+ # @param async [Boolean]
188
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
189
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
190
+ # @param mime_type [String]
191
+ # Required only if async is true.
192
+ # @param batch_size [Integer]
193
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
194
+ # @param destination [String]
195
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
196
+ # @yield [result, operation] Access the result along with the RPC operation
197
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
198
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
199
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
200
+ # @example
201
+ # require "google/cloud/vision"
202
+ #
203
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
204
+ #
205
+ # response = image_annotator_client.logo_detection image: "path\to\image.png"
206
+ # response.responses.each do |res|
207
+ # puts res
208
+ # end
209
+
210
+ def logo_detection \
211
+ images: [],
212
+ image: nil,
213
+ max_results: 10,
214
+ options: nil,
215
+ async: false,
216
+ mime_type: nil,
217
+ batch_size: 10,
218
+ destination: nil,
219
+ &blk
220
+
221
+ feature = { type: :LOGO_DETECTION }
222
+ feature[:max_results] = max_results
223
+ images << image if image
224
+
225
+ formatted_images = images.map do |img|
226
+ formatted_image = normalize_image img
227
+ formatted_image[:mime_type] = mime_type if mime_type
228
+ formatted_image
229
+ end
230
+
231
+ requests = formatted_images.map do |img|
232
+ {
233
+ image: img,
234
+ features: [feature]
235
+ }
236
+ end
237
+
238
+ if async
239
+ requests.map! do |request|
240
+ {
241
+ input_config: request[:image],
242
+ features: request[:features],
243
+ output_config: {
244
+ gcs_destination: destination,
245
+ batch_size: batch_size
246
+ }
247
+ }
248
+ end
249
+ async_batch_annotate_files requests, options
250
+ else
251
+ batch_annotate_images requests, options, &blk
252
+ end
253
+ end
254
+
255
+ # @param images [Array<String>, Array<File>]
256
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
257
+ # @param image [File, String]
258
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
259
+ # @param max_results [Integer]
260
+ # Optional. Defaults to 10.
261
+ # @param options [Google::Gax::CallOptions]
262
+ # Optional. Overrides the default settings for this call, e.g, timeout,
263
+ # retries, etc.
264
+ # @param async [Boolean]
265
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
266
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
267
+ # @param mime_type [String]
268
+ # Required only if async is true.
269
+ # @param batch_size [Integer]
270
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
271
+ # @param destination [String]
272
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
273
+ # @yield [result, operation] Access the result along with the RPC operation
274
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
275
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
276
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
277
+ # @example
278
+ # require "google/cloud/vision"
279
+ #
280
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
281
+ #
282
+ # response = image_annotator_client.label_detection image: "path\to\image.png"
283
+ # response.responses.each do |res|
284
+ # puts res
285
+ # end
286
+
287
+ def label_detection \
288
+ images: [],
289
+ image: nil,
290
+ max_results: 10,
291
+ options: nil,
292
+ async: false,
293
+ mime_type: nil,
294
+ batch_size: 10,
295
+ destination: nil,
296
+ &blk
297
+
298
+ feature = { type: :LABEL_DETECTION }
299
+ feature[:max_results] = max_results
300
+ images << image if image
301
+
302
+ formatted_images = images.map do |img|
303
+ formatted_image = normalize_image img
304
+ formatted_image[:mime_type] = mime_type if mime_type
305
+ formatted_image
306
+ end
307
+
308
+ requests = formatted_images.map do |img|
309
+ {
310
+ image: img,
311
+ features: [feature]
312
+ }
313
+ end
314
+
315
+ if async
316
+ requests.map! do |request|
317
+ {
318
+ input_config: request[:image],
319
+ features: request[:features],
320
+ output_config: {
321
+ gcs_destination: destination,
322
+ batch_size: batch_size
323
+ }
324
+ }
325
+ end
326
+ async_batch_annotate_files requests, options
327
+ else
328
+ batch_annotate_images requests, options, &blk
329
+ end
330
+ end
331
+
332
+ # @param images [Array<String>, Array<File>]
333
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
334
+ # @param image [File, String]
335
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
336
+ # @param max_results [Integer]
337
+ # Optional. Defaults to 10.
338
+ # @param options [Google::Gax::CallOptions]
339
+ # Optional. Overrides the default settings for this call, e.g, timeout,
340
+ # retries, etc.
341
+ # @param async [Boolean]
342
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
343
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
344
+ # @param mime_type [String]
345
+ # Required only if async is true.
346
+ # @param batch_size [Integer]
347
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
348
+ # @param destination [String]
349
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
350
+ # @yield [result, operation] Access the result along with the RPC operation
351
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
352
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
353
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
354
+ # @example
355
+ # require "google/cloud/vision"
356
+ #
357
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
358
+ #
359
+ # response = image_annotator_client.text_detection image: "path\to\image.png"
360
+ # response.responses.each do |res|
361
+ # puts res
362
+ # end
363
+
364
+ def text_detection \
365
+ images: [],
366
+ image: nil,
367
+ max_results: 10,
368
+ options: nil,
369
+ async: false,
370
+ mime_type: nil,
371
+ batch_size: 10,
372
+ destination: nil,
373
+ &blk
374
+
375
+ feature = { type: :TEXT_DETECTION }
376
+ feature[:max_results] = max_results
377
+ images << image if image
378
+
379
+ formatted_images = images.map do |img|
380
+ formatted_image = normalize_image img
381
+ formatted_image[:mime_type] = mime_type if mime_type
382
+ formatted_image
383
+ end
384
+
385
+ requests = formatted_images.map do |img|
386
+ {
387
+ image: img,
388
+ features: [feature]
389
+ }
390
+ end
391
+
392
+ if async
393
+ requests.map! do |request|
394
+ {
395
+ input_config: request[:image],
396
+ features: request[:features],
397
+ output_config: {
398
+ gcs_destination: destination,
399
+ batch_size: batch_size
400
+ }
401
+ }
402
+ end
403
+ async_batch_annotate_files requests, options
404
+ else
405
+ batch_annotate_images requests, options, &blk
406
+ end
407
+ end
408
+
409
+ # @param images [Array<String>, Array<File>]
410
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
411
+ # @param image [File, String]
412
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
413
+ # @param max_results [Integer]
414
+ # Optional. Defaults to 10.
415
+ # @param options [Google::Gax::CallOptions]
416
+ # Optional. Overrides the default settings for this call, e.g, timeout,
417
+ # retries, etc.
418
+ # @param async [Boolean]
419
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
420
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
421
+ # @param mime_type [String]
422
+ # Required only if async is true.
423
+ # @param batch_size [Integer]
424
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
425
+ # @param destination [String]
426
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
427
+ # @yield [result, operation] Access the result along with the RPC operation
428
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
429
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
430
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
431
+ # @example
432
+ # require "google/cloud/vision"
433
+ #
434
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
435
+ #
436
+ # response = image_annotator_client.document_text_detection image: "path\to\image.png"
437
+ # response.responses.each do |res|
438
+ # puts res
439
+ # end
440
+
441
+ def document_text_detection \
442
+ images: [],
443
+ image: nil,
444
+ max_results: 10,
445
+ options: nil,
446
+ async: false,
447
+ mime_type: nil,
448
+ batch_size: 10,
449
+ destination: nil,
450
+ &blk
451
+
452
+ feature = { type: :DOCUMENT_TEXT_DETECTION }
453
+ feature[:max_results] = max_results
454
+ images << image if image
455
+
456
+ formatted_images = images.map do |img|
457
+ formatted_image = normalize_image img
458
+ formatted_image[:mime_type] = mime_type if mime_type
459
+ formatted_image
460
+ end
461
+
462
+ requests = formatted_images.map do |img|
463
+ {
464
+ image: img,
465
+ features: [feature]
466
+ }
467
+ end
468
+
469
+ if async
470
+ requests.map! do |request|
471
+ {
472
+ input_config: request[:image],
473
+ features: request[:features],
474
+ output_config: {
475
+ gcs_destination: destination,
476
+ batch_size: batch_size
477
+ }
478
+ }
479
+ end
480
+ async_batch_annotate_files requests, options
481
+ else
482
+ batch_annotate_images requests, options, &blk
483
+ end
484
+ end
485
+
486
+ # @param images [Array<String>, Array<File>]
487
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
488
+ # @param image [File, String]
489
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
490
+ # @param max_results [Integer]
491
+ # Optional. Defaults to 10.
492
+ # @param options [Google::Gax::CallOptions]
493
+ # Optional. Overrides the default settings for this call, e.g, timeout,
494
+ # retries, etc.
495
+ # @param async [Boolean]
496
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
497
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
498
+ # @param mime_type [String]
499
+ # Required only if async is true.
500
+ # @param batch_size [Integer]
501
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
502
+ # @param destination [String]
503
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
504
+ # @yield [result, operation] Access the result along with the RPC operation
505
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
506
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
507
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
508
+ # @example
509
+ # require "google/cloud/vision"
510
+ #
511
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
512
+ #
513
+ # response = image_annotator_client.safe_search_detection image: "path\to\image.png"
514
+ # response.responses.each do |res|
515
+ # puts res
516
+ # end
517
+
518
+ def safe_search_detection \
519
+ images: [],
520
+ image: nil,
521
+ max_results: 10,
522
+ options: nil,
523
+ async: false,
524
+ mime_type: nil,
525
+ batch_size: 10,
526
+ destination: nil,
527
+ &blk
528
+
529
+ feature = { type: :SAFE_SEARCH_DETECTION }
530
+ feature[:max_results] = max_results
531
+ images << image if image
532
+
533
+ formatted_images = images.map do |img|
534
+ formatted_image = normalize_image img
535
+ formatted_image[:mime_type] = mime_type if mime_type
536
+ formatted_image
537
+ end
538
+
539
+ requests = formatted_images.map do |img|
540
+ {
541
+ image: img,
542
+ features: [feature]
543
+ }
544
+ end
545
+
546
+ if async
547
+ requests.map! do |request|
548
+ {
549
+ input_config: request[:image],
550
+ features: request[:features],
551
+ output_config: {
552
+ gcs_destination: destination,
553
+ batch_size: batch_size
554
+ }
555
+ }
556
+ end
557
+ async_batch_annotate_files requests, options
558
+ else
559
+ batch_annotate_images requests, options, &blk
560
+ end
561
+ end
562
+
563
+ # @param images [Array<String>, Array<File>]
564
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
565
+ # @param image [File, String]
566
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
567
+ # @param max_results [Integer]
568
+ # Optional. Defaults to 10.
569
+ # @param options [Google::Gax::CallOptions]
570
+ # Optional. Overrides the default settings for this call, e.g, timeout,
571
+ # retries, etc.
572
+ # @param async [Boolean]
573
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
574
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
575
+ # @param mime_type [String]
576
+ # Required only if async is true.
577
+ # @param batch_size [Integer]
578
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
579
+ # @param destination [String]
580
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
581
+ # @yield [result, operation] Access the result along with the RPC operation
582
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
583
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
584
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
585
+ # @example
586
+ # require "google/cloud/vision"
587
+ #
588
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
589
+ #
590
+ # response = image_annotator_client.image_properties_detection image: "path\to\image.png"
591
+ # response.responses.each do |res|
592
+ # puts res
593
+ # end
594
+
595
+ def image_properties_detection \
596
+ images: [],
597
+ image: nil,
598
+ max_results: 10,
599
+ options: nil,
600
+ async: false,
601
+ mime_type: nil,
602
+ batch_size: 10,
603
+ destination: nil,
604
+ &blk
605
+
606
+ feature = { type: :IMAGE_PROPERTIES }
607
+ feature[:max_results] = max_results
608
+ images << image if image
609
+
610
+ formatted_images = images.map do |img|
611
+ formatted_image = normalize_image img
612
+ formatted_image[:mime_type] = mime_type if mime_type
613
+ formatted_image
614
+ end
615
+
616
+ requests = formatted_images.map do |img|
617
+ {
618
+ image: img,
619
+ features: [feature]
620
+ }
621
+ end
622
+
623
+ if async
624
+ requests.map! do |request|
625
+ {
626
+ input_config: request[:image],
627
+ features: request[:features],
628
+ output_config: {
629
+ gcs_destination: destination,
630
+ batch_size: batch_size
631
+ }
632
+ }
633
+ end
634
+ async_batch_annotate_files requests, options
635
+ else
636
+ batch_annotate_images requests, options, &blk
637
+ end
638
+ end
639
+
640
+ # @param images [Array<String>, Array<File>]
641
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
642
+ # @param image [File, String]
643
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
644
+ # @param max_results [Integer]
645
+ # Optional. Defaults to 10.
646
+ # @param options [Google::Gax::CallOptions]
647
+ # Optional. Overrides the default settings for this call, e.g, timeout,
648
+ # retries, etc.
649
+ # @param async [Boolean]
650
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
651
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
652
+ # @param mime_type [String]
653
+ # Required only if async is true.
654
+ # @param batch_size [Integer]
655
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
656
+ # @param destination [String]
657
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
658
+ # @yield [result, operation] Access the result along with the RPC operation
659
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
660
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
661
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
662
+ # @example
663
+ # require "google/cloud/vision"
664
+ #
665
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
666
+ #
667
+ # response = image_annotator_client.crop_hints_detection image: "path\to\image.png"
668
+ # response.responses.each do |res|
669
+ # puts res
670
+ # end
671
+
672
+ def crop_hints_detection \
673
+ images: [],
674
+ image: nil,
675
+ max_results: 10,
676
+ options: nil,
677
+ async: false,
678
+ mime_type: nil,
679
+ batch_size: 10,
680
+ destination: nil,
681
+ &blk
682
+
683
+ feature = { type: :CROP_HINTS }
684
+ feature[:max_results] = max_results
685
+ images << image if image
686
+
687
+ formatted_images = images.map do |img|
688
+ formatted_image = normalize_image img
689
+ formatted_image[:mime_type] = mime_type if mime_type
690
+ formatted_image
691
+ end
692
+
693
+ requests = formatted_images.map do |img|
694
+ {
695
+ image: img,
696
+ features: [feature]
697
+ }
698
+ end
699
+
700
+ if async
701
+ requests.map! do |request|
702
+ {
703
+ input_config: request[:image],
704
+ features: request[:features],
705
+ output_config: {
706
+ gcs_destination: destination,
707
+ batch_size: batch_size
708
+ }
709
+ }
710
+ end
711
+ async_batch_annotate_files requests, options
712
+ else
713
+ batch_annotate_images requests, options, &blk
714
+ end
715
+ end
716
+
717
+ # @param images [Array<String>, Array<File>]
718
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
719
+ # @param image [File, String]
720
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
721
+ # @param max_results [Integer]
722
+ # Optional. Defaults to 10.
723
+ # @param options [Google::Gax::CallOptions]
724
+ # Optional. Overrides the default settings for this call, e.g, timeout,
725
+ # retries, etc.
726
+ # @param async [Boolean]
727
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
728
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::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 number of input files per output json.
733
+ # @param destination [String]
734
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
735
+ # @yield [result, operation] Access the result along with the RPC operation
736
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
737
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
738
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
739
+ # @example
740
+ # require "google/cloud/vision"
741
+ #
742
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
743
+ #
744
+ # response = image_annotator_client.product_search_detection image: "path\to\image.png"
745
+ # response.responses.each do |res|
746
+ # puts res
747
+ # end
748
+
749
+ def product_search_detection \
750
+ images: [],
751
+ image: nil,
752
+ max_results: 10,
753
+ options: nil,
754
+ async: false,
755
+ mime_type: nil,
756
+ batch_size: 10,
757
+ destination: nil,
758
+ &blk
759
+
760
+ feature = { type: :PRODUCT_SEARCH }
761
+ feature[:max_results] = max_results
762
+ images << image if image
763
+
764
+ formatted_images = images.map do |img|
765
+ formatted_image = normalize_image img
766
+ formatted_image[:mime_type] = mime_type if mime_type
767
+ formatted_image
768
+ end
769
+
770
+ requests = formatted_images.map do |img|
771
+ {
772
+ image: img,
773
+ features: [feature]
774
+ }
775
+ end
776
+
777
+ if async
778
+ requests.map! do |request|
779
+ {
780
+ input_config: request[:image],
781
+ features: request[:features],
782
+ output_config: {
783
+ gcs_destination: destination,
784
+ batch_size: batch_size
785
+ }
786
+ }
787
+ end
788
+ async_batch_annotate_files requests, options
789
+ else
790
+ batch_annotate_images requests, options, &blk
791
+ end
792
+ end
793
+
794
+ # @param images [Array<String>, Array<File>]
795
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
796
+ # @param image [File, String]
797
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
798
+ # @param max_results [Integer]
799
+ # Optional. Defaults to 10.
800
+ # @param options [Google::Gax::CallOptions]
801
+ # Optional. Overrides the default settings for this call, e.g, timeout,
802
+ # retries, etc.
803
+ # @param async [Boolean]
804
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
805
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
806
+ # @param mime_type [String]
807
+ # Required only if async is true.
808
+ # @param batch_size [Integer]
809
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
810
+ # @param destination [String]
811
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
812
+ # @yield [result, operation] Access the result along with the RPC operation
813
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
814
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
815
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
816
+ # @example
817
+ # require "google/cloud/vision"
818
+ #
819
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
820
+ #
821
+ # response = image_annotator_client.object_localization_detection image: "path\to\image.png"
822
+ # response.responses.each do |res|
823
+ # puts res
824
+ # end
825
+
826
+ def object_localization_detection \
827
+ images: [],
828
+ image: nil,
829
+ max_results: 10,
830
+ options: nil,
831
+ async: false,
832
+ mime_type: nil,
833
+ batch_size: 10,
834
+ destination: nil,
835
+ &blk
836
+
837
+ feature = { type: :OBJECT_LOCALIZATION }
838
+ feature[:max_results] = max_results
839
+ images << image if image
840
+
841
+ formatted_images = images.map do |img|
842
+ formatted_image = normalize_image img
843
+ formatted_image[:mime_type] = mime_type if mime_type
844
+ formatted_image
845
+ end
846
+
847
+ requests = formatted_images.map do |img|
848
+ {
849
+ image: img,
850
+ features: [feature]
851
+ }
852
+ end
853
+
854
+ if async
855
+ requests.map! do |request|
856
+ {
857
+ input_config: request[:image],
858
+ features: request[:features],
859
+ output_config: {
860
+ gcs_destination: destination,
861
+ batch_size: batch_size
862
+ }
863
+ }
864
+ end
865
+ async_batch_annotate_files requests, options
866
+ else
867
+ batch_annotate_images requests, options, &blk
868
+ end
869
+ end
870
+
871
+ # @param images [Array<String>, Array<File>]
872
+ # An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
873
+ # @param image [File, String]
874
+ # A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
875
+ # @param max_results [Integer]
876
+ # Optional. Defaults to 10.
877
+ # @param options [Google::Gax::CallOptions]
878
+ # Optional. Overrides the default settings for this call, e.g, timeout,
879
+ # retries, etc.
880
+ # @param async [Boolean]
881
+ # Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
882
+ # BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
883
+ # @param mime_type [String]
884
+ # Required only if async is true.
885
+ # @param batch_size [Integer]
886
+ # Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
887
+ # @param destination [String]
888
+ # Required only if async is true. A Google Cloud Storage location for storing the output.
889
+ # @yield [result, operation] Access the result along with the RPC operation
890
+ # @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
891
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
892
+ # @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse, Google::Gax::Operation]
893
+ # @example
894
+ # require "google/cloud/vision"
895
+ #
896
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1)
897
+ #
898
+ # response = image_annotator_client.web_detection image: "path\to\image.png"
899
+ # response.responses.each do |res|
900
+ # puts res
901
+ # end
902
+
903
+ def web_detection \
904
+ images: [],
905
+ image: nil,
906
+ max_results: 10,
907
+ options: nil,
908
+ async: false,
909
+ mime_type: nil,
910
+ batch_size: 10,
911
+ destination: nil,
912
+ &blk
913
+
914
+ feature = { type: :WEB_DETECTION }
915
+ feature[:max_results] = max_results
916
+ images << image if image
917
+
918
+ formatted_images = images.map do |img|
919
+ formatted_image = normalize_image img
920
+ formatted_image[:mime_type] = mime_type if mime_type
921
+ formatted_image
922
+ end
923
+
924
+ requests = formatted_images.map do |img|
925
+ {
926
+ image: img,
927
+ features: [feature]
928
+ }
929
+ end
930
+
931
+ if async
932
+ requests.map! do |request|
933
+ {
934
+ input_config: request[:image],
935
+ features: request[:features],
936
+ output_config: {
937
+ gcs_destination: destination,
938
+ batch_size: batch_size
939
+ }
940
+ }
941
+ end
942
+ async_batch_annotate_files requests, options
943
+ else
944
+ batch_annotate_images requests, options, &blk
945
+ end
946
+ end
947
+
948
+ private
949
+
950
+ def normalize_image image
951
+ formatted_image =
952
+ if image.respond_to? :binmode
953
+ { content: image.binmode.read }
954
+ elsif image.is_a? String
955
+ if File.file? image
956
+ { content: File.binread(image) }
957
+ elsif image =~ URI::DEFAULT_PARSER.make_regexp
958
+ if URI(image).scheme == "gs"
959
+ { source: { gcs_image_uri: image } }
960
+ else
961
+ { source: { image_uri: image } }
962
+ end
963
+ end
964
+ end
965
+ raise TypeError.new("Image must be a filepath, url, or IO object") unless formatted_image
966
+ formatted_image
967
+ end
968
+ end
969
+ end
970
+ end
971
+ end
972
+ end