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
data/TROUBLESHOOTING.md
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Troubleshooting
|
2
|
-
|
3
|
-
## Where can I get more help?
|
4
|
-
|
5
|
-
### Ask the Community
|
6
|
-
|
7
|
-
If you have a question about how to use a Google Cloud client library in your
|
8
|
-
project or are stuck in the Developer's console and don't know where to turn,
|
9
|
-
it's possible your questions have already been addressed by the community.
|
10
|
-
|
11
|
-
First, check out the appropriate tags on StackOverflow:
|
12
|
-
- [`google-cloud-platform+ruby+vision`][so-ruby]
|
13
|
-
|
14
|
-
Next, try searching through the issues on GitHub:
|
15
|
-
|
16
|
-
- [`api:vision` issues][gh-search-ruby]
|
17
|
-
|
18
|
-
Still nothing?
|
19
|
-
|
20
|
-
### Ask the Developers
|
21
|
-
|
22
|
-
If you're experiencing a bug with the code, or have an idea for how it can be
|
23
|
-
improved, *please* create a new issue on GitHub so we can talk about it.
|
24
|
-
|
25
|
-
- [New issue][gh-ruby]
|
26
|
-
|
27
|
-
Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
|
28
|
-
can use the "ruby" channel for general Ruby questions, or use the
|
29
|
-
"google-cloud-ruby" channel if you have questions about this gem in particular.
|
30
|
-
|
31
|
-
[so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+vision
|
32
|
-
|
33
|
-
[gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+vision%22
|
34
|
-
|
35
|
-
[gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
|
36
|
-
|
37
|
-
[slack-ruby]: https://gcp-slack.appspot.com/
|
data/lib/google-cloud-vision.rb
DELETED
@@ -1,146 +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
|
-
##
|
17
|
-
# This file is here to be autorequired by bundler, so that the
|
18
|
-
# Google::Cloud.vision and Google::Cloud#vision methods can be available, but
|
19
|
-
# the library and all dependencies won't be loaded until required and used.
|
20
|
-
|
21
|
-
|
22
|
-
gem "google-cloud-core"
|
23
|
-
require "google/cloud" unless defined? Google::Cloud.new
|
24
|
-
require "google/cloud/config"
|
25
|
-
require "googleauth"
|
26
|
-
|
27
|
-
module Google
|
28
|
-
module Cloud
|
29
|
-
##
|
30
|
-
# Creates a new object for connecting to the Vision service.
|
31
|
-
# Each call creates a new connection.
|
32
|
-
#
|
33
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
34
|
-
# set of resources and operations that the connection can access. See
|
35
|
-
# [Using OAuth 2.0 to Access Google
|
36
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
37
|
-
#
|
38
|
-
# The default scope is:
|
39
|
-
#
|
40
|
-
# * `https://www.googleapis.com/auth/cloud-platform`
|
41
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
42
|
-
# @param [Hash] client_config A hash of values to override the default
|
43
|
-
# behavior of the API client. Optional.
|
44
|
-
#
|
45
|
-
# @return [Google::Cloud::Vision::Project]
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# require "google/cloud"
|
49
|
-
#
|
50
|
-
# gcloud = Google::Cloud.new
|
51
|
-
# vision = gcloud.vision
|
52
|
-
#
|
53
|
-
# image = vision.image "path/to/landmark.jpg"
|
54
|
-
#
|
55
|
-
# landmark = image.landmark
|
56
|
-
# landmark.description #=> "Mount Rushmore"
|
57
|
-
#
|
58
|
-
# @example The default scope can be overridden with the `scope` option:
|
59
|
-
# require "google/cloud"
|
60
|
-
#
|
61
|
-
# gcloud = Google::Cloud.new
|
62
|
-
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
63
|
-
# vision = gcloud.vision scope: platform_scope
|
64
|
-
#
|
65
|
-
def vision scope: nil, timeout: nil, client_config: nil
|
66
|
-
Google::Cloud.vision @project, @keyfile, scope: scope,
|
67
|
-
timeout: (timeout || @timeout),
|
68
|
-
client_config: client_config
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# Creates a new object for connecting to the Vision service.
|
73
|
-
# Each call creates a new connection.
|
74
|
-
#
|
75
|
-
# @param [String] project_id Project identifier for the Vision service you
|
76
|
-
# are connecting to. If not present, the default project for the
|
77
|
-
# credentials is used.
|
78
|
-
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
79
|
-
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
80
|
-
# Google::Auth::Credentials object. (See {Vision::Credentials})
|
81
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
82
|
-
# set of resources and operations that the connection can access. See
|
83
|
-
# [Using OAuth 2.0 to Access Google
|
84
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
85
|
-
#
|
86
|
-
# The default scope is:
|
87
|
-
#
|
88
|
-
# * `https://www.googleapis.com/auth/cloud-platform`
|
89
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
90
|
-
# @param [Hash] client_config A hash of values to override the default
|
91
|
-
# behavior of the API client. Optional.
|
92
|
-
#
|
93
|
-
# @return [Google::Cloud::Vision::Project]
|
94
|
-
#
|
95
|
-
# @example
|
96
|
-
# require "google/cloud"
|
97
|
-
#
|
98
|
-
# vision = Google::Cloud.vision
|
99
|
-
#
|
100
|
-
# image = vision.image "path/to/landmark.jpg"
|
101
|
-
#
|
102
|
-
# landmark = image.landmark
|
103
|
-
# landmark.description #=> "Mount Rushmore"
|
104
|
-
#
|
105
|
-
def self.vision project_id = nil, credentials = nil, scope: nil,
|
106
|
-
timeout: nil, client_config: nil
|
107
|
-
require "google/cloud/vision"
|
108
|
-
Google::Cloud::Vision.new project_id: project_id,
|
109
|
-
credentials: credentials,
|
110
|
-
scope: scope, timeout: timeout,
|
111
|
-
client_config: client_config
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Set the default vision configuration
|
117
|
-
Google::Cloud.configure.add_config! :vision do |config|
|
118
|
-
default_project = Google::Cloud::Config.deferred do
|
119
|
-
ENV["VISION_PROJECT"]
|
120
|
-
end
|
121
|
-
default_creds = Google::Cloud::Config.deferred do
|
122
|
-
Google::Cloud::Config.credentials_from_env(
|
123
|
-
"VISION_CREDENTIALS", "VISION_CREDENTIALS_JSON",
|
124
|
-
"VISION_KEYFILE", "VISION_KEYFILE_JSON"
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
129
|
-
config.add_alias! :project, :project_id
|
130
|
-
config.add_field! :credentials, default_creds,
|
131
|
-
match: [String, Hash, Google::Auth::Credentials],
|
132
|
-
allow_nil: true
|
133
|
-
config.add_alias! :keyfile, :credentials
|
134
|
-
config.add_field! :scope, nil, match: [String, Array]
|
135
|
-
config.add_field! :timeout, nil, match: Integer
|
136
|
-
config.add_field! :client_config, nil, match: Hash
|
137
|
-
# Update the documentation on the Vision module methods when these
|
138
|
-
# defaults change.
|
139
|
-
config.add_field! :default_max_faces, 100
|
140
|
-
config.add_field! :default_max_landmarks, 100
|
141
|
-
config.add_field! :default_max_logos, 100
|
142
|
-
config.add_field! :default_max_labels, 100
|
143
|
-
config.add_field! :default_max_crop_hints, 100
|
144
|
-
config.add_field! :default_max_web, 100
|
145
|
-
config.add_field! :default_max_object_localizations, 100
|
146
|
-
end
|
@@ -1,303 +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/vision/image"
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Cloud
|
20
|
-
module Vision
|
21
|
-
##
|
22
|
-
# # Annotate
|
23
|
-
#
|
24
|
-
# Accumulates configuration for an image annotation request. Users
|
25
|
-
# describe the type of Google Cloud Vision API tasks to perform over
|
26
|
-
# images by configuring features such as `faces`, `landmarks`, `text`,
|
27
|
-
# etc. This configuration captures the Cloud Vision API vertical to
|
28
|
-
# operate on and the number of top-scoring results to return.
|
29
|
-
#
|
30
|
-
# See {Project#annotate}.
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# require "google/cloud/vision"
|
34
|
-
#
|
35
|
-
# vision = Google::Cloud::Vision.new
|
36
|
-
#
|
37
|
-
# face_image = vision.image "path/to/face.jpg"
|
38
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
39
|
-
#
|
40
|
-
# annotations = vision.annotate do |annotate|
|
41
|
-
# annotate.annotate face_image, faces: true, labels: true
|
42
|
-
# annotate.annotate landmark_image, landmarks: true
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# annotations[0].faces.count #=> 1
|
46
|
-
# annotations[0].labels.count #=> 4
|
47
|
-
# annotations[1].landmarks.count #=> 1
|
48
|
-
#
|
49
|
-
class Annotate
|
50
|
-
# @private
|
51
|
-
attr_accessor :requests
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Creates a new Annotate instance.
|
55
|
-
def initialize project
|
56
|
-
@project = project
|
57
|
-
@requests = []
|
58
|
-
end
|
59
|
-
|
60
|
-
##
|
61
|
-
# Performs detection of Cloud Vision
|
62
|
-
# [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#Feature)
|
63
|
-
# on the given images. If no options for features are provided, **all**
|
64
|
-
# image detection features will be performed, with a default of `100`
|
65
|
-
# results for faces, landmarks, logos, and labels. If any feature option
|
66
|
-
# is provided, only the specified feature detections will be performed.
|
67
|
-
# Please review [Pricing](https://cloud.google.com/vision/docs/pricing)
|
68
|
-
# before use, as a separate charge is incurred for each feature
|
69
|
-
# performed on an image.
|
70
|
-
#
|
71
|
-
# Cloud Vision sets upper limits on file size as well as on the total
|
72
|
-
# combined size of all images in a request. Reducing your file size can
|
73
|
-
# significantly improve throughput; however, be careful not to reduce
|
74
|
-
# image quality in the process. See [Best Practices - Image
|
75
|
-
# Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
|
76
|
-
# for current file size limits.
|
77
|
-
#
|
78
|
-
# See {Project#annotate} for requests that do not involve multiple
|
79
|
-
# feature configurations.
|
80
|
-
#
|
81
|
-
# @see https://cloud.google.com/vision/docs/requests-and-responses Cloud
|
82
|
-
# Vision API Requests and Responses
|
83
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#AnnotateImageRequest
|
84
|
-
# AnnotateImageRequest
|
85
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
86
|
-
#
|
87
|
-
# @param [Image, Object] images The image or images to annotate. This
|
88
|
-
# can be an {Image} instance, or any other type that converts to an
|
89
|
-
# {Image}. See {#image} for details.
|
90
|
-
# @param [Boolean, Integer] faces Whether to perform the facial
|
91
|
-
# detection feature. The maximum number of results is configured in
|
92
|
-
# {Google::Cloud::Vision.default_max_faces}, or may be provided here.
|
93
|
-
# Optional.
|
94
|
-
# @param [Boolean, Integer] landmarks Whether to perform the landmark
|
95
|
-
# detection feature. The maximum number of results is configured in
|
96
|
-
# {Google::Cloud::Vision.default_max_landmarks}, or may be provided
|
97
|
-
# here. Optional.
|
98
|
-
# @param [Boolean, Integer] logos Whether to perform the logo detection
|
99
|
-
# feature. The maximum number of results is configured in
|
100
|
-
# {Google::Cloud::Vision.default_max_logos}, or may be provided here.
|
101
|
-
# Optional.
|
102
|
-
# @param [Boolean, Integer] labels Whether to perform the label
|
103
|
-
# detection feature. The maximum number of results is configured in
|
104
|
-
# {Google::Cloud::Vision.default_max_labels}, or may be provided here.
|
105
|
-
# Optional.
|
106
|
-
# @param [Boolean] text Whether to perform the text detection feature
|
107
|
-
# (OCR for shorter documents with sparse text). Optional.
|
108
|
-
# @param [Boolean] document Whether to perform the document text
|
109
|
-
# detection feature (OCR for longer documents with dense text).
|
110
|
-
# Optional.
|
111
|
-
# @param [Boolean] safe_search Whether to perform the safe search
|
112
|
-
# feature. Optional.
|
113
|
-
# @param [Boolean] properties Whether to perform the image properties
|
114
|
-
# feature (currently, the image's dominant colors.) Optional.
|
115
|
-
# @param [Boolean, Integer] crop_hints Whether to perform the crop hints
|
116
|
-
# feature. Optional.
|
117
|
-
# @param [Boolean, Integer] web Whether to perform the web annotation
|
118
|
-
# feature. Optional.
|
119
|
-
# @param [Boolean, Integer] object_localizations TODO! Optional.
|
120
|
-
#
|
121
|
-
# @return [Annotation, Array<Annotation>] The results for all image
|
122
|
-
# detections, returned as a single {Annotation} instance for one
|
123
|
-
# image, or as an array of {Annotation} instances, one per image, for
|
124
|
-
# multiple images.
|
125
|
-
#
|
126
|
-
# @example
|
127
|
-
# require "google/cloud/vision"
|
128
|
-
#
|
129
|
-
# vision = Google::Cloud::Vision.new
|
130
|
-
#
|
131
|
-
# face_image = vision.image "path/to/face.jpg"
|
132
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
133
|
-
# text_image = vision.image "path/to/text.png"
|
134
|
-
#
|
135
|
-
# annotations = vision.annotate do |annotate|
|
136
|
-
# annotate.annotate face_image, faces: true, labels: true
|
137
|
-
# annotate.annotate landmark_image, landmarks: true
|
138
|
-
# annotate.annotate text_image, text: true
|
139
|
-
# end
|
140
|
-
#
|
141
|
-
# annotations[0].faces.count #=> 1
|
142
|
-
# annotations[0].labels.count #=> 4
|
143
|
-
# annotations[1].landmarks.count #=> 1
|
144
|
-
# annotations[2].text.pages.count #=> 1
|
145
|
-
#
|
146
|
-
def annotate *images, faces: false, landmarks: false, logos: false,
|
147
|
-
labels: false, text: false, document: false,
|
148
|
-
safe_search: false, properties: false, crop_hints: false,
|
149
|
-
web: false, object_localizations: false
|
150
|
-
add_requests(images, faces, landmarks, logos, labels, text, document,
|
151
|
-
safe_search, properties, crop_hints, web,
|
152
|
-
object_localizations)
|
153
|
-
end
|
154
|
-
|
155
|
-
protected
|
156
|
-
|
157
|
-
def image source
|
158
|
-
return source if source.is_a? Image
|
159
|
-
Image.from_source source, @project
|
160
|
-
end
|
161
|
-
|
162
|
-
def add_requests images, faces, landmarks, logos, labels, text,
|
163
|
-
document, safe_search, properties, crop_hints, web,
|
164
|
-
object_localizations
|
165
|
-
features = annotate_features(faces, landmarks, logos, labels, text,
|
166
|
-
document, safe_search, properties,
|
167
|
-
crop_hints, web, object_localizations)
|
168
|
-
|
169
|
-
Array(images).flatten.each do |img|
|
170
|
-
i = image(img)
|
171
|
-
@requests << Google::Cloud::Vision::V1::AnnotateImageRequest.new(
|
172
|
-
image: i.to_grpc,
|
173
|
-
features: features,
|
174
|
-
image_context: i.context.to_grpc
|
175
|
-
)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def annotate_features faces, landmarks, logos, labels, text, document,
|
180
|
-
safe_search, properties, crop_hints, web,
|
181
|
-
object_localizations
|
182
|
-
return default_features if default_features?(
|
183
|
-
faces, landmarks, logos, labels, text, document, safe_search,
|
184
|
-
properties, crop_hints, web, object_localizations
|
185
|
-
)
|
186
|
-
|
187
|
-
faces, landmarks, logos, labels, crop_hints, web, \
|
188
|
-
object_localizations = validate_max_args(
|
189
|
-
faces, landmarks, logos, labels, crop_hints, web,
|
190
|
-
object_localizations
|
191
|
-
)
|
192
|
-
|
193
|
-
f = value_features faces, landmarks, logos, labels, crop_hints, web,
|
194
|
-
object_localizations
|
195
|
-
f + boolean_features(text, document, safe_search, properties)
|
196
|
-
end
|
197
|
-
|
198
|
-
def value_features faces, landmarks, logos, labels, crop_hints, web,
|
199
|
-
object_localizations
|
200
|
-
[
|
201
|
-
value_feature(:FACE_DETECTION, faces),
|
202
|
-
value_feature(:LANDMARK_DETECTION, landmarks),
|
203
|
-
value_feature(:LOGO_DETECTION, logos),
|
204
|
-
value_feature(:LABEL_DETECTION, labels),
|
205
|
-
value_feature(:CROP_HINTS, crop_hints),
|
206
|
-
value_feature(:WEB_DETECTION, web),
|
207
|
-
value_feature(:OBJECT_LOCALIZATION, object_localizations)
|
208
|
-
].compact
|
209
|
-
end
|
210
|
-
|
211
|
-
def value_feature type, value
|
212
|
-
return if value.zero?
|
213
|
-
feature type, value
|
214
|
-
end
|
215
|
-
|
216
|
-
def boolean_features text, document, safe_search, properties
|
217
|
-
[
|
218
|
-
boolean_feature(:TEXT_DETECTION, text),
|
219
|
-
boolean_feature(:DOCUMENT_TEXT_DETECTION, document),
|
220
|
-
boolean_feature(:SAFE_SEARCH_DETECTION, safe_search),
|
221
|
-
boolean_feature(:IMAGE_PROPERTIES, properties)
|
222
|
-
].compact
|
223
|
-
end
|
224
|
-
|
225
|
-
def boolean_feature type, value
|
226
|
-
return unless value
|
227
|
-
feature type, 1
|
228
|
-
end
|
229
|
-
|
230
|
-
def feature type, max_results
|
231
|
-
Google::Cloud::Vision::V1::Feature.new(
|
232
|
-
type: type, max_results: max_results
|
233
|
-
)
|
234
|
-
end
|
235
|
-
|
236
|
-
def default_features? faces, landmarks, logos, labels, text, document,
|
237
|
-
safe_search, properties, crop_hints, web,
|
238
|
-
object_localizations
|
239
|
-
faces == false && landmarks == false && logos == false &&
|
240
|
-
labels == false && text == false && document == false &&
|
241
|
-
safe_search == false && properties == false &&
|
242
|
-
crop_hints == false && web == false && object_localizations == false
|
243
|
-
end
|
244
|
-
|
245
|
-
def default_features
|
246
|
-
[
|
247
|
-
feature(:FACE_DETECTION, Google::Cloud::Vision.default_max_faces),
|
248
|
-
feature(:LANDMARK_DETECTION,
|
249
|
-
Google::Cloud::Vision.default_max_landmarks),
|
250
|
-
feature(:LOGO_DETECTION, Google::Cloud::Vision.default_max_logos),
|
251
|
-
feature(:LABEL_DETECTION,
|
252
|
-
Google::Cloud::Vision.default_max_labels),
|
253
|
-
feature(:TEXT_DETECTION, 1),
|
254
|
-
feature(:DOCUMENT_TEXT_DETECTION, 1),
|
255
|
-
feature(:SAFE_SEARCH_DETECTION, 1),
|
256
|
-
feature(:IMAGE_PROPERTIES, 1),
|
257
|
-
feature(:CROP_HINTS, Google::Cloud::Vision.default_max_crop_hints),
|
258
|
-
feature(:WEB_DETECTION, Google::Cloud::Vision.default_max_web),
|
259
|
-
feature(:OBJECT_LOCALIZATION,
|
260
|
-
Google::Cloud::Vision.default_max_object_localizations)
|
261
|
-
]
|
262
|
-
end
|
263
|
-
|
264
|
-
def validate_max_args faces, landmarks, logos, labels, crop_hints, web,
|
265
|
-
object_localizations
|
266
|
-
faces = validate_max_value(
|
267
|
-
faces, Google::Cloud::Vision.default_max_faces
|
268
|
-
)
|
269
|
-
landmarks = validate_max_value(
|
270
|
-
landmarks, Google::Cloud::Vision.default_max_landmarks
|
271
|
-
)
|
272
|
-
logos = validate_max_value(
|
273
|
-
logos, Google::Cloud::Vision.default_max_logos
|
274
|
-
)
|
275
|
-
labels = validate_max_value(
|
276
|
-
labels, Google::Cloud::Vision.default_max_labels
|
277
|
-
)
|
278
|
-
crop_hints = validate_max_value(
|
279
|
-
crop_hints, Google::Cloud::Vision.default_max_crop_hints
|
280
|
-
)
|
281
|
-
web = validate_max_value(
|
282
|
-
web, Google::Cloud::Vision.default_max_web
|
283
|
-
)
|
284
|
-
object_localizations = validate_max_value(
|
285
|
-
object_localizations,
|
286
|
-
Google::Cloud::Vision.default_max_object_localizations
|
287
|
-
)
|
288
|
-
|
289
|
-
[
|
290
|
-
faces, landmarks, logos, labels, crop_hints, web,
|
291
|
-
object_localizations
|
292
|
-
]
|
293
|
-
end
|
294
|
-
|
295
|
-
def validate_max_value value, default_value
|
296
|
-
return value.to_int if value.respond_to? :to_int
|
297
|
-
return default_value if value
|
298
|
-
0 # not a number, not a truthy value
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|