google-cloud-vision 0.20.2 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google-cloud-vision.rb +14 -26
- data/lib/google/cloud/vision.rb +108 -91
- data/lib/google/cloud/vision/annotate.rb +23 -25
- data/lib/google/cloud/vision/annotation.rb +58 -77
- data/lib/google/cloud/vision/annotation/entity.rb +24 -27
- data/lib/google/cloud/vision/annotation/face.rb +131 -148
- data/lib/google/cloud/vision/annotation/properties.rb +25 -27
- data/lib/google/cloud/vision/annotation/safe_search.rb +13 -14
- data/lib/google/cloud/vision/annotation/text.rb +27 -29
- data/lib/google/cloud/vision/annotation/vertex.rb +4 -5
- data/lib/google/cloud/vision/image.rb +39 -46
- data/lib/google/cloud/vision/location.rb +8 -9
- data/lib/google/cloud/vision/project.rb +31 -37
- data/lib/google/cloud/vision/service.rb +46 -21
- data/lib/google/cloud/vision/v1/image_annotator_api.rb +22 -6
- data/lib/google/cloud/vision/version.rb +1 -1
- metadata +63 -7
@@ -28,10 +28,9 @@ module Google
|
|
28
28
|
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
29
29
|
#
|
30
30
|
# @example
|
31
|
-
# require "google/cloud"
|
31
|
+
# require "google/cloud/vision"
|
32
32
|
#
|
33
|
-
#
|
34
|
-
# vision = gcloud.vision
|
33
|
+
# vision = Google::Cloud::Vision.new
|
35
34
|
#
|
36
35
|
# image = vision.image "path/to/landmark.jpg"
|
37
36
|
# entity = image.landmark
|
@@ -80,18 +79,18 @@ module Google
|
|
80
79
|
end
|
81
80
|
|
82
81
|
##
|
83
|
-
# @private New
|
84
|
-
def
|
85
|
-
Google::
|
82
|
+
# @private New GRPC LatLng object.
|
83
|
+
def to_grpc
|
84
|
+
Google::Type::LatLng.new(
|
86
85
|
latitude: latitude,
|
87
86
|
longitude: longitude
|
88
87
|
)
|
89
88
|
end
|
90
89
|
|
91
90
|
##
|
92
|
-
# @private New Location from a
|
93
|
-
def self.
|
94
|
-
new
|
91
|
+
# @private New Location from a GRPC LatLng object.
|
92
|
+
def self.from_grpc grpc
|
93
|
+
new grpc.latitude, grpc.longitude
|
95
94
|
end
|
96
95
|
end
|
97
96
|
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "google/cloud/errors"
|
17
|
-
require "google/cloud/core/
|
17
|
+
require "google/cloud/core/environment"
|
18
18
|
require "google/cloud/vision/service"
|
19
19
|
require "google/cloud/vision/credentials"
|
20
20
|
require "google/cloud/vision/annotate"
|
@@ -27,16 +27,15 @@ module Google
|
|
27
27
|
##
|
28
28
|
# # Project
|
29
29
|
#
|
30
|
-
# Google Cloud Vision allows
|
31
|
-
# within
|
32
|
-
# landmark detection, optical character recognition (OCR), and tagging
|
33
|
-
# explicit content.
|
30
|
+
# Google Cloud Vision allows developers to easily integrate vision
|
31
|
+
# detection features within applications, including image labeling, face
|
32
|
+
# and landmark detection, optical character recognition (OCR), and tagging
|
33
|
+
# of explicit content.
|
34
34
|
#
|
35
35
|
# @example
|
36
|
-
# require "google/cloud"
|
36
|
+
# require "google/cloud/vision"
|
37
37
|
#
|
38
|
-
#
|
39
|
-
# vision = gcloud.vision
|
38
|
+
# vision = Google::Cloud::Vision.new
|
40
39
|
#
|
41
40
|
# image = vision.image "path/to/landmark.jpg"
|
42
41
|
#
|
@@ -61,11 +60,12 @@ module Google
|
|
61
60
|
# The Vision project connected to.
|
62
61
|
#
|
63
62
|
# @example
|
64
|
-
# require "google/cloud"
|
63
|
+
# require "google/cloud/vision"
|
65
64
|
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
65
|
+
# vision = Google::Cloud::Vision.new(
|
66
|
+
# project: "my-todo-project",
|
67
|
+
# keyfile: "/path/to/keyfile.json"
|
68
|
+
# )
|
69
69
|
#
|
70
70
|
# vision.project #=> "my-todo-project"
|
71
71
|
#
|
@@ -79,7 +79,7 @@ module Google
|
|
79
79
|
ENV["VISION_PROJECT"] ||
|
80
80
|
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
81
81
|
ENV["GCLOUD_PROJECT"] ||
|
82
|
-
Google::Cloud::Core::
|
82
|
+
Google::Cloud::Core::Environment.project_id
|
83
83
|
end
|
84
84
|
|
85
85
|
##
|
@@ -89,7 +89,7 @@ module Google
|
|
89
89
|
# combined size of all images in a request. Reducing your file size can
|
90
90
|
# significantly improve throughput; however, be careful not to reduce
|
91
91
|
# image quality in the process. See [Best Practices - Image
|
92
|
-
# Sizing](https://cloud.google.com/vision/docs/
|
92
|
+
# Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
|
93
93
|
# for current file size limits.
|
94
94
|
#
|
95
95
|
# Note that an object in Google Cloud Storage is a single entity;
|
@@ -97,7 +97,7 @@ module Google
|
|
97
97
|
# exist (though default bucket permissions do exist). Make sure the code
|
98
98
|
# which performs your request has access to that image.
|
99
99
|
#
|
100
|
-
# @see https://cloud.google.com/vision/docs/
|
100
|
+
# @see https://cloud.google.com/vision/docs/best-practices Best
|
101
101
|
# Practices
|
102
102
|
#
|
103
103
|
# @param [String, IO, StringIO, Tempfile, Google::Cloud::Storage::File]
|
@@ -109,18 +109,16 @@ module Google
|
|
109
109
|
# @return [Image] An image for the Vision service.
|
110
110
|
#
|
111
111
|
# @example With a Google Cloud Storage URI:
|
112
|
-
# require "google/cloud"
|
112
|
+
# require "google/cloud/vision"
|
113
113
|
#
|
114
|
-
#
|
115
|
-
# vision = gcloud.vision
|
114
|
+
# vision = Google::Cloud::Vision.new
|
116
115
|
#
|
117
116
|
# image = vision.image "gs://bucket-name/path_to_image_object"
|
118
117
|
#
|
119
118
|
# @example With a local file path:
|
120
|
-
# require "google/cloud"
|
119
|
+
# require "google/cloud/vision"
|
121
120
|
#
|
122
|
-
#
|
123
|
-
# vision = gcloud.vision
|
121
|
+
# vision = Google::Cloud::Vision.new
|
124
122
|
#
|
125
123
|
# image = vision.image "path/to/landmark.jpg"
|
126
124
|
#
|
@@ -144,7 +142,7 @@ module Google
|
|
144
142
|
# combined size of all images in a request. Reducing your file size can
|
145
143
|
# significantly improve throughput; however, be careful not to reduce
|
146
144
|
# image quality in the process. See [Best Practices - Image
|
147
|
-
# Sizing](https://cloud.google.com/vision/docs/
|
145
|
+
# Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
|
148
146
|
# for current file size limits.
|
149
147
|
#
|
150
148
|
# @see https://cloud.google.com/vision/docs/requests-and-responses Cloud
|
@@ -189,10 +187,9 @@ module Google
|
|
189
187
|
# multiple images.
|
190
188
|
#
|
191
189
|
# @example With a single image:
|
192
|
-
# require "google/cloud"
|
190
|
+
# require "google/cloud/vision"
|
193
191
|
#
|
194
|
-
#
|
195
|
-
# vision = gcloud.vision
|
192
|
+
# vision = Google::Cloud::Vision.new
|
196
193
|
#
|
197
194
|
# image = vision.image "path/to/landmark.jpg"
|
198
195
|
#
|
@@ -203,10 +200,9 @@ module Google
|
|
203
200
|
# #=> "monument", "landmark"]
|
204
201
|
#
|
205
202
|
# @example With multiple images:
|
206
|
-
# require "google/cloud"
|
203
|
+
# require "google/cloud/vision"
|
207
204
|
#
|
208
|
-
#
|
209
|
-
# vision = gcloud.vision
|
205
|
+
# vision = Google::Cloud::Vision.new
|
210
206
|
#
|
211
207
|
# face_img = vision.image "path/to/face.jpg"
|
212
208
|
# landmark_img = vision.image "path/to/landmark.jpg"
|
@@ -217,10 +213,9 @@ module Google
|
|
217
213
|
# annotations[1].labels.count #=> 6
|
218
214
|
#
|
219
215
|
# @example With multiple images and configurations passed in a block:
|
220
|
-
# require "google/cloud"
|
216
|
+
# require "google/cloud/vision"
|
221
217
|
#
|
222
|
-
#
|
223
|
-
# vision = gcloud.vision
|
218
|
+
# vision = Google::Cloud::Vision.new
|
224
219
|
#
|
225
220
|
# face_img = vision.image "path/to/face.jpg"
|
226
221
|
# landmark_img = vision.image "path/to/landmark.jpg"
|
@@ -238,10 +233,9 @@ module Google
|
|
238
233
|
# annotations[2].text.words.count #=> 28
|
239
234
|
#
|
240
235
|
# @example Maximum result values can also be provided:
|
241
|
-
# require "google/cloud"
|
236
|
+
# require "google/cloud/vision"
|
242
237
|
#
|
243
|
-
#
|
244
|
-
# vision = gcloud.vision
|
238
|
+
# vision = Google::Cloud::Vision.new
|
245
239
|
#
|
246
240
|
# image = vision.image "path/to/landmark.jpg"
|
247
241
|
#
|
@@ -260,10 +254,10 @@ module Google
|
|
260
254
|
|
261
255
|
yield a if block_given?
|
262
256
|
|
263
|
-
|
264
|
-
annotations = Array(
|
257
|
+
grpc = service.annotate a.requests
|
258
|
+
annotations = Array(grpc.responses).map do |g|
|
265
259
|
fail Error.from_error(g.error) if g.error
|
266
|
-
Annotation.
|
260
|
+
Annotation.from_grpc g
|
267
261
|
end
|
268
262
|
return annotations.first if annotations.count == 1
|
269
263
|
annotations
|
@@ -15,7 +15,8 @@
|
|
15
15
|
|
16
16
|
require "google/cloud/errors"
|
17
17
|
require "google/cloud/vision/version"
|
18
|
-
require "google/
|
18
|
+
require "google/cloud/vision/v1"
|
19
|
+
require "google/gax/errors"
|
19
20
|
|
20
21
|
module Google
|
21
22
|
module Cloud
|
@@ -24,39 +25,54 @@ module Google
|
|
24
25
|
# @private
|
25
26
|
# Represents the service to Vision, exposing the API calls.
|
26
27
|
class Service
|
27
|
-
|
28
|
-
# Alias to the Google Client API module
|
29
|
-
API = Google::Apis::VisionV1
|
30
|
-
|
31
|
-
attr_accessor :project
|
32
|
-
attr_accessor :credentials
|
28
|
+
attr_accessor :project, :credentials, :host, :timeout, :client_config
|
33
29
|
|
34
30
|
##
|
35
31
|
# Creates a new Service instance.
|
36
|
-
def initialize project, credentials,
|
32
|
+
def initialize project, credentials, host: nil, timeout: nil,
|
33
|
+
client_config: nil
|
37
34
|
@project = project
|
38
35
|
@credentials = credentials
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
@host = host || V1::ImageAnnotatorApi::SERVICE_ADDRESS
|
37
|
+
@timeout = timeout
|
38
|
+
@client_config = client_config || {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def channel
|
42
|
+
require "grpc"
|
43
|
+
GRPC::Core::Channel.new host, nil, chan_creds
|
44
|
+
end
|
45
|
+
|
46
|
+
def chan_creds
|
47
|
+
return credentials if insecure?
|
48
|
+
require "grpc"
|
49
|
+
GRPC::Core::ChannelCredentials.new.compose \
|
50
|
+
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
47
51
|
end
|
48
52
|
|
49
53
|
def service
|
50
54
|
return mocked_service if mocked_service
|
51
|
-
@service
|
55
|
+
@service ||= \
|
56
|
+
V1::ImageAnnotatorApi.new(
|
57
|
+
service_path: host,
|
58
|
+
channel: channel,
|
59
|
+
timeout: timeout,
|
60
|
+
client_config: client_config,
|
61
|
+
app_name: "gcloud-ruby",
|
62
|
+
app_version: Google::Cloud::Vision::VERSION)
|
52
63
|
end
|
53
64
|
attr_accessor :mocked_service
|
54
65
|
|
66
|
+
def insecure?
|
67
|
+
credentials == :this_channel_is_insecure
|
68
|
+
end
|
69
|
+
|
55
70
|
##
|
56
71
|
# Returns API::BatchAnnotateImagesResponse
|
57
72
|
def annotate requests
|
58
|
-
|
59
|
-
|
73
|
+
execute do
|
74
|
+
service.batch_annotate_images requests, options: default_options
|
75
|
+
end
|
60
76
|
end
|
61
77
|
|
62
78
|
def inspect
|
@@ -65,10 +81,19 @@ module Google
|
|
65
81
|
|
66
82
|
protected
|
67
83
|
|
84
|
+
def default_headers
|
85
|
+
{ "google-cloud-resource-prefix" => "projects/#{@project}" }
|
86
|
+
end
|
87
|
+
|
88
|
+
def default_options
|
89
|
+
Google::Gax::CallOptions.new kwargs: default_headers
|
90
|
+
end
|
91
|
+
|
68
92
|
def execute
|
69
93
|
yield
|
70
|
-
rescue Google::
|
71
|
-
|
94
|
+
rescue Google::Gax::GaxError => e
|
95
|
+
# GaxError wraps BadStatus, but exposes it as #cause
|
96
|
+
raise Google::Cloud::Error.from_error(e.cause)
|
72
97
|
end
|
73
98
|
end
|
74
99
|
end
|
@@ -26,7 +26,7 @@ require "json"
|
|
26
26
|
require "pathname"
|
27
27
|
|
28
28
|
require "google/gax"
|
29
|
-
require "google/cloud/vision/v1/
|
29
|
+
require "google/cloud/vision/v1/image_annotator_pb"
|
30
30
|
|
31
31
|
module Google
|
32
32
|
module Cloud
|
@@ -36,10 +36,10 @@ module Google
|
|
36
36
|
# landmark, logo, label, and text detection, over client images, and returns
|
37
37
|
# detected entities from the images.
|
38
38
|
#
|
39
|
-
# @!attribute [r]
|
39
|
+
# @!attribute [r] image_annotator_stub
|
40
40
|
# @return [Google::Cloud::Vision::V1::ImageAnnotator::Stub]
|
41
41
|
class ImageAnnotatorApi
|
42
|
-
attr_reader :
|
42
|
+
attr_reader :image_annotator_stub
|
43
43
|
|
44
44
|
# The default address of the service.
|
45
45
|
SERVICE_ADDRESS = "vision.googleapis.com".freeze
|
@@ -86,8 +86,15 @@ module Google
|
|
86
86
|
timeout: DEFAULT_TIMEOUT,
|
87
87
|
app_name: "gax",
|
88
88
|
app_version: Google::Gax::VERSION
|
89
|
+
# These require statements are intentionally placed here to initialize
|
90
|
+
# the gRPC module only when it's required.
|
91
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
92
|
+
require "google/gax/grpc"
|
93
|
+
require "google/cloud/vision/v1/image_annotator_services_pb"
|
94
|
+
|
89
95
|
google_api_client = "#{app_name}/#{app_version} " \
|
90
|
-
"#{CODE_GEN_NAME_VERSION}
|
96
|
+
"#{CODE_GEN_NAME_VERSION} gax/#{Google::Gax::VERSION} " \
|
97
|
+
"ruby/#{RUBY_VERSION}".freeze
|
91
98
|
headers = { :"x-goog-api-client" => google_api_client }
|
92
99
|
client_config_file = Pathname.new(__dir__).join(
|
93
100
|
"image_annotator_client_config.json"
|
@@ -103,7 +110,7 @@ module Google
|
|
103
110
|
kwargs: headers
|
104
111
|
)
|
105
112
|
end
|
106
|
-
@
|
113
|
+
@image_annotator_stub = Google::Gax::Grpc.create_stub(
|
107
114
|
service_path,
|
108
115
|
port,
|
109
116
|
chan_creds: chan_creds,
|
@@ -113,7 +120,7 @@ module Google
|
|
113
120
|
)
|
114
121
|
|
115
122
|
@batch_annotate_images = Google::Gax.create_api_call(
|
116
|
-
@
|
123
|
+
@image_annotator_stub.method(:batch_annotate_images),
|
117
124
|
defaults["batch_annotate_images"]
|
118
125
|
)
|
119
126
|
end
|
@@ -129,6 +136,15 @@ module Google
|
|
129
136
|
# retries, etc.
|
130
137
|
# @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse]
|
131
138
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
139
|
+
# @example
|
140
|
+
# require "google/cloud/vision/v1/image_annotator_api"
|
141
|
+
#
|
142
|
+
# ImageAnnotatorApi = Google::Cloud::Vision::V1::ImageAnnotatorApi
|
143
|
+
#
|
144
|
+
# image_annotator_api = ImageAnnotatorApi.new
|
145
|
+
# requests = []
|
146
|
+
# response = image_annotator_api.batch_annotate_images(requests)
|
147
|
+
|
132
148
|
def batch_annotate_images \
|
133
149
|
requests,
|
134
150
|
options: nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-vision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -17,28 +17,70 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.21.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.21.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: grpc
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0
|
34
|
+
version: '1.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: google-gax
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.6.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: google-protobuf
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: googleapis-common-protos
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
35
77
|
type: :runtime
|
36
78
|
prerelease: false
|
37
79
|
version_requirements: !ruby/object:Gem::Requirement
|
38
80
|
requirements:
|
39
81
|
- - "~>"
|
40
82
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
83
|
+
version: '1.3'
|
42
84
|
- !ruby/object:Gem::Dependency
|
43
85
|
name: minitest
|
44
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +193,20 @@ dependencies:
|
|
151
193
|
- - "~>"
|
152
194
|
- !ruby/object:Gem::Version
|
153
195
|
version: '0.9'
|
196
|
+
- !ruby/object:Gem::Dependency
|
197
|
+
name: yard-doctest
|
198
|
+
requirement: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 0.1.6
|
203
|
+
type: :development
|
204
|
+
prerelease: false
|
205
|
+
version_requirements: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - "~>"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: 0.1.6
|
154
210
|
description: google-cloud-vision is the official library for Google Cloud Vision API.
|
155
211
|
email:
|
156
212
|
- mike@blowmage.com
|