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
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
module Google
|
17
|
+
module Rpc
|
18
|
+
# The `Status` type defines a logical error model that is suitable for different
|
19
|
+
# programming environments, including REST APIs and RPC APIs. It is used by
|
20
|
+
# [gRPC](https://github.com/grpc). The error model is designed to be:
|
21
|
+
#
|
22
|
+
# * Simple to use and understand for most users
|
23
|
+
# * Flexible enough to meet unexpected needs
|
24
|
+
#
|
25
|
+
# = Overview
|
26
|
+
#
|
27
|
+
# The `Status` message contains three pieces of data: error code, error message,
|
28
|
+
# and error details. The error code should be an enum value of
|
29
|
+
# {Google::Rpc::Code}, but it may accept additional error codes if needed. The
|
30
|
+
# error message should be a developer-facing English message that helps
|
31
|
+
# developers *understand* and *resolve* the error. If a localized user-facing
|
32
|
+
# error message is needed, put the localized message in the error details or
|
33
|
+
# localize it in the client. The optional error details may contain arbitrary
|
34
|
+
# information about the error. There is a predefined set of error detail types
|
35
|
+
# in the package `google.rpc` that can be used for common error conditions.
|
36
|
+
#
|
37
|
+
# = Language mapping
|
38
|
+
#
|
39
|
+
# The `Status` message is the logical representation of the error model, but it
|
40
|
+
# is not necessarily the actual wire format. When the `Status` message is
|
41
|
+
# exposed in different client libraries and different wire protocols, it can be
|
42
|
+
# mapped differently. For example, it will likely be mapped to some exceptions
|
43
|
+
# in Java, but more likely mapped to some error codes in C.
|
44
|
+
#
|
45
|
+
# = Other uses
|
46
|
+
#
|
47
|
+
# The error model and the `Status` message can be used in a variety of
|
48
|
+
# environments, either with or without APIs, to provide a
|
49
|
+
# consistent developer experience across different environments.
|
50
|
+
#
|
51
|
+
# Example uses of this error model include:
|
52
|
+
#
|
53
|
+
# * Partial errors. If a service needs to return partial errors to the client,
|
54
|
+
# it may embed the `Status` in the normal response to indicate the partial
|
55
|
+
# errors.
|
56
|
+
#
|
57
|
+
# * Workflow errors. A typical workflow has multiple steps. Each step may
|
58
|
+
# have a `Status` message for error reporting.
|
59
|
+
#
|
60
|
+
# * Batch operations. If a client uses batch request and batch response, the
|
61
|
+
# `Status` message should be used directly inside batch response, one for
|
62
|
+
# each error sub-response.
|
63
|
+
#
|
64
|
+
# * Asynchronous operations. If an API call embeds asynchronous operation
|
65
|
+
# results in its response, the status of those operations should be
|
66
|
+
# represented directly using the `Status` message.
|
67
|
+
#
|
68
|
+
# * Logging. If some API errors are stored in logs, the message `Status` could
|
69
|
+
# be used directly after any stripping needed for security/privacy reasons.
|
70
|
+
# @!attribute [rw] code
|
71
|
+
# @return [Integer]
|
72
|
+
# The status code, which should be an enum value of {Google::Rpc::Code}.
|
73
|
+
# @!attribute [rw] message
|
74
|
+
# @return [String]
|
75
|
+
# A developer-facing error message, which should be in English. Any
|
76
|
+
# user-facing error message should be localized and sent in the
|
77
|
+
# {Google::Rpc::Status#details} field, or localized by the client.
|
78
|
+
# @!attribute [rw] details
|
79
|
+
# @return [Array<Google::Protobuf::Any>]
|
80
|
+
# A list of messages that carry the error details. There is a common set of
|
81
|
+
# message types for APIs to use.
|
82
|
+
class Status; end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
module Google
|
17
|
+
module Type
|
18
|
+
# Represents a color in the RGBA color space. This representation is designed
|
19
|
+
# for simplicity of conversion to/from color representations in various
|
20
|
+
# languages over compactness; for example, the fields of this representation
|
21
|
+
# can be trivially provided to the constructor of "java.awt.Color" in Java; it
|
22
|
+
# can also be trivially provided to UIColor's "+colorWithRed:green:blue:alpha"
|
23
|
+
# method in iOS; and, with just a little work, it can be easily formatted into
|
24
|
+
# a CSS "rgba()" string in JavaScript, as well. Here are some examples:
|
25
|
+
#
|
26
|
+
# Example (Java):
|
27
|
+
#
|
28
|
+
# import com.google.type.Color;
|
29
|
+
#
|
30
|
+
# // ...
|
31
|
+
# public static java.awt.Color fromProto(Color protocolor) {
|
32
|
+
# float alpha = protocolor.hasAlpha()
|
33
|
+
# ? protocolor.getAlpha().getValue()
|
34
|
+
# : 1.0;
|
35
|
+
#
|
36
|
+
# return new java.awt.Color(
|
37
|
+
# protocolor.getRed(),
|
38
|
+
# protocolor.getGreen(),
|
39
|
+
# protocolor.getBlue(),
|
40
|
+
# alpha);
|
41
|
+
# }
|
42
|
+
#
|
43
|
+
# public static Color toProto(java.awt.Color color) {
|
44
|
+
# float red = (float) color.getRed();
|
45
|
+
# float green = (float) color.getGreen();
|
46
|
+
# float blue = (float) color.getBlue();
|
47
|
+
# float denominator = 255.0;
|
48
|
+
# Color.Builder resultBuilder =
|
49
|
+
# Color
|
50
|
+
# .newBuilder()
|
51
|
+
# .setRed(red / denominator)
|
52
|
+
# .setGreen(green / denominator)
|
53
|
+
# .setBlue(blue / denominator);
|
54
|
+
# int alpha = color.getAlpha();
|
55
|
+
# if (alpha != 255) {
|
56
|
+
# result.setAlpha(
|
57
|
+
# FloatValue
|
58
|
+
# .newBuilder()
|
59
|
+
# .setValue(((float) alpha) / denominator)
|
60
|
+
# .build());
|
61
|
+
# }
|
62
|
+
# return resultBuilder.build();
|
63
|
+
# }
|
64
|
+
# // ...
|
65
|
+
#
|
66
|
+
# Example (iOS / Obj-C):
|
67
|
+
#
|
68
|
+
# // ...
|
69
|
+
# static UIColor* fromProto(Color* protocolor) {
|
70
|
+
# float red = [protocolor red];
|
71
|
+
# float green = [protocolor green];
|
72
|
+
# float blue = [protocolor blue];
|
73
|
+
# FloatValue* alpha_wrapper = [protocolor alpha];
|
74
|
+
# float alpha = 1.0;
|
75
|
+
# if (alpha_wrapper != nil) {
|
76
|
+
# alpha = [alpha_wrapper value];
|
77
|
+
# }
|
78
|
+
# return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
|
79
|
+
# }
|
80
|
+
#
|
81
|
+
# static Color* toProto(UIColor* color) {
|
82
|
+
# CGFloat red, green, blue, alpha;
|
83
|
+
# if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
|
84
|
+
# return nil;
|
85
|
+
# }
|
86
|
+
# Color* result = [Color alloc] init];
|
87
|
+
# [result setRed:red];
|
88
|
+
# [result setGreen:green];
|
89
|
+
# [result setBlue:blue];
|
90
|
+
# if (alpha <= 0.9999) {
|
91
|
+
# [result setAlpha:floatWrapperWithValue(alpha)];
|
92
|
+
# }
|
93
|
+
# [result autorelease];
|
94
|
+
# return result;
|
95
|
+
# }
|
96
|
+
# // ...
|
97
|
+
#
|
98
|
+
# Example (JavaScript):
|
99
|
+
#
|
100
|
+
# // ...
|
101
|
+
#
|
102
|
+
# var protoToCssColor = function(rgb_color) {
|
103
|
+
# var redFrac = rgb_color.red || 0.0;
|
104
|
+
# var greenFrac = rgb_color.green || 0.0;
|
105
|
+
# var blueFrac = rgb_color.blue || 0.0;
|
106
|
+
# var red = Math.floor(redFrac * 255);
|
107
|
+
# var green = Math.floor(greenFrac * 255);
|
108
|
+
# var blue = Math.floor(blueFrac * 255);
|
109
|
+
#
|
110
|
+
# if (!('alpha' in rgb_color)) {
|
111
|
+
# return rgbToCssColor_(red, green, blue);
|
112
|
+
# }
|
113
|
+
#
|
114
|
+
# var alphaFrac = rgb_color.alpha.value || 0.0;
|
115
|
+
# var rgbParams = [red, green, blue].join(',');
|
116
|
+
# return ['rgba(', rgbParams, ',', alphaFrac, ')'].join('');
|
117
|
+
# };
|
118
|
+
#
|
119
|
+
# var rgbToCssColor_ = function(red, green, blue) {
|
120
|
+
# var rgbNumber = new Number((red << 16) | (green << 8) | blue);
|
121
|
+
# var hexString = rgbNumber.toString(16);
|
122
|
+
# var missingZeros = 6 - hexString.length;
|
123
|
+
# var resultBuilder = ['#'];
|
124
|
+
# for (var i = 0; i < missingZeros; i++) {
|
125
|
+
# resultBuilder.push('0');
|
126
|
+
# }
|
127
|
+
# resultBuilder.push(hexString);
|
128
|
+
# return resultBuilder.join('');
|
129
|
+
# };
|
130
|
+
#
|
131
|
+
# // ...
|
132
|
+
# @!attribute [rw] red
|
133
|
+
# @return [Float]
|
134
|
+
# The amount of red in the color as a value in the interval [0, 1].
|
135
|
+
# @!attribute [rw] green
|
136
|
+
# @return [Float]
|
137
|
+
# The amount of green in the color as a value in the interval [0, 1].
|
138
|
+
# @!attribute [rw] blue
|
139
|
+
# @return [Float]
|
140
|
+
# The amount of blue in the color as a value in the interval [0, 1].
|
141
|
+
# @!attribute [rw] alpha
|
142
|
+
# @return [Google::Protobuf::FloatValue]
|
143
|
+
# The fraction of this color that should be applied to the pixel. That is,
|
144
|
+
# the final pixel color is defined by the equation:
|
145
|
+
#
|
146
|
+
# pixel color = alpha * (this color) + (1.0 - alpha) * (background color)
|
147
|
+
#
|
148
|
+
# This means that a value of 1.0 corresponds to a solid color, whereas
|
149
|
+
# a value of 0.0 corresponds to a completely transparent color. This
|
150
|
+
# uses a wrapper message rather than a simple float scalar so that it is
|
151
|
+
# possible to distinguish between a default value and the value being unset.
|
152
|
+
# If omitted, this color object is to be rendered as a solid color
|
153
|
+
# (as if the alpha value had been explicitly given with a value of 1.0).
|
154
|
+
class Color; end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
module Google
|
17
|
+
module Type
|
18
|
+
# An object representing a latitude/longitude pair. This is expressed as a pair
|
19
|
+
# of doubles representing degrees latitude and degrees longitude. Unless
|
20
|
+
# specified otherwise, this must conform to the
|
21
|
+
# <a href="http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf">WGS84
|
22
|
+
# standard</a>. Values must be within normalized ranges.
|
23
|
+
#
|
24
|
+
# Example of normalization code in Python:
|
25
|
+
#
|
26
|
+
# def NormalizeLongitude(longitude):
|
27
|
+
# """Wraps decimal degrees longitude to [-180.0, 180.0]."""
|
28
|
+
# q, r = divmod(longitude, 360.0)
|
29
|
+
# if r > 180.0 or (r == 180.0 and q <= -1.0):
|
30
|
+
# return r - 360.0
|
31
|
+
# return r
|
32
|
+
#
|
33
|
+
# def NormalizeLatLng(latitude, longitude):
|
34
|
+
# """Wraps decimal degrees latitude and longitude to
|
35
|
+
# [-90.0, 90.0] and [-180.0, 180.0], respectively."""
|
36
|
+
# r = latitude % 360.0
|
37
|
+
# if r <= 90.0:
|
38
|
+
# return r, NormalizeLongitude(longitude)
|
39
|
+
# elif r >= 270.0:
|
40
|
+
# return r - 360, NormalizeLongitude(longitude)
|
41
|
+
# else:
|
42
|
+
# return 180 - r, NormalizeLongitude(longitude + 180.0)
|
43
|
+
#
|
44
|
+
# assert 180.0 == NormalizeLongitude(180.0)
|
45
|
+
# assert -180.0 == NormalizeLongitude(-180.0)
|
46
|
+
# assert -179.0 == NormalizeLongitude(181.0)
|
47
|
+
# assert (0.0, 0.0) == NormalizeLatLng(360.0, 0.0)
|
48
|
+
# assert (0.0, 0.0) == NormalizeLatLng(-360.0, 0.0)
|
49
|
+
# assert (85.0, 180.0) == NormalizeLatLng(95.0, 0.0)
|
50
|
+
# assert (-85.0, -170.0) == NormalizeLatLng(-95.0, 10.0)
|
51
|
+
# assert (90.0, 10.0) == NormalizeLatLng(90.0, 10.0)
|
52
|
+
# assert (-90.0, -10.0) == NormalizeLatLng(-90.0, -10.0)
|
53
|
+
# assert (0.0, -170.0) == NormalizeLatLng(-180.0, 10.0)
|
54
|
+
# assert (0.0, -170.0) == NormalizeLatLng(180.0, 10.0)
|
55
|
+
# assert (-90.0, 10.0) == NormalizeLatLng(270.0, 10.0)
|
56
|
+
# assert (90.0, 10.0) == NormalizeLatLng(-270.0, 10.0)
|
57
|
+
# @!attribute [rw] latitude
|
58
|
+
# @return [Float]
|
59
|
+
# The latitude in degrees. It must be in the range [-90.0, +90.0].
|
60
|
+
# @!attribute [rw] longitude
|
61
|
+
# @return [Float]
|
62
|
+
# The longitude in degrees. It must be in the range [-180.0, +180.0].
|
63
|
+
class LatLng; end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/vision/v1p3beta1/geometry.proto
|
3
|
+
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/api/annotations_pb'
|
8
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
+
add_message "google.cloud.vision.v1p3beta1.Vertex" do
|
10
|
+
optional :x, :int32, 1
|
11
|
+
optional :y, :int32, 2
|
12
|
+
end
|
13
|
+
add_message "google.cloud.vision.v1p3beta1.NormalizedVertex" do
|
14
|
+
optional :x, :float, 1
|
15
|
+
optional :y, :float, 2
|
16
|
+
end
|
17
|
+
add_message "google.cloud.vision.v1p3beta1.BoundingPoly" do
|
18
|
+
repeated :vertices, :message, 1, "google.cloud.vision.v1p3beta1.Vertex"
|
19
|
+
repeated :normalized_vertices, :message, 2, "google.cloud.vision.v1p3beta1.NormalizedVertex"
|
20
|
+
end
|
21
|
+
add_message "google.cloud.vision.v1p3beta1.NormalizedBoundingPoly" do
|
22
|
+
repeated :vertices, :message, 1, "google.cloud.vision.v1p3beta1.NormalizedVertex"
|
23
|
+
end
|
24
|
+
add_message "google.cloud.vision.v1p3beta1.Position" do
|
25
|
+
optional :x, :float, 1
|
26
|
+
optional :y, :float, 2
|
27
|
+
optional :z, :float, 3
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Google
|
32
|
+
module Cloud
|
33
|
+
module Vision
|
34
|
+
module V1p3beta1
|
35
|
+
Vertex = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1p3beta1.Vertex").msgclass
|
36
|
+
NormalizedVertex = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1p3beta1.NormalizedVertex").msgclass
|
37
|
+
BoundingPoly = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1p3beta1.BoundingPoly").msgclass
|
38
|
+
NormalizedBoundingPoly = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1p3beta1.NormalizedBoundingPoly").msgclass
|
39
|
+
Position = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1p3beta1.Position").msgclass
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,972 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# # limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "uri"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Vision
|
21
|
+
module V1p3beta1
|
22
|
+
class ImageAnnotatorClient
|
23
|
+
|
24
|
+
# @param images [Array<String>, Array<File>]
|
25
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
26
|
+
# @param image [File, String]
|
27
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
28
|
+
# @param max_results [Integer]
|
29
|
+
# Optional. Defaults to 10.
|
30
|
+
# @param options [Google::Gax::CallOptions]
|
31
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
32
|
+
# retries, etc.
|
33
|
+
# @param async [Boolean]
|
34
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
35
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
36
|
+
# @param mime_type [String]
|
37
|
+
# Required only if async is true.
|
38
|
+
# @param batch_size [Integer]
|
39
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
40
|
+
# @param destination [String]
|
41
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
42
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
43
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
44
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
45
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
46
|
+
# @example
|
47
|
+
# require "google/cloud/vision"
|
48
|
+
#
|
49
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
50
|
+
#
|
51
|
+
# response = image_annotator_client.face_detection image: "path\to\image.png"
|
52
|
+
# response.responses.each do |res|
|
53
|
+
# puts res
|
54
|
+
# end
|
55
|
+
|
56
|
+
def face_detection \
|
57
|
+
images: [],
|
58
|
+
image: nil,
|
59
|
+
max_results: 10,
|
60
|
+
options: nil,
|
61
|
+
async: false,
|
62
|
+
mime_type: nil,
|
63
|
+
batch_size: 10,
|
64
|
+
destination: nil,
|
65
|
+
&blk
|
66
|
+
|
67
|
+
feature = { type: :FACE_DETECTION }
|
68
|
+
feature[:max_results] = max_results
|
69
|
+
images << image if image
|
70
|
+
|
71
|
+
formatted_images = images.map do |img|
|
72
|
+
formatted_image = normalize_image img
|
73
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
74
|
+
formatted_image
|
75
|
+
end
|
76
|
+
|
77
|
+
requests = formatted_images.map do |img|
|
78
|
+
{
|
79
|
+
image: img,
|
80
|
+
features: [feature]
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
if async
|
85
|
+
requests.map! do |request|
|
86
|
+
{
|
87
|
+
input_config: request[:image],
|
88
|
+
features: request[:features],
|
89
|
+
output_config: {
|
90
|
+
gcs_destination: destination,
|
91
|
+
batch_size: batch_size
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
async_batch_annotate_files requests, options
|
96
|
+
else
|
97
|
+
batch_annotate_images requests, options, &blk
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# @param images [Array<String>, Array<File>]
|
102
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
103
|
+
# @param image [File, String]
|
104
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
105
|
+
# @param max_results [Integer]
|
106
|
+
# Optional. Defaults to 10.
|
107
|
+
# @param options [Google::Gax::CallOptions]
|
108
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
109
|
+
# retries, etc.
|
110
|
+
# @param async [Boolean]
|
111
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
112
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
113
|
+
# @param mime_type [String]
|
114
|
+
# Required only if async is true.
|
115
|
+
# @param batch_size [Integer]
|
116
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
117
|
+
# @param destination [String]
|
118
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
119
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
120
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
121
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
122
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
123
|
+
# @example
|
124
|
+
# require "google/cloud/vision"
|
125
|
+
#
|
126
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
127
|
+
#
|
128
|
+
# response = image_annotator_client.landmark_detection image: "path\to\image.png"
|
129
|
+
# response.responses.each do |res|
|
130
|
+
# puts res
|
131
|
+
# end
|
132
|
+
|
133
|
+
def landmark_detection \
|
134
|
+
images: [],
|
135
|
+
image: nil,
|
136
|
+
max_results: 10,
|
137
|
+
options: nil,
|
138
|
+
async: false,
|
139
|
+
mime_type: nil,
|
140
|
+
batch_size: 10,
|
141
|
+
destination: nil,
|
142
|
+
&blk
|
143
|
+
|
144
|
+
feature = { type: :LANDMARK_DETECTION }
|
145
|
+
feature[:max_results] = max_results
|
146
|
+
images << image if image
|
147
|
+
|
148
|
+
formatted_images = images.map do |img|
|
149
|
+
formatted_image = normalize_image img
|
150
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
151
|
+
formatted_image
|
152
|
+
end
|
153
|
+
|
154
|
+
requests = formatted_images.map do |img|
|
155
|
+
{
|
156
|
+
image: img,
|
157
|
+
features: [feature]
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
if async
|
162
|
+
requests.map! do |request|
|
163
|
+
{
|
164
|
+
input_config: request[:image],
|
165
|
+
features: request[:features],
|
166
|
+
output_config: {
|
167
|
+
gcs_destination: destination,
|
168
|
+
batch_size: batch_size
|
169
|
+
}
|
170
|
+
}
|
171
|
+
end
|
172
|
+
async_batch_annotate_files requests, options
|
173
|
+
else
|
174
|
+
batch_annotate_images requests, options, &blk
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# @param images [Array<String>, Array<File>]
|
179
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
180
|
+
# @param image [File, String]
|
181
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
182
|
+
# @param max_results [Integer]
|
183
|
+
# Optional. Defaults to 10.
|
184
|
+
# @param options [Google::Gax::CallOptions]
|
185
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
186
|
+
# retries, etc.
|
187
|
+
# @param async [Boolean]
|
188
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
189
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
190
|
+
# @param mime_type [String]
|
191
|
+
# Required only if async is true.
|
192
|
+
# @param batch_size [Integer]
|
193
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
194
|
+
# @param destination [String]
|
195
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
196
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
197
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
198
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
199
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
200
|
+
# @example
|
201
|
+
# require "google/cloud/vision"
|
202
|
+
#
|
203
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
204
|
+
#
|
205
|
+
# response = image_annotator_client.logo_detection image: "path\to\image.png"
|
206
|
+
# response.responses.each do |res|
|
207
|
+
# puts res
|
208
|
+
# end
|
209
|
+
|
210
|
+
def logo_detection \
|
211
|
+
images: [],
|
212
|
+
image: nil,
|
213
|
+
max_results: 10,
|
214
|
+
options: nil,
|
215
|
+
async: false,
|
216
|
+
mime_type: nil,
|
217
|
+
batch_size: 10,
|
218
|
+
destination: nil,
|
219
|
+
&blk
|
220
|
+
|
221
|
+
feature = { type: :LOGO_DETECTION }
|
222
|
+
feature[:max_results] = max_results
|
223
|
+
images << image if image
|
224
|
+
|
225
|
+
formatted_images = images.map do |img|
|
226
|
+
formatted_image = normalize_image img
|
227
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
228
|
+
formatted_image
|
229
|
+
end
|
230
|
+
|
231
|
+
requests = formatted_images.map do |img|
|
232
|
+
{
|
233
|
+
image: img,
|
234
|
+
features: [feature]
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
if async
|
239
|
+
requests.map! do |request|
|
240
|
+
{
|
241
|
+
input_config: request[:image],
|
242
|
+
features: request[:features],
|
243
|
+
output_config: {
|
244
|
+
gcs_destination: destination,
|
245
|
+
batch_size: batch_size
|
246
|
+
}
|
247
|
+
}
|
248
|
+
end
|
249
|
+
async_batch_annotate_files requests, options
|
250
|
+
else
|
251
|
+
batch_annotate_images requests, options, &blk
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# @param images [Array<String>, Array<File>]
|
256
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
257
|
+
# @param image [File, String]
|
258
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
259
|
+
# @param max_results [Integer]
|
260
|
+
# Optional. Defaults to 10.
|
261
|
+
# @param options [Google::Gax::CallOptions]
|
262
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
263
|
+
# retries, etc.
|
264
|
+
# @param async [Boolean]
|
265
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
266
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
267
|
+
# @param mime_type [String]
|
268
|
+
# Required only if async is true.
|
269
|
+
# @param batch_size [Integer]
|
270
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
271
|
+
# @param destination [String]
|
272
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
273
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
274
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
275
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
276
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
277
|
+
# @example
|
278
|
+
# require "google/cloud/vision"
|
279
|
+
#
|
280
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
281
|
+
#
|
282
|
+
# response = image_annotator_client.label_detection image: "path\to\image.png"
|
283
|
+
# response.responses.each do |res|
|
284
|
+
# puts res
|
285
|
+
# end
|
286
|
+
|
287
|
+
def label_detection \
|
288
|
+
images: [],
|
289
|
+
image: nil,
|
290
|
+
max_results: 10,
|
291
|
+
options: nil,
|
292
|
+
async: false,
|
293
|
+
mime_type: nil,
|
294
|
+
batch_size: 10,
|
295
|
+
destination: nil,
|
296
|
+
&blk
|
297
|
+
|
298
|
+
feature = { type: :LABEL_DETECTION }
|
299
|
+
feature[:max_results] = max_results
|
300
|
+
images << image if image
|
301
|
+
|
302
|
+
formatted_images = images.map do |img|
|
303
|
+
formatted_image = normalize_image img
|
304
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
305
|
+
formatted_image
|
306
|
+
end
|
307
|
+
|
308
|
+
requests = formatted_images.map do |img|
|
309
|
+
{
|
310
|
+
image: img,
|
311
|
+
features: [feature]
|
312
|
+
}
|
313
|
+
end
|
314
|
+
|
315
|
+
if async
|
316
|
+
requests.map! do |request|
|
317
|
+
{
|
318
|
+
input_config: request[:image],
|
319
|
+
features: request[:features],
|
320
|
+
output_config: {
|
321
|
+
gcs_destination: destination,
|
322
|
+
batch_size: batch_size
|
323
|
+
}
|
324
|
+
}
|
325
|
+
end
|
326
|
+
async_batch_annotate_files requests, options
|
327
|
+
else
|
328
|
+
batch_annotate_images requests, options, &blk
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
# @param images [Array<String>, Array<File>]
|
333
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
334
|
+
# @param image [File, String]
|
335
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
336
|
+
# @param max_results [Integer]
|
337
|
+
# Optional. Defaults to 10.
|
338
|
+
# @param options [Google::Gax::CallOptions]
|
339
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
340
|
+
# retries, etc.
|
341
|
+
# @param async [Boolean]
|
342
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
343
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
344
|
+
# @param mime_type [String]
|
345
|
+
# Required only if async is true.
|
346
|
+
# @param batch_size [Integer]
|
347
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
348
|
+
# @param destination [String]
|
349
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
350
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
351
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
352
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
353
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
354
|
+
# @example
|
355
|
+
# require "google/cloud/vision"
|
356
|
+
#
|
357
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
358
|
+
#
|
359
|
+
# response = image_annotator_client.text_detection image: "path\to\image.png"
|
360
|
+
# response.responses.each do |res|
|
361
|
+
# puts res
|
362
|
+
# end
|
363
|
+
|
364
|
+
def text_detection \
|
365
|
+
images: [],
|
366
|
+
image: nil,
|
367
|
+
max_results: 10,
|
368
|
+
options: nil,
|
369
|
+
async: false,
|
370
|
+
mime_type: nil,
|
371
|
+
batch_size: 10,
|
372
|
+
destination: nil,
|
373
|
+
&blk
|
374
|
+
|
375
|
+
feature = { type: :TEXT_DETECTION }
|
376
|
+
feature[:max_results] = max_results
|
377
|
+
images << image if image
|
378
|
+
|
379
|
+
formatted_images = images.map do |img|
|
380
|
+
formatted_image = normalize_image img
|
381
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
382
|
+
formatted_image
|
383
|
+
end
|
384
|
+
|
385
|
+
requests = formatted_images.map do |img|
|
386
|
+
{
|
387
|
+
image: img,
|
388
|
+
features: [feature]
|
389
|
+
}
|
390
|
+
end
|
391
|
+
|
392
|
+
if async
|
393
|
+
requests.map! do |request|
|
394
|
+
{
|
395
|
+
input_config: request[:image],
|
396
|
+
features: request[:features],
|
397
|
+
output_config: {
|
398
|
+
gcs_destination: destination,
|
399
|
+
batch_size: batch_size
|
400
|
+
}
|
401
|
+
}
|
402
|
+
end
|
403
|
+
async_batch_annotate_files requests, options
|
404
|
+
else
|
405
|
+
batch_annotate_images requests, options, &blk
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# @param images [Array<String>, Array<File>]
|
410
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
411
|
+
# @param image [File, String]
|
412
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
413
|
+
# @param max_results [Integer]
|
414
|
+
# Optional. Defaults to 10.
|
415
|
+
# @param options [Google::Gax::CallOptions]
|
416
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
417
|
+
# retries, etc.
|
418
|
+
# @param async [Boolean]
|
419
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
420
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
421
|
+
# @param mime_type [String]
|
422
|
+
# Required only if async is true.
|
423
|
+
# @param batch_size [Integer]
|
424
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
425
|
+
# @param destination [String]
|
426
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
427
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
428
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
429
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
430
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
431
|
+
# @example
|
432
|
+
# require "google/cloud/vision"
|
433
|
+
#
|
434
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
435
|
+
#
|
436
|
+
# response = image_annotator_client.document_text_detection image: "path\to\image.png"
|
437
|
+
# response.responses.each do |res|
|
438
|
+
# puts res
|
439
|
+
# end
|
440
|
+
|
441
|
+
def document_text_detection \
|
442
|
+
images: [],
|
443
|
+
image: nil,
|
444
|
+
max_results: 10,
|
445
|
+
options: nil,
|
446
|
+
async: false,
|
447
|
+
mime_type: nil,
|
448
|
+
batch_size: 10,
|
449
|
+
destination: nil,
|
450
|
+
&blk
|
451
|
+
|
452
|
+
feature = { type: :DOCUMENT_TEXT_DETECTION }
|
453
|
+
feature[:max_results] = max_results
|
454
|
+
images << image if image
|
455
|
+
|
456
|
+
formatted_images = images.map do |img|
|
457
|
+
formatted_image = normalize_image img
|
458
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
459
|
+
formatted_image
|
460
|
+
end
|
461
|
+
|
462
|
+
requests = formatted_images.map do |img|
|
463
|
+
{
|
464
|
+
image: img,
|
465
|
+
features: [feature]
|
466
|
+
}
|
467
|
+
end
|
468
|
+
|
469
|
+
if async
|
470
|
+
requests.map! do |request|
|
471
|
+
{
|
472
|
+
input_config: request[:image],
|
473
|
+
features: request[:features],
|
474
|
+
output_config: {
|
475
|
+
gcs_destination: destination,
|
476
|
+
batch_size: batch_size
|
477
|
+
}
|
478
|
+
}
|
479
|
+
end
|
480
|
+
async_batch_annotate_files requests, options
|
481
|
+
else
|
482
|
+
batch_annotate_images requests, options, &blk
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
# @param images [Array<String>, Array<File>]
|
487
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
488
|
+
# @param image [File, String]
|
489
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
490
|
+
# @param max_results [Integer]
|
491
|
+
# Optional. Defaults to 10.
|
492
|
+
# @param options [Google::Gax::CallOptions]
|
493
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
494
|
+
# retries, etc.
|
495
|
+
# @param async [Boolean]
|
496
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
497
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
498
|
+
# @param mime_type [String]
|
499
|
+
# Required only if async is true.
|
500
|
+
# @param batch_size [Integer]
|
501
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
502
|
+
# @param destination [String]
|
503
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
504
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
505
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
506
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
507
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
508
|
+
# @example
|
509
|
+
# require "google/cloud/vision"
|
510
|
+
#
|
511
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
512
|
+
#
|
513
|
+
# response = image_annotator_client.safe_search_detection image: "path\to\image.png"
|
514
|
+
# response.responses.each do |res|
|
515
|
+
# puts res
|
516
|
+
# end
|
517
|
+
|
518
|
+
def safe_search_detection \
|
519
|
+
images: [],
|
520
|
+
image: nil,
|
521
|
+
max_results: 10,
|
522
|
+
options: nil,
|
523
|
+
async: false,
|
524
|
+
mime_type: nil,
|
525
|
+
batch_size: 10,
|
526
|
+
destination: nil,
|
527
|
+
&blk
|
528
|
+
|
529
|
+
feature = { type: :SAFE_SEARCH_DETECTION }
|
530
|
+
feature[:max_results] = max_results
|
531
|
+
images << image if image
|
532
|
+
|
533
|
+
formatted_images = images.map do |img|
|
534
|
+
formatted_image = normalize_image img
|
535
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
536
|
+
formatted_image
|
537
|
+
end
|
538
|
+
|
539
|
+
requests = formatted_images.map do |img|
|
540
|
+
{
|
541
|
+
image: img,
|
542
|
+
features: [feature]
|
543
|
+
}
|
544
|
+
end
|
545
|
+
|
546
|
+
if async
|
547
|
+
requests.map! do |request|
|
548
|
+
{
|
549
|
+
input_config: request[:image],
|
550
|
+
features: request[:features],
|
551
|
+
output_config: {
|
552
|
+
gcs_destination: destination,
|
553
|
+
batch_size: batch_size
|
554
|
+
}
|
555
|
+
}
|
556
|
+
end
|
557
|
+
async_batch_annotate_files requests, options
|
558
|
+
else
|
559
|
+
batch_annotate_images requests, options, &blk
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
# @param images [Array<String>, Array<File>]
|
564
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
565
|
+
# @param image [File, String]
|
566
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
567
|
+
# @param max_results [Integer]
|
568
|
+
# Optional. Defaults to 10.
|
569
|
+
# @param options [Google::Gax::CallOptions]
|
570
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
571
|
+
# retries, etc.
|
572
|
+
# @param async [Boolean]
|
573
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
574
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
575
|
+
# @param mime_type [String]
|
576
|
+
# Required only if async is true.
|
577
|
+
# @param batch_size [Integer]
|
578
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
579
|
+
# @param destination [String]
|
580
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
581
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
582
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
583
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
584
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
585
|
+
# @example
|
586
|
+
# require "google/cloud/vision"
|
587
|
+
#
|
588
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
589
|
+
#
|
590
|
+
# response = image_annotator_client.image_properties_detection image: "path\to\image.png"
|
591
|
+
# response.responses.each do |res|
|
592
|
+
# puts res
|
593
|
+
# end
|
594
|
+
|
595
|
+
def image_properties_detection \
|
596
|
+
images: [],
|
597
|
+
image: nil,
|
598
|
+
max_results: 10,
|
599
|
+
options: nil,
|
600
|
+
async: false,
|
601
|
+
mime_type: nil,
|
602
|
+
batch_size: 10,
|
603
|
+
destination: nil,
|
604
|
+
&blk
|
605
|
+
|
606
|
+
feature = { type: :IMAGE_PROPERTIES }
|
607
|
+
feature[:max_results] = max_results
|
608
|
+
images << image if image
|
609
|
+
|
610
|
+
formatted_images = images.map do |img|
|
611
|
+
formatted_image = normalize_image img
|
612
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
613
|
+
formatted_image
|
614
|
+
end
|
615
|
+
|
616
|
+
requests = formatted_images.map do |img|
|
617
|
+
{
|
618
|
+
image: img,
|
619
|
+
features: [feature]
|
620
|
+
}
|
621
|
+
end
|
622
|
+
|
623
|
+
if async
|
624
|
+
requests.map! do |request|
|
625
|
+
{
|
626
|
+
input_config: request[:image],
|
627
|
+
features: request[:features],
|
628
|
+
output_config: {
|
629
|
+
gcs_destination: destination,
|
630
|
+
batch_size: batch_size
|
631
|
+
}
|
632
|
+
}
|
633
|
+
end
|
634
|
+
async_batch_annotate_files requests, options
|
635
|
+
else
|
636
|
+
batch_annotate_images requests, options, &blk
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
# @param images [Array<String>, Array<File>]
|
641
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
642
|
+
# @param image [File, String]
|
643
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
644
|
+
# @param max_results [Integer]
|
645
|
+
# Optional. Defaults to 10.
|
646
|
+
# @param options [Google::Gax::CallOptions]
|
647
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
648
|
+
# retries, etc.
|
649
|
+
# @param async [Boolean]
|
650
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
651
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
652
|
+
# @param mime_type [String]
|
653
|
+
# Required only if async is true.
|
654
|
+
# @param batch_size [Integer]
|
655
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
656
|
+
# @param destination [String]
|
657
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
658
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
659
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
660
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
661
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
662
|
+
# @example
|
663
|
+
# require "google/cloud/vision"
|
664
|
+
#
|
665
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
666
|
+
#
|
667
|
+
# response = image_annotator_client.crop_hints_detection image: "path\to\image.png"
|
668
|
+
# response.responses.each do |res|
|
669
|
+
# puts res
|
670
|
+
# end
|
671
|
+
|
672
|
+
def crop_hints_detection \
|
673
|
+
images: [],
|
674
|
+
image: nil,
|
675
|
+
max_results: 10,
|
676
|
+
options: nil,
|
677
|
+
async: false,
|
678
|
+
mime_type: nil,
|
679
|
+
batch_size: 10,
|
680
|
+
destination: nil,
|
681
|
+
&blk
|
682
|
+
|
683
|
+
feature = { type: :CROP_HINTS }
|
684
|
+
feature[:max_results] = max_results
|
685
|
+
images << image if image
|
686
|
+
|
687
|
+
formatted_images = images.map do |img|
|
688
|
+
formatted_image = normalize_image img
|
689
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
690
|
+
formatted_image
|
691
|
+
end
|
692
|
+
|
693
|
+
requests = formatted_images.map do |img|
|
694
|
+
{
|
695
|
+
image: img,
|
696
|
+
features: [feature]
|
697
|
+
}
|
698
|
+
end
|
699
|
+
|
700
|
+
if async
|
701
|
+
requests.map! do |request|
|
702
|
+
{
|
703
|
+
input_config: request[:image],
|
704
|
+
features: request[:features],
|
705
|
+
output_config: {
|
706
|
+
gcs_destination: destination,
|
707
|
+
batch_size: batch_size
|
708
|
+
}
|
709
|
+
}
|
710
|
+
end
|
711
|
+
async_batch_annotate_files requests, options
|
712
|
+
else
|
713
|
+
batch_annotate_images requests, options, &blk
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
# @param images [Array<String>, Array<File>]
|
718
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
719
|
+
# @param image [File, String]
|
720
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
721
|
+
# @param max_results [Integer]
|
722
|
+
# Optional. Defaults to 10.
|
723
|
+
# @param options [Google::Gax::CallOptions]
|
724
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
725
|
+
# retries, etc.
|
726
|
+
# @param async [Boolean]
|
727
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
728
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
729
|
+
# @param mime_type [String]
|
730
|
+
# Required only if async is true.
|
731
|
+
# @param batch_size [Integer]
|
732
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
733
|
+
# @param destination [String]
|
734
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
735
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
736
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
737
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
738
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
739
|
+
# @example
|
740
|
+
# require "google/cloud/vision"
|
741
|
+
#
|
742
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
743
|
+
#
|
744
|
+
# response = image_annotator_client.product_search_detection image: "path\to\image.png"
|
745
|
+
# response.responses.each do |res|
|
746
|
+
# puts res
|
747
|
+
# end
|
748
|
+
|
749
|
+
def product_search_detection \
|
750
|
+
images: [],
|
751
|
+
image: nil,
|
752
|
+
max_results: 10,
|
753
|
+
options: nil,
|
754
|
+
async: false,
|
755
|
+
mime_type: nil,
|
756
|
+
batch_size: 10,
|
757
|
+
destination: nil,
|
758
|
+
&blk
|
759
|
+
|
760
|
+
feature = { type: :PRODUCT_SEARCH }
|
761
|
+
feature[:max_results] = max_results
|
762
|
+
images << image if image
|
763
|
+
|
764
|
+
formatted_images = images.map do |img|
|
765
|
+
formatted_image = normalize_image img
|
766
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
767
|
+
formatted_image
|
768
|
+
end
|
769
|
+
|
770
|
+
requests = formatted_images.map do |img|
|
771
|
+
{
|
772
|
+
image: img,
|
773
|
+
features: [feature]
|
774
|
+
}
|
775
|
+
end
|
776
|
+
|
777
|
+
if async
|
778
|
+
requests.map! do |request|
|
779
|
+
{
|
780
|
+
input_config: request[:image],
|
781
|
+
features: request[:features],
|
782
|
+
output_config: {
|
783
|
+
gcs_destination: destination,
|
784
|
+
batch_size: batch_size
|
785
|
+
}
|
786
|
+
}
|
787
|
+
end
|
788
|
+
async_batch_annotate_files requests, options
|
789
|
+
else
|
790
|
+
batch_annotate_images requests, options, &blk
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
# @param images [Array<String>, Array<File>]
|
795
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
796
|
+
# @param image [File, String]
|
797
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
798
|
+
# @param max_results [Integer]
|
799
|
+
# Optional. Defaults to 10.
|
800
|
+
# @param options [Google::Gax::CallOptions]
|
801
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
802
|
+
# retries, etc.
|
803
|
+
# @param async [Boolean]
|
804
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
805
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
806
|
+
# @param mime_type [String]
|
807
|
+
# Required only if async is true.
|
808
|
+
# @param batch_size [Integer]
|
809
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
810
|
+
# @param destination [String]
|
811
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
812
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
813
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
814
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
815
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
816
|
+
# @example
|
817
|
+
# require "google/cloud/vision"
|
818
|
+
#
|
819
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
820
|
+
#
|
821
|
+
# response = image_annotator_client.object_localization_detection image: "path\to\image.png"
|
822
|
+
# response.responses.each do |res|
|
823
|
+
# puts res
|
824
|
+
# end
|
825
|
+
|
826
|
+
def object_localization_detection \
|
827
|
+
images: [],
|
828
|
+
image: nil,
|
829
|
+
max_results: 10,
|
830
|
+
options: nil,
|
831
|
+
async: false,
|
832
|
+
mime_type: nil,
|
833
|
+
batch_size: 10,
|
834
|
+
destination: nil,
|
835
|
+
&blk
|
836
|
+
|
837
|
+
feature = { type: :OBJECT_LOCALIZATION }
|
838
|
+
feature[:max_results] = max_results
|
839
|
+
images << image if image
|
840
|
+
|
841
|
+
formatted_images = images.map do |img|
|
842
|
+
formatted_image = normalize_image img
|
843
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
844
|
+
formatted_image
|
845
|
+
end
|
846
|
+
|
847
|
+
requests = formatted_images.map do |img|
|
848
|
+
{
|
849
|
+
image: img,
|
850
|
+
features: [feature]
|
851
|
+
}
|
852
|
+
end
|
853
|
+
|
854
|
+
if async
|
855
|
+
requests.map! do |request|
|
856
|
+
{
|
857
|
+
input_config: request[:image],
|
858
|
+
features: request[:features],
|
859
|
+
output_config: {
|
860
|
+
gcs_destination: destination,
|
861
|
+
batch_size: batch_size
|
862
|
+
}
|
863
|
+
}
|
864
|
+
end
|
865
|
+
async_batch_annotate_files requests, options
|
866
|
+
else
|
867
|
+
batch_annotate_images requests, options, &blk
|
868
|
+
end
|
869
|
+
end
|
870
|
+
|
871
|
+
# @param images [Array<String>, Array<File>]
|
872
|
+
# An array containing files, file paths, io objects, image urls, or Google Cloud Storage urls. Can be used with or instead of image.
|
873
|
+
# @param image [File, String]
|
874
|
+
# A file, file path, io object, url pointing to an image, or Google Cloud Storage url. Can be used with or instead of images.
|
875
|
+
# @param max_results [Integer]
|
876
|
+
# Optional. Defaults to 10.
|
877
|
+
# @param options [Google::Gax::CallOptions]
|
878
|
+
# Optional. Overrides the default settings for this call, e.g, timeout,
|
879
|
+
# retries, etc.
|
880
|
+
# @param async [Boolean]
|
881
|
+
# Optional. Defaults to false. Specifies whether to preform the request synchronously and return a
|
882
|
+
# BatchAnnotateImagesResponse instance or to return a Google::Gax::Operation.
|
883
|
+
# @param mime_type [String]
|
884
|
+
# Required only if async is true.
|
885
|
+
# @param batch_size [Integer]
|
886
|
+
# Optional. Defaults to 10. When async is true, this specifies the number of input files per output json.
|
887
|
+
# @param destination [String]
|
888
|
+
# Required only if async is true. A Google Cloud Storage location for storing the output.
|
889
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
890
|
+
# @yieldparam result [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse]
|
891
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
892
|
+
# @return [Google::Cloud::Vision::V1p3beta1::BatchAnnotateImagesResponse, Google::Gax::Operation]
|
893
|
+
# @example
|
894
|
+
# require "google/cloud/vision"
|
895
|
+
#
|
896
|
+
# image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new(version: :v1p3beta1)
|
897
|
+
#
|
898
|
+
# response = image_annotator_client.web_detection image: "path\to\image.png"
|
899
|
+
# response.responses.each do |res|
|
900
|
+
# puts res
|
901
|
+
# end
|
902
|
+
|
903
|
+
def web_detection \
|
904
|
+
images: [],
|
905
|
+
image: nil,
|
906
|
+
max_results: 10,
|
907
|
+
options: nil,
|
908
|
+
async: false,
|
909
|
+
mime_type: nil,
|
910
|
+
batch_size: 10,
|
911
|
+
destination: nil,
|
912
|
+
&blk
|
913
|
+
|
914
|
+
feature = { type: :WEB_DETECTION }
|
915
|
+
feature[:max_results] = max_results
|
916
|
+
images << image if image
|
917
|
+
|
918
|
+
formatted_images = images.map do |img|
|
919
|
+
formatted_image = normalize_image img
|
920
|
+
formatted_image[:mime_type] = mime_type if mime_type
|
921
|
+
formatted_image
|
922
|
+
end
|
923
|
+
|
924
|
+
requests = formatted_images.map do |img|
|
925
|
+
{
|
926
|
+
image: img,
|
927
|
+
features: [feature]
|
928
|
+
}
|
929
|
+
end
|
930
|
+
|
931
|
+
if async
|
932
|
+
requests.map! do |request|
|
933
|
+
{
|
934
|
+
input_config: request[:image],
|
935
|
+
features: request[:features],
|
936
|
+
output_config: {
|
937
|
+
gcs_destination: destination,
|
938
|
+
batch_size: batch_size
|
939
|
+
}
|
940
|
+
}
|
941
|
+
end
|
942
|
+
async_batch_annotate_files requests, options
|
943
|
+
else
|
944
|
+
batch_annotate_images requests, options, &blk
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
private
|
949
|
+
|
950
|
+
def normalize_image image
|
951
|
+
formatted_image =
|
952
|
+
if image.respond_to? :binmode
|
953
|
+
{ content: image.binmode.read }
|
954
|
+
elsif image.is_a? String
|
955
|
+
if File.file? image
|
956
|
+
{ content: File.binread(image) }
|
957
|
+
elsif image =~ URI::DEFAULT_PARSER.make_regexp
|
958
|
+
if URI(image).scheme == "gs"
|
959
|
+
{ source: { gcs_image_uri: image } }
|
960
|
+
else
|
961
|
+
{ source: { image_uri: image } }
|
962
|
+
end
|
963
|
+
end
|
964
|
+
end
|
965
|
+
raise TypeError.new("Image must be a filepath, url, or IO object") unless formatted_image
|
966
|
+
formatted_image
|
967
|
+
end
|
968
|
+
end
|
969
|
+
end
|
970
|
+
end
|
971
|
+
end
|
972
|
+
end
|