google-cloud-vision 0.31.0 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -9
- data/LICENSE +1 -1
- data/README.md +94 -0
- data/lib/google/cloud/vision.rb +200 -535
- data/lib/google/cloud/vision/v1.rb +129 -55
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/image_annotator.rb +9 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search.rb +88 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search_service.rb +539 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/text_annotation.rb +3 -3
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/web_detection.rb +2 -1
- data/lib/google/cloud/vision/{version.rb → v1/doc/google/protobuf/empty.rb} +13 -6
- data/lib/google/cloud/vision/v1/doc/google/protobuf/field_mask.rb +230 -0
- data/lib/google/cloud/vision/v1/doc/google/protobuf/timestamp.rb +109 -0
- data/lib/google/cloud/vision/v1/geometry_pb.rb +1 -0
- data/lib/google/cloud/vision/v1/helpers.rb +972 -0
- data/lib/google/cloud/vision/v1/image_annotator_client.rb +4 -4
- data/lib/google/cloud/vision/v1/image_annotator_pb.rb +5 -0
- data/lib/google/cloud/vision/v1/image_annotator_services_pb.rb +2 -1
- data/lib/google/cloud/vision/v1/product_search_client.rb +1337 -0
- data/lib/google/cloud/vision/v1/product_search_client_config.json +116 -0
- data/lib/google/cloud/vision/v1/product_search_pb.rb +45 -0
- data/lib/google/cloud/vision/v1/product_search_service_pb.rb +191 -0
- data/lib/google/cloud/vision/v1/product_search_service_services_pb.rb +224 -0
- data/lib/google/cloud/vision/v1p3beta1.rb +233 -0
- data/lib/google/cloud/vision/v1p3beta1/credentials.rb +42 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/geometry.rb +72 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/image_annotator.rb +763 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search.rb +154 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search_service.rb +533 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/text_annotation.rb +254 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/web_detection.rb +101 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/longrunning/operations.rb +93 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/any.rb +130 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/field_mask.rb +230 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/timestamp.rb +109 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/wrappers.rb +90 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/rpc/status.rb +84 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/type/color.rb +156 -0
- data/lib/google/cloud/vision/v1p3beta1/doc/google/type/latlng.rb +65 -0
- data/lib/google/cloud/vision/v1p3beta1/geometry_pb.rb +43 -0
- data/lib/google/cloud/vision/v1p3beta1/helpers.rb +972 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_client.rb +302 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_client_config.json +36 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_pb.rb +304 -0
- data/lib/google/cloud/vision/v1p3beta1/image_annotator_services_pb.rb +55 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_client.rb +1351 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_client_config.json +116 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_pb.rb +64 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_service_pb.rb +191 -0
- data/lib/google/cloud/vision/v1p3beta1/product_search_service_services_pb.rb +222 -0
- data/lib/google/cloud/vision/v1p3beta1/text_annotation_pb.rb +94 -0
- data/lib/google/cloud/vision/v1p3beta1/web_detection_pb.rb +51 -0
- metadata +53 -122
- data/AUTHENTICATION.md +0 -179
- data/CHANGELOG.md +0 -109
- data/CODE_OF_CONDUCT.md +0 -40
- data/CONTRIBUTING.md +0 -188
- data/LOGGING.md +0 -32
- data/OVERVIEW.md +0 -202
- data/TROUBLESHOOTING.md +0 -37
- data/lib/google-cloud-vision.rb +0 -146
- data/lib/google/cloud/vision/annotate.rb +0 -303
- data/lib/google/cloud/vision/annotation.rb +0 -553
- data/lib/google/cloud/vision/annotation/crop_hint.rb +0 -126
- data/lib/google/cloud/vision/annotation/entity.rb +0 -225
- data/lib/google/cloud/vision/annotation/face.rb +0 -1497
- data/lib/google/cloud/vision/annotation/normalized_vertex.rb +0 -76
- data/lib/google/cloud/vision/annotation/object_localization.rb +0 -115
- data/lib/google/cloud/vision/annotation/properties.rb +0 -220
- data/lib/google/cloud/vision/annotation/safe_search.rb +0 -153
- data/lib/google/cloud/vision/annotation/text.rb +0 -1015
- data/lib/google/cloud/vision/annotation/vertex.rb +0 -91
- data/lib/google/cloud/vision/annotation/web.rb +0 -420
- data/lib/google/cloud/vision/credentials.rb +0 -57
- data/lib/google/cloud/vision/image.rb +0 -832
- data/lib/google/cloud/vision/location.rb +0 -98
- data/lib/google/cloud/vision/project.rb +0 -367
- data/lib/google/cloud/vision/service.rb +0 -83
@@ -1,98 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
module Google
|
17
|
-
module Cloud
|
18
|
-
module Vision
|
19
|
-
##
|
20
|
-
# # Location
|
21
|
-
#
|
22
|
-
# A latitude/longitude pair with values conforming to the [WGS84
|
23
|
-
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
24
|
-
#
|
25
|
-
# @attr [Float] latitude The degrees latitude conforming to the [WGS84
|
26
|
-
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
27
|
-
# @attr [Float] longitude The degrees longitude conforming to the [WGS84
|
28
|
-
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
29
|
-
#
|
30
|
-
# @example
|
31
|
-
# require "google/cloud/vision"
|
32
|
-
#
|
33
|
-
# vision = Google::Cloud::Vision.new
|
34
|
-
#
|
35
|
-
# image = vision.image "path/to/landmark.jpg"
|
36
|
-
# entity = image.landmark
|
37
|
-
#
|
38
|
-
# location = entity.locations.first
|
39
|
-
#
|
40
|
-
# location.latitude #=> 43.878264
|
41
|
-
# location.longitude #=> -103.45700740814209
|
42
|
-
#
|
43
|
-
class Location
|
44
|
-
attr_accessor :latitude, :longitude
|
45
|
-
|
46
|
-
##
|
47
|
-
# @private Creates a new Location instance.
|
48
|
-
def initialize latitude, longitude
|
49
|
-
@latitude = latitude
|
50
|
-
@longitude = longitude
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Returns the object's property values as an array.
|
55
|
-
#
|
56
|
-
# @return [Array]
|
57
|
-
#
|
58
|
-
def to_a
|
59
|
-
[latitude, longitude]
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# Converts object to a hash. All keys will be symbolized.
|
64
|
-
#
|
65
|
-
# @return [Hash]
|
66
|
-
#
|
67
|
-
def to_h
|
68
|
-
{ latitude: latitude, longitude: longitude }
|
69
|
-
end
|
70
|
-
|
71
|
-
# @private
|
72
|
-
def to_s
|
73
|
-
"(latitude: #{latitude.inspect}, longitude: #{longitude.inspect})"
|
74
|
-
end
|
75
|
-
|
76
|
-
# @private
|
77
|
-
def inspect
|
78
|
-
"#<#{self.class.name} #{self}>"
|
79
|
-
end
|
80
|
-
|
81
|
-
##
|
82
|
-
# @private New GRPC LatLng object.
|
83
|
-
def to_grpc
|
84
|
-
Google::Type::LatLng.new(
|
85
|
-
latitude: latitude,
|
86
|
-
longitude: longitude
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# @private New Location from a GRPC LatLng object.
|
92
|
-
def self.from_grpc grpc
|
93
|
-
new grpc.latitude, grpc.longitude
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,367 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
require "google/cloud/errors"
|
17
|
-
require "google/cloud/vision/service"
|
18
|
-
require "google/cloud/vision/credentials"
|
19
|
-
require "google/cloud/vision/annotate"
|
20
|
-
require "google/cloud/vision/image"
|
21
|
-
require "google/cloud/vision/annotation"
|
22
|
-
|
23
|
-
module Google
|
24
|
-
module Cloud
|
25
|
-
module Vision
|
26
|
-
##
|
27
|
-
# # Project
|
28
|
-
#
|
29
|
-
# Google Cloud Vision allows developers to easily integrate vision
|
30
|
-
# detection features within applications, including image labeling, face
|
31
|
-
# and landmark detection, optical character recognition (OCR), and tagging
|
32
|
-
# of explicit content.
|
33
|
-
#
|
34
|
-
# @example
|
35
|
-
# require "google/cloud/vision"
|
36
|
-
#
|
37
|
-
# vision = Google::Cloud::Vision.new
|
38
|
-
#
|
39
|
-
# image = vision.image "path/to/landmark.jpg"
|
40
|
-
#
|
41
|
-
# annotation = vision.annotate image, labels: true
|
42
|
-
#
|
43
|
-
# annotation.labels.map &:description
|
44
|
-
# # ["stone carving", "ancient history", "statue", "sculpture",
|
45
|
-
# # "monument", "landmark"]
|
46
|
-
#
|
47
|
-
# See Google::Cloud#vision
|
48
|
-
class Project
|
49
|
-
##
|
50
|
-
# @private The Service object.
|
51
|
-
attr_accessor :service
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Creates a new Project instance.
|
55
|
-
def initialize service
|
56
|
-
@service = service
|
57
|
-
end
|
58
|
-
|
59
|
-
# The Vision project connected to.
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# require "google/cloud/vision"
|
63
|
-
#
|
64
|
-
# vision = Google::Cloud::Vision.new(
|
65
|
-
# project_id: "my-project",
|
66
|
-
# credentials: "/path/to/keyfile.json"
|
67
|
-
# )
|
68
|
-
#
|
69
|
-
# vision.project_id #=> "my-project"
|
70
|
-
#
|
71
|
-
def project_id
|
72
|
-
service.project
|
73
|
-
end
|
74
|
-
alias project project_id
|
75
|
-
|
76
|
-
##
|
77
|
-
# Returns a new image from the given source.
|
78
|
-
#
|
79
|
-
# Cloud Vision sets upper limits on file size as well as on the total
|
80
|
-
# combined size of all images in a request. Reducing your file size can
|
81
|
-
# significantly improve throughput; however, be careful not to reduce
|
82
|
-
# image quality in the process. See [Best Practices - Image
|
83
|
-
# Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
|
84
|
-
# for current file size limits.
|
85
|
-
#
|
86
|
-
# Note that an object in Google Cloud Storage is a single entity;
|
87
|
-
# permissions affect only that object. "Directory permissions" do not
|
88
|
-
# exist (though default bucket permissions do exist). Make sure the code
|
89
|
-
# which performs your request has access to that image.
|
90
|
-
#
|
91
|
-
# @see https://cloud.google.com/vision/docs/best-practices Best
|
92
|
-
# Practices
|
93
|
-
#
|
94
|
-
# @param [String, IO, StringIO, Tempfile, Google::Cloud::Storage::File]
|
95
|
-
# source A string file path, publicly-accessible image HTTP/HTTPS URL,
|
96
|
-
# or Cloud Storage URI of the form
|
97
|
-
# `"gs://bucketname/path/to/image_filename"`; or a File, IO, StringIO,
|
98
|
-
# or Tempfile instance; or an instance of
|
99
|
-
# Google::Cloud::Storage::File.
|
100
|
-
#
|
101
|
-
# @return [Image] An image for the Vision service.
|
102
|
-
#
|
103
|
-
# @example With a publicly-accessible image HTTP/HTTPS URL:
|
104
|
-
# require "google/cloud/vision"
|
105
|
-
#
|
106
|
-
# vision = Google::Cloud::Vision.new
|
107
|
-
#
|
108
|
-
# image = vision.image "https://www.example.com/images/landmark.jpg"
|
109
|
-
#
|
110
|
-
# @example With a Google Cloud Storage URI:
|
111
|
-
# require "google/cloud/vision"
|
112
|
-
#
|
113
|
-
# vision = Google::Cloud::Vision.new
|
114
|
-
#
|
115
|
-
# image = vision.image "gs://bucket-name/path_to_image_object"
|
116
|
-
#
|
117
|
-
# @example With a local file path:
|
118
|
-
# require "google/cloud/vision"
|
119
|
-
#
|
120
|
-
# vision = Google::Cloud::Vision.new
|
121
|
-
#
|
122
|
-
# image = vision.image "path/to/landmark.jpg"
|
123
|
-
#
|
124
|
-
def image source
|
125
|
-
return source if source.is_a? Image
|
126
|
-
Image.from_source source, self
|
127
|
-
end
|
128
|
-
|
129
|
-
##
|
130
|
-
# Performs detection of Cloud Vision
|
131
|
-
# [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#Feature)
|
132
|
-
# on the given image(s). If no options for features are provided,
|
133
|
-
# **all** image detection features will be performed, with a default of
|
134
|
-
# `100` results for faces, landmarks, logos, labels, crop_hints, and
|
135
|
-
# web. If any feature option is provided, only the specified feature
|
136
|
-
# detections will be performed. Please review
|
137
|
-
# [Pricing](https://cloud.google.com/vision/docs/pricing) before use, as
|
138
|
-
# a separate charge is incurred for each feature performed on an image.
|
139
|
-
#
|
140
|
-
# Cloud Vision sets upper limits on file size as well as on the total
|
141
|
-
# combined size of all images in a request. Reducing your file size can
|
142
|
-
# significantly improve throughput; however, be careful not to reduce
|
143
|
-
# image quality in the process. See [Best Practices - Image
|
144
|
-
# Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
|
145
|
-
# for current file size limits.
|
146
|
-
#
|
147
|
-
# @see https://cloud.google.com/vision/docs/requests-and-responses Cloud
|
148
|
-
# Vision API Requests and Responses
|
149
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#AnnotateImageRequest
|
150
|
-
# AnnotateImageRequest
|
151
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
152
|
-
#
|
153
|
-
# @param [Image, Object] images The image or images to annotate. This
|
154
|
-
# can be an {Image} instance, or any other type that converts to an
|
155
|
-
# {Image}: A string file path, publicly-accessible image HTTP/HTTPS
|
156
|
-
# URL, or Cloud Storage URI of the form
|
157
|
-
# `"gs://bucketname/path/to/image_filename"`; or a File, IO, StringIO,
|
158
|
-
# or Tempfile instance; or an instance of
|
159
|
-
# Google::Cloud::Storage::File.
|
160
|
-
# @param [Boolean, Integer] faces Whether to perform the facial
|
161
|
-
# detection feature. The maximum number of results is configured in
|
162
|
-
# {Google::Cloud::Vision.default_max_faces}, or may be provided here.
|
163
|
-
# Optional.
|
164
|
-
# @param [Boolean, Integer] landmarks Whether to perform the landmark
|
165
|
-
# detection feature. The maximum number of results is configured in
|
166
|
-
# {Google::Cloud::Vision.default_max_landmarks}, or may be provided
|
167
|
-
# here. Optional.
|
168
|
-
# @param [Boolean, Integer] logos Whether to perform the logo detection
|
169
|
-
# feature. The maximum number of results is configured in
|
170
|
-
# {Google::Cloud::Vision.default_max_logos}, or may be provided here.
|
171
|
-
# Optional.
|
172
|
-
# @param [Boolean, Integer] labels Whether to perform the label
|
173
|
-
# detection feature. The maximum number of results is configured in
|
174
|
-
# {Google::Cloud::Vision.default_max_labels}, or may be provided here.
|
175
|
-
# Optional.
|
176
|
-
# @param [Boolean] text Whether to perform the text detection feature
|
177
|
-
# (OCR for shorter documents with sparse text). Optional.
|
178
|
-
# @param [Boolean] document Whether to perform the document text
|
179
|
-
# detection feature (OCR for longer documents with dense text).
|
180
|
-
# Optional.
|
181
|
-
# @param [Boolean] safe_search Whether to perform the safe search
|
182
|
-
# feature. Optional.
|
183
|
-
# @param [Boolean] properties Whether to perform the image properties
|
184
|
-
# feature (currently, the image's dominant colors.) Optional.
|
185
|
-
# @param [Boolean, Integer] crop_hints Whether to perform the crop hints
|
186
|
-
# feature. Optional.
|
187
|
-
# @param [Boolean, Integer] web Whether to perform the web annotation
|
188
|
-
# feature. Optional.
|
189
|
-
# @param [Boolean, Integer] object_localizations Whether to perform the
|
190
|
-
# object localizations feature. Optional.
|
191
|
-
#
|
192
|
-
# @yield [annotate] A block for requests that involve multiple feature
|
193
|
-
# configurations. See {Annotate#annotate}.
|
194
|
-
# @yieldparam [Annotate] annotate the Annotate object
|
195
|
-
#
|
196
|
-
# @return [Annotation, Array<Annotation>] The results for all image
|
197
|
-
# detections, returned as a single {Annotation} instance for one
|
198
|
-
# image, or as an array of {Annotation} instances, one per image, for
|
199
|
-
# multiple images.
|
200
|
-
#
|
201
|
-
# @example With a single image:
|
202
|
-
# require "google/cloud/vision"
|
203
|
-
#
|
204
|
-
# vision = Google::Cloud::Vision.new
|
205
|
-
#
|
206
|
-
# image = vision.image "path/to/landmark.jpg"
|
207
|
-
#
|
208
|
-
# annotation = vision.annotate image, labels: true
|
209
|
-
#
|
210
|
-
# annotation.labels.map &:description
|
211
|
-
# # ["stone carving", "ancient history", "statue", "sculpture",
|
212
|
-
# # "monument", "landmark"]
|
213
|
-
#
|
214
|
-
# @example With multiple images:
|
215
|
-
# require "google/cloud/vision"
|
216
|
-
#
|
217
|
-
# vision = Google::Cloud::Vision.new
|
218
|
-
#
|
219
|
-
# face_img = vision.image "path/to/face.jpg"
|
220
|
-
# landmark_img = vision.image "path/to/landmark.jpg"
|
221
|
-
#
|
222
|
-
# annotations = vision.annotate face_img, landmark_img, labels: true
|
223
|
-
#
|
224
|
-
# annotations[0].labels.count #=> 4
|
225
|
-
# annotations[1].labels.count #=> 6
|
226
|
-
#
|
227
|
-
# @example With multiple images and configurations passed in a block:
|
228
|
-
# require "google/cloud/vision"
|
229
|
-
#
|
230
|
-
# vision = Google::Cloud::Vision.new
|
231
|
-
#
|
232
|
-
# face_img = vision.image "path/to/face.jpg"
|
233
|
-
# landmark_img = vision.image "path/to/landmark.jpg"
|
234
|
-
# text_image = vision.image "path/to/text.png"
|
235
|
-
#
|
236
|
-
# annotations = vision.annotate do |annotate|
|
237
|
-
# annotate.annotate face_img, faces: true, labels: true
|
238
|
-
# annotate.annotate landmark_img, landmarks: true
|
239
|
-
# annotate.annotate text_image, text: true
|
240
|
-
# end
|
241
|
-
#
|
242
|
-
# annotations[0].faces.count #=> 1
|
243
|
-
# annotations[0].labels.count #=> 4
|
244
|
-
# annotations[1].landmarks.count #=> 1
|
245
|
-
# annotations[2].text.pages.count #=> 1
|
246
|
-
#
|
247
|
-
# @example Maximum result values can also be provided:
|
248
|
-
# require "google/cloud/vision"
|
249
|
-
#
|
250
|
-
# vision = Google::Cloud::Vision.new
|
251
|
-
#
|
252
|
-
# image = vision.image "path/to/landmark.jpg"
|
253
|
-
#
|
254
|
-
# annotation = vision.annotate image, labels: 3
|
255
|
-
#
|
256
|
-
# annotation.labels.map &:description
|
257
|
-
# # ["stone carving", "ancient history", "statue"]
|
258
|
-
#
|
259
|
-
def annotate *images, faces: false, landmarks: false, logos: false,
|
260
|
-
labels: false, text: false, document: false,
|
261
|
-
safe_search: false, properties: false, crop_hints: false,
|
262
|
-
web: false, object_localizations: false
|
263
|
-
a = Annotate.new self
|
264
|
-
a.annotate(*images, faces: faces, landmarks: landmarks, logos: logos,
|
265
|
-
labels: labels, text: text, document: document,
|
266
|
-
safe_search: safe_search, properties: properties,
|
267
|
-
crop_hints: crop_hints, web: web,
|
268
|
-
object_localizations: object_localizations)
|
269
|
-
|
270
|
-
yield a if block_given?
|
271
|
-
|
272
|
-
grpc = service.annotate a.requests
|
273
|
-
annotations = Array(grpc.responses).map do |g|
|
274
|
-
raise Error.from_error(g.error) if g.error
|
275
|
-
Annotation.from_grpc g
|
276
|
-
end
|
277
|
-
return annotations.first if annotations.count == 1
|
278
|
-
annotations
|
279
|
-
end
|
280
|
-
|
281
|
-
# rubocop:disable LineLength
|
282
|
-
|
283
|
-
##
|
284
|
-
# Run asynchronous image detection and annotation for a list of generic
|
285
|
-
# files, such as PDF files, which may contain multiple pages and
|
286
|
-
# multiple images per page. Progress and results can be retrieved
|
287
|
-
# through the google.longrunning.Operations interface.
|
288
|
-
# Operation.metadata contains OperationMetadata (metadata).
|
289
|
-
# Operation.response contains AsyncBatchAnnotateFilesResponse
|
290
|
-
# (results).
|
291
|
-
#
|
292
|
-
# @param requests [Array<Google::Cloud::Vision::V1::AsyncAnnotateFileRequest|Hash>]
|
293
|
-
# Individual async file annotation requests for this batch.
|
294
|
-
# A hash of the same form as
|
295
|
-
# `Google::Cloud::Vision::V1::AsyncAnnotateFileRequest` can also be
|
296
|
-
# provided.
|
297
|
-
# @param options [Google::Gax::CallOptions]
|
298
|
-
# Overrides the default settings for this call, e.g, timeout,
|
299
|
-
# retries, etc.
|
300
|
-
# @return [Google::Gax::Operation]
|
301
|
-
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
302
|
-
#
|
303
|
-
# @example
|
304
|
-
# require "google/cloud/vision"
|
305
|
-
#
|
306
|
-
# # Create a new vision client.
|
307
|
-
# vision_client = Google::Cloud::Vision.new project_id: 'project_id'
|
308
|
-
# requests = [{
|
309
|
-
# input_config: {
|
310
|
-
# gcs_source: { uri: 'source_uri' },
|
311
|
-
# mime_type: "application/pdf"
|
312
|
-
# },
|
313
|
-
# features: [{ type: :DOCUMENT_TEXT_DETECTION }],
|
314
|
-
# output_config: {
|
315
|
-
# gcs_destination: { uri: 'destination_uri' },
|
316
|
-
# batch_size: 2
|
317
|
-
# }
|
318
|
-
# }]
|
319
|
-
#
|
320
|
-
# # Register a callback during the method call.
|
321
|
-
# operation = vision_client
|
322
|
-
# .async_batch_annotate_files(requests) do |op|
|
323
|
-
# raise op.results.message if op.error?
|
324
|
-
# op_results = op.results
|
325
|
-
# # Process the results.
|
326
|
-
#
|
327
|
-
# metadata = op.metadata
|
328
|
-
# # Process the metadata.
|
329
|
-
# end
|
330
|
-
#
|
331
|
-
# # Or use the return value to register a callback.
|
332
|
-
# operation.on_done do |op|
|
333
|
-
# raise op.results.message if op.error?
|
334
|
-
# op_results = op.results
|
335
|
-
# # Process the results.
|
336
|
-
#
|
337
|
-
# metadata = op.metadata
|
338
|
-
# # Process the metadata.
|
339
|
-
# end
|
340
|
-
#
|
341
|
-
# # Manually reload the operation.
|
342
|
-
# operation.reload!
|
343
|
-
#
|
344
|
-
# # Or block until the operation completes, triggering callbacks on
|
345
|
-
# # completion.
|
346
|
-
# operation.wait_until_done!
|
347
|
-
#
|
348
|
-
def async_batch_annotate_files requests, options = {}
|
349
|
-
service.service.async_batch_annotate_files requests, options
|
350
|
-
end
|
351
|
-
|
352
|
-
# rubocop:enable LineLength
|
353
|
-
|
354
|
-
alias mark annotate
|
355
|
-
alias detect annotate
|
356
|
-
|
357
|
-
protected
|
358
|
-
|
359
|
-
##
|
360
|
-
# Raise an error unless an active connection is available.
|
361
|
-
def ensure_service!
|
362
|
-
raise "Must have active connection" unless service
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|