gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
@@ -1,108 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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 Gcloud
|
17
|
-
module Vision
|
18
|
-
class Annotation
|
19
|
-
##
|
20
|
-
# # Vertex
|
21
|
-
#
|
22
|
-
# A vertex in a set of bounding polygon vertices.
|
23
|
-
#
|
24
|
-
# See {Face::Bounds} and {Text}.
|
25
|
-
#
|
26
|
-
# @attr_reader [Integer] x The X coordinate.
|
27
|
-
# @attr_reader [Integer] y The Y coordinate.
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# require "gcloud"
|
31
|
-
#
|
32
|
-
# gcloud = Gcloud.new
|
33
|
-
# vision = gcloud.vision
|
34
|
-
#
|
35
|
-
# image = vision.image "path/to/text.png"
|
36
|
-
# text = image.text
|
37
|
-
#
|
38
|
-
# text.bounds.count #=> 4
|
39
|
-
# vertex = text.bounds.first
|
40
|
-
# vertex.x #=> 13
|
41
|
-
# vertex.y #=> 8
|
42
|
-
#
|
43
|
-
class Vertex
|
44
|
-
attr_reader :x, :y
|
45
|
-
|
46
|
-
##
|
47
|
-
# @private Creates a new Vertex instance.
|
48
|
-
def initialize x, y
|
49
|
-
@x = x
|
50
|
-
@y = y
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Returns the object's property values as an array.
|
55
|
-
#
|
56
|
-
# @return [Array]
|
57
|
-
#
|
58
|
-
def to_a
|
59
|
-
to_ary
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# Returns the object's property values as an array.
|
64
|
-
#
|
65
|
-
# @return [Array]
|
66
|
-
#
|
67
|
-
def to_ary
|
68
|
-
[x, y]
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# Converts object to a hash. All keys will be symbolized.
|
73
|
-
#
|
74
|
-
# @return [Hash]
|
75
|
-
#
|
76
|
-
def to_h
|
77
|
-
to_hash
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Converts object to a hash. All keys will be symbolized.
|
82
|
-
#
|
83
|
-
# @return [Hash]
|
84
|
-
#
|
85
|
-
def to_hash
|
86
|
-
{ x: x, y: y }
|
87
|
-
end
|
88
|
-
|
89
|
-
# @private
|
90
|
-
def to_s
|
91
|
-
"(x: #{x.inspect}, y: #{y.inspect})"
|
92
|
-
end
|
93
|
-
|
94
|
-
# @private
|
95
|
-
def inspect
|
96
|
-
"#<Vertex #{self}>"
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
# @private New Annotation::Entity::Bounds::Vertex from a Google API
|
101
|
-
# Client object.
|
102
|
-
def self.from_gapi gapi
|
103
|
-
new gapi.x, gapi.y
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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 "gcloud/credentials"
|
17
|
-
|
18
|
-
module Gcloud
|
19
|
-
module Vision
|
20
|
-
##
|
21
|
-
# @private Represents the OAuth 2.0 signing logic for Vision.
|
22
|
-
class Credentials < Gcloud::Credentials
|
23
|
-
SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
|
24
|
-
PATH_ENV_VARS = %w(VISION_KEYFILE GCLOUD_KEYFILE GOOGLE_CLOUD_KEYFILE)
|
25
|
-
JSON_ENV_VARS = %w(VISION_KEYFILE_JSON GCLOUD_KEYFILE_JSON
|
26
|
-
GOOGLE_CLOUD_KEYFILE_JSON)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/gcloud/vision/image.rb
DELETED
@@ -1,590 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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 "gcloud/vision/location"
|
17
|
-
require "google/apis/vision_v1"
|
18
|
-
require "stringio"
|
19
|
-
require "base64"
|
20
|
-
|
21
|
-
module Gcloud
|
22
|
-
module Vision
|
23
|
-
##
|
24
|
-
# # Image
|
25
|
-
#
|
26
|
-
# Represents an image for the Vision service.
|
27
|
-
#
|
28
|
-
# See {Project#image}.
|
29
|
-
#
|
30
|
-
# The Cloud Vision API supports a variety of image file formats, including
|
31
|
-
# JPEG, PNG8, PNG24, Animated GIF (first frame only), and RAW. See [Best
|
32
|
-
# Practices - Image Types](https://cloud.google.com/vision/docs/image-best-practices#image_types)
|
33
|
-
# for the list of formats. Be aware that Cloud Vision sets upper limits on
|
34
|
-
# file size as well as the total combined size of all images in a request.
|
35
|
-
# Reducing your file size can significantly improve throughput; however, be
|
36
|
-
# careful not to reduce image quality in the process. See [Best Practices -
|
37
|
-
# Image Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
|
38
|
-
# for current file size limits.
|
39
|
-
#
|
40
|
-
# @see https://cloud.google.com/vision/docs/image-best-practices Best
|
41
|
-
# Practices
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# require "gcloud"
|
45
|
-
#
|
46
|
-
# gcloud = Gcloud.new
|
47
|
-
# vision = gcloud.vision
|
48
|
-
#
|
49
|
-
# image = vision.image "path/to/text.png"
|
50
|
-
#
|
51
|
-
# image.context.languages = ["en"]
|
52
|
-
#
|
53
|
-
# text = image.text
|
54
|
-
# text.words.count #=> 28
|
55
|
-
#
|
56
|
-
class Image
|
57
|
-
# Returns the image context for the image, which accepts metadata values
|
58
|
-
# such as location and language hints.
|
59
|
-
# @return [Context] The context instance for the image.
|
60
|
-
attr_reader :context
|
61
|
-
|
62
|
-
##
|
63
|
-
# @private Creates a new Image instance.
|
64
|
-
def initialize
|
65
|
-
@io = nil
|
66
|
-
@url = nil
|
67
|
-
@vision = nil
|
68
|
-
@context = Context.new
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# @private Whether the Image has content.
|
73
|
-
#
|
74
|
-
def io?
|
75
|
-
!@io.nil?
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# @private Whether the Image is a URL.
|
80
|
-
#
|
81
|
-
def url?
|
82
|
-
!@url.nil?
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# @private The URL of the image.
|
87
|
-
#
|
88
|
-
# @return [String]
|
89
|
-
#
|
90
|
-
def url
|
91
|
-
@url
|
92
|
-
end
|
93
|
-
|
94
|
-
##
|
95
|
-
# Performs the `FACE_DETECTION` feature on the image.
|
96
|
-
#
|
97
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
98
|
-
#
|
99
|
-
# @param [Integer] max_results The maximum number of results. The default
|
100
|
-
# is {Gcloud::Vision.default_max_faces}. Optional.
|
101
|
-
#
|
102
|
-
# @return [Array<Annotation::Face>] The results of face detection.
|
103
|
-
#
|
104
|
-
# @example
|
105
|
-
# require "gcloud"
|
106
|
-
#
|
107
|
-
# gcloud = Gcloud.new
|
108
|
-
# vision = gcloud.vision
|
109
|
-
# image = vision.image "path/to/face.jpg"
|
110
|
-
#
|
111
|
-
# faces = image.faces
|
112
|
-
#
|
113
|
-
# face = faces.first
|
114
|
-
# face.bounds.face.count #=> 4
|
115
|
-
# face.bounds.face.first #=> #<Vertex (x: 153, y: 34)>
|
116
|
-
#
|
117
|
-
def faces max_results = Gcloud::Vision.default_max_faces
|
118
|
-
ensure_vision!
|
119
|
-
annotation = @vision.mark self, faces: max_results
|
120
|
-
annotation.faces
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
# Performs the `FACE_DETECTION` feature on the image and returns only the
|
125
|
-
# first result.
|
126
|
-
#
|
127
|
-
# @return [Annotation::Face] The first result of face detection.
|
128
|
-
#
|
129
|
-
def face
|
130
|
-
faces(1).first
|
131
|
-
end
|
132
|
-
|
133
|
-
##
|
134
|
-
# Performs the `LANDMARK_DETECTION` feature on the image.
|
135
|
-
#
|
136
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
137
|
-
#
|
138
|
-
# @param [Integer] max_results The maximum number of results. The default
|
139
|
-
# is {Gcloud::Vision.default_max_landmarks}. Optional.
|
140
|
-
#
|
141
|
-
# @return [Array<Annotation::Entity>] The results of landmark detection.
|
142
|
-
#
|
143
|
-
# @example
|
144
|
-
# require "gcloud"
|
145
|
-
#
|
146
|
-
# gcloud = Gcloud.new
|
147
|
-
# vision = gcloud.vision
|
148
|
-
# image = vision.image "path/to/landmark.jpg"
|
149
|
-
#
|
150
|
-
# landmarks = image.landmarks
|
151
|
-
#
|
152
|
-
# landmark = landmarks.first
|
153
|
-
# landmark.score #=> 0.91912264
|
154
|
-
# landmark.description #=> "Mount Rushmore"
|
155
|
-
# landmark.mid #=> "/m/019dvv"
|
156
|
-
#
|
157
|
-
def landmarks max_results = Gcloud::Vision.default_max_landmarks
|
158
|
-
ensure_vision!
|
159
|
-
annotation = @vision.mark self, landmarks: max_results
|
160
|
-
annotation.landmarks
|
161
|
-
end
|
162
|
-
|
163
|
-
##
|
164
|
-
# Performs the `LANDMARK_DETECTION` feature on the image and returns only
|
165
|
-
# the first result.
|
166
|
-
#
|
167
|
-
# @return [Annotation::Entity] The first result of landmark detection.
|
168
|
-
#
|
169
|
-
def landmark
|
170
|
-
landmarks(1).first
|
171
|
-
end
|
172
|
-
|
173
|
-
##
|
174
|
-
# Performs the `LOGO_DETECTION` feature on the image.
|
175
|
-
#
|
176
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
177
|
-
#
|
178
|
-
# @param [Integer] max_results The maximum number of results. The default
|
179
|
-
# is {Gcloud::Vision.default_max_logos}. Optional.
|
180
|
-
#
|
181
|
-
# @return [Array<Annotation::Entity>] The results of logo detection.
|
182
|
-
#
|
183
|
-
# @example
|
184
|
-
# require "gcloud"
|
185
|
-
#
|
186
|
-
# gcloud = Gcloud.new
|
187
|
-
# vision = gcloud.vision
|
188
|
-
# image = vision.image "path/to/logo.jpg"
|
189
|
-
#
|
190
|
-
# logos = image.logos
|
191
|
-
#
|
192
|
-
# logo = logos.first
|
193
|
-
# logo.score #=> 0.70057315
|
194
|
-
# logo.description #=> "Google"
|
195
|
-
# logo.mid #=> "/m/0b34hf"
|
196
|
-
#
|
197
|
-
def logos max_results = Gcloud::Vision.default_max_logos
|
198
|
-
ensure_vision!
|
199
|
-
annotation = @vision.mark self, logos: max_results
|
200
|
-
annotation.logos
|
201
|
-
end
|
202
|
-
|
203
|
-
##
|
204
|
-
# Performs the `LOGO_DETECTION` feature on the image and returns only the
|
205
|
-
# first result.
|
206
|
-
#
|
207
|
-
# @return [Annotation::Entity] The first result of logo detection.
|
208
|
-
#
|
209
|
-
def logo
|
210
|
-
logos(1).first
|
211
|
-
end
|
212
|
-
|
213
|
-
##
|
214
|
-
# Performs the `LABEL_DETECTION` feature on the image.
|
215
|
-
#
|
216
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
217
|
-
#
|
218
|
-
# @param [Integer] max_results The maximum number of results. The default
|
219
|
-
# is {Gcloud::Vision.default_max_labels}. Optional.
|
220
|
-
#
|
221
|
-
# @return [Array<Annotation::Entity>] The results of label detection.
|
222
|
-
#
|
223
|
-
# @example
|
224
|
-
# require "gcloud"
|
225
|
-
#
|
226
|
-
# gcloud = Gcloud.new
|
227
|
-
# vision = gcloud.vision
|
228
|
-
# image = vision.image "path/to/face.jpg"
|
229
|
-
#
|
230
|
-
# labels = image.labels
|
231
|
-
#
|
232
|
-
# labels.count #=> 4
|
233
|
-
# label = labels.first
|
234
|
-
# label.score #=> 0.9481349
|
235
|
-
# label.description #=> "person"
|
236
|
-
# label.mid #=> "/m/01g317"
|
237
|
-
#
|
238
|
-
def labels max_results = Gcloud::Vision.default_max_labels
|
239
|
-
ensure_vision!
|
240
|
-
annotation = @vision.mark self, labels: max_results
|
241
|
-
annotation.labels
|
242
|
-
end
|
243
|
-
|
244
|
-
##
|
245
|
-
# Performs the `LABEL_DETECTION` feature on the image and returns only the
|
246
|
-
# first result.
|
247
|
-
#
|
248
|
-
# @return [Annotation::Entity] The first result of label detection.
|
249
|
-
#
|
250
|
-
def label
|
251
|
-
labels(1).first
|
252
|
-
end
|
253
|
-
|
254
|
-
##
|
255
|
-
# Performs the `TEXT_DETECTION` (OCR) feature on the image.
|
256
|
-
#
|
257
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
258
|
-
#
|
259
|
-
# @return [Annotation::Text] The results of text (OCR) detection.
|
260
|
-
#
|
261
|
-
# @example
|
262
|
-
# require "gcloud"
|
263
|
-
#
|
264
|
-
# gcloud = Gcloud.new
|
265
|
-
# vision = gcloud.vision
|
266
|
-
# image = vision.image "path/to/text.png"
|
267
|
-
#
|
268
|
-
# text = image.text
|
269
|
-
#
|
270
|
-
# text = image.text
|
271
|
-
# text.locale #=> "en"
|
272
|
-
# text.words.count #=> 28
|
273
|
-
# text.text
|
274
|
-
# #=> "Google Cloud Client Library for Ruby an idiomatic, intuitive... "
|
275
|
-
#
|
276
|
-
def text
|
277
|
-
ensure_vision!
|
278
|
-
annotation = @vision.mark self, text: true
|
279
|
-
annotation.text
|
280
|
-
end
|
281
|
-
|
282
|
-
##
|
283
|
-
# Performs the `SAFE_SEARCH_DETECTION` feature on the image.
|
284
|
-
#
|
285
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
286
|
-
#
|
287
|
-
# @return [Annotation::SafeSearch] The results of safe search detection.
|
288
|
-
#
|
289
|
-
# @example
|
290
|
-
# require "gcloud"
|
291
|
-
#
|
292
|
-
# gcloud = Gcloud.new
|
293
|
-
# vision = gcloud.vision
|
294
|
-
# image = vision.image "path/to/face.jpg"
|
295
|
-
#
|
296
|
-
# safe_search = image.safe_search
|
297
|
-
#
|
298
|
-
# safe_search.spoof? #=> false
|
299
|
-
# safe_search.spoof #=> "VERY_UNLIKELY"
|
300
|
-
#
|
301
|
-
def safe_search
|
302
|
-
ensure_vision!
|
303
|
-
annotation = @vision.mark self, safe_search: true
|
304
|
-
annotation.safe_search
|
305
|
-
end
|
306
|
-
|
307
|
-
##
|
308
|
-
# Performs the `IMAGE_PROPERTIES` feature on the image.
|
309
|
-
#
|
310
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
311
|
-
#
|
312
|
-
# @return [Annotation::Properties] The results of image properties
|
313
|
-
# detection.
|
314
|
-
#
|
315
|
-
# @example
|
316
|
-
# require "gcloud"
|
317
|
-
#
|
318
|
-
# gcloud = Gcloud.new
|
319
|
-
# vision = gcloud.vision
|
320
|
-
# image = vision.image "path/to/logo.jpg"
|
321
|
-
#
|
322
|
-
# properties = image.properties
|
323
|
-
#
|
324
|
-
# properties.colors.count #=> 10
|
325
|
-
# color = properties.colors.first
|
326
|
-
# color.red #=> 247.0
|
327
|
-
# color.green #=> 236.0
|
328
|
-
# color.blue #=> 20.0
|
329
|
-
#
|
330
|
-
def properties
|
331
|
-
ensure_vision!
|
332
|
-
annotation = @vision.mark self, properties: true
|
333
|
-
annotation.properties
|
334
|
-
end
|
335
|
-
|
336
|
-
# @private
|
337
|
-
def to_s
|
338
|
-
@to_s ||= begin
|
339
|
-
if io?
|
340
|
-
@io.rewind
|
341
|
-
"(#{@io.read(16)}...)"
|
342
|
-
else
|
343
|
-
"(#{url})"
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
# @private
|
349
|
-
def inspect
|
350
|
-
"#<#{self.class.name} #{self}>"
|
351
|
-
end
|
352
|
-
|
353
|
-
##
|
354
|
-
# @private The Google API Client object for the Image.
|
355
|
-
def to_gapi
|
356
|
-
if io?
|
357
|
-
@io.rewind
|
358
|
-
Google::Apis::VisionV1::Image.new content: @io.read
|
359
|
-
elsif url?
|
360
|
-
Google::Apis::VisionV1::Image.new source: { gcsImageUri: @url }
|
361
|
-
else
|
362
|
-
fail ArgumentError, "Unable to use Image with Vision service."
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
##
|
367
|
-
# @private New Image from a source object.
|
368
|
-
def self.from_source source, vision = nil
|
369
|
-
if source.respond_to?(:read) && source.respond_to?(:rewind)
|
370
|
-
return from_io(source, vision)
|
371
|
-
end
|
372
|
-
# Convert Storage::File objects to the URL
|
373
|
-
source = source.to_gs_url if source.respond_to? :to_gs_url
|
374
|
-
# Everything should be a string from now on
|
375
|
-
source = String source
|
376
|
-
# Create an Image from the Google Storage URL
|
377
|
-
return from_url(source, vision) if source.start_with? "gs://"
|
378
|
-
# Create an image from a file on the filesystem
|
379
|
-
if File.file? source
|
380
|
-
unless File.readable? source
|
381
|
-
fail ArgumentError, "Cannot read #{source}"
|
382
|
-
end
|
383
|
-
return from_io(File.open(source, "rb"), vision)
|
384
|
-
end
|
385
|
-
fail ArgumentError, "Unable to convert #{source} to an Image"
|
386
|
-
end
|
387
|
-
|
388
|
-
##
|
389
|
-
# @private New Image from an IO object.
|
390
|
-
def self.from_io io, vision
|
391
|
-
if !io.respond_to?(:read) && !io.respond_to?(:rewind)
|
392
|
-
fail ArgumentError, "Cannot create an Image without an IO object"
|
393
|
-
end
|
394
|
-
new.tap do |i|
|
395
|
-
i.instance_variable_set :@io, io
|
396
|
-
i.instance_variable_set :@vision, vision
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
##
|
401
|
-
# @private New Image from an IO object.
|
402
|
-
def self.from_url url, vision
|
403
|
-
url = String url
|
404
|
-
unless url.start_with? "gs://"
|
405
|
-
fail ArgumentError, "Cannot create an Image without a Storage URL"
|
406
|
-
end
|
407
|
-
new.tap do |i|
|
408
|
-
i.instance_variable_set :@url, url
|
409
|
-
i.instance_variable_set :@vision, vision
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
protected
|
414
|
-
|
415
|
-
##
|
416
|
-
# Raise an error unless an active vision project object is available.
|
417
|
-
def ensure_vision!
|
418
|
-
fail "Must have active connection" unless @vision
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
class Image
|
423
|
-
##
|
424
|
-
# # Image::Context
|
425
|
-
#
|
426
|
-
# Represents an image context.
|
427
|
-
#
|
428
|
-
# @attr [Array<String>] languages A list of [ISO 639-1 language
|
429
|
-
# codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
430
|
-
# to use for text (OCR) detection. In most cases, an empty value
|
431
|
-
# will yield the best results as it will allow text detection to
|
432
|
-
# automatically detect the text language. For languages based on the
|
433
|
-
# latin alphabet a hint is not needed. In rare cases, when the
|
434
|
-
# language of the text in the image is known in advance, setting
|
435
|
-
# this hint will help get better results (although it will hurt a
|
436
|
-
# great deal if the hint is wrong).
|
437
|
-
#
|
438
|
-
# @example
|
439
|
-
# require "gcloud"
|
440
|
-
#
|
441
|
-
# gcloud = Gcloud.new
|
442
|
-
# vision = gcloud.vision
|
443
|
-
#
|
444
|
-
# image = vision.image "path/to/landmark.jpg"
|
445
|
-
# image.context.area.min = { longitude: -122.0862462,
|
446
|
-
# latitude: 37.4220041 }
|
447
|
-
# image.context.area.max = { longitude: -122.0762462,
|
448
|
-
# latitude: 37.4320041 }
|
449
|
-
#
|
450
|
-
class Context
|
451
|
-
# Returns a lat/long rectangle that specifies the location of the image.
|
452
|
-
# @return [Area] The lat/long pairs for `latLongRect`.
|
453
|
-
attr_reader :area
|
454
|
-
|
455
|
-
attr_accessor :languages
|
456
|
-
|
457
|
-
##
|
458
|
-
# @private Creates a new Context instance.
|
459
|
-
def initialize
|
460
|
-
@area = Area.new
|
461
|
-
@languages = []
|
462
|
-
end
|
463
|
-
|
464
|
-
##
|
465
|
-
# Returns `true` if either `min` or `max` are not populated.
|
466
|
-
#
|
467
|
-
# @return [Boolean]
|
468
|
-
#
|
469
|
-
def empty?
|
470
|
-
area.empty? && languages.empty?
|
471
|
-
end
|
472
|
-
|
473
|
-
##
|
474
|
-
# @private
|
475
|
-
def to_gapi
|
476
|
-
return nil if empty?
|
477
|
-
gapi = Google::Apis::VisionV1::ImageContext.new
|
478
|
-
gapi.lat_long_rect = area.to_gapi unless area.empty?
|
479
|
-
gapi.language_hints = languages unless languages.empty?
|
480
|
-
gapi
|
481
|
-
end
|
482
|
-
|
483
|
-
##
|
484
|
-
# # Image::Context::Area
|
485
|
-
#
|
486
|
-
# A Lat/long rectangle that specifies the location of the image.
|
487
|
-
#
|
488
|
-
# @example
|
489
|
-
# require "gcloud"
|
490
|
-
#
|
491
|
-
# gcloud = Gcloud.new
|
492
|
-
# vision = gcloud.vision
|
493
|
-
#
|
494
|
-
# image = vision.image "path/to/landmark.jpg"
|
495
|
-
#
|
496
|
-
# image.context.area.min = { longitude: -122.0862462,
|
497
|
-
# latitude: 37.4220041 }
|
498
|
-
# image.context.area.max = { longitude: -122.0762462,
|
499
|
-
# latitude: 37.4320041 }
|
500
|
-
#
|
501
|
-
# entity = image.landmark
|
502
|
-
#
|
503
|
-
class Area
|
504
|
-
# Returns the min lat/long pair.
|
505
|
-
# @return [Location]
|
506
|
-
attr_reader :min
|
507
|
-
|
508
|
-
# Returns the max lat/long pair.
|
509
|
-
# @return [Location]
|
510
|
-
attr_reader :max
|
511
|
-
|
512
|
-
##
|
513
|
-
# @private Creates a new Area instance.
|
514
|
-
def initialize
|
515
|
-
@min = Location.new nil, nil
|
516
|
-
@max = Location.new nil, nil
|
517
|
-
end
|
518
|
-
|
519
|
-
##
|
520
|
-
# Sets the min lat/long pair for the area.
|
521
|
-
#
|
522
|
-
# @param [Hash(Symbol => Float)] location A Hash containing the keys
|
523
|
-
# `:latitude` and `:longitude` with corresponding values conforming
|
524
|
-
# to the [WGS84
|
525
|
-
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
526
|
-
def min= location
|
527
|
-
if location.respond_to?(:to_hash) &&
|
528
|
-
location.to_hash.keys.sort == [:latitude, :longitude]
|
529
|
-
return @min = Location.new(location.to_hash[:latitude],
|
530
|
-
location.to_hash[:longitude])
|
531
|
-
end
|
532
|
-
fail ArgumentError, "Must pass a proper location value."
|
533
|
-
end
|
534
|
-
|
535
|
-
##
|
536
|
-
# Sets the max lat/long pair for the area.
|
537
|
-
#
|
538
|
-
# @param [Hash(Symbol => Float)] location A Hash containing the keys
|
539
|
-
# `:latitude` and `:longitude` with corresponding values conforming
|
540
|
-
# to the [WGS84
|
541
|
-
# standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
|
542
|
-
def max= location
|
543
|
-
if location.respond_to?(:to_hash) &&
|
544
|
-
location.to_hash.keys.sort == [:latitude, :longitude]
|
545
|
-
return @max = Location.new(location.to_hash[:latitude],
|
546
|
-
location.to_hash[:longitude])
|
547
|
-
end
|
548
|
-
fail ArgumentError, "Must pass a proper location value."
|
549
|
-
end
|
550
|
-
|
551
|
-
##
|
552
|
-
# Returns `true` if either `min` or `max` are not populated.
|
553
|
-
#
|
554
|
-
# @return [Boolean]
|
555
|
-
#
|
556
|
-
def empty?
|
557
|
-
min.to_hash.values.reject(&:nil?).empty? ||
|
558
|
-
max.to_hash.values.reject(&:nil?).empty?
|
559
|
-
end
|
560
|
-
|
561
|
-
##
|
562
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
563
|
-
#
|
564
|
-
# @return [Hash]
|
565
|
-
#
|
566
|
-
def to_h
|
567
|
-
to_hash
|
568
|
-
end
|
569
|
-
|
570
|
-
##
|
571
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
572
|
-
#
|
573
|
-
# @return [Hash]
|
574
|
-
#
|
575
|
-
def to_hash
|
576
|
-
{ min_lat_lng: min.to_hash, max_lat_lng: max.to_hash }
|
577
|
-
end
|
578
|
-
|
579
|
-
def to_gapi
|
580
|
-
return nil if empty?
|
581
|
-
Google::Apis::VisionV1::LatLongRect.new(
|
582
|
-
min_lat_lng: min.to_gapi,
|
583
|
-
max_lat_lng: max.to_gapi
|
584
|
-
)
|
585
|
-
end
|
586
|
-
end
|
587
|
-
end
|
588
|
-
end
|
589
|
-
end
|
590
|
-
end
|