Skip to content

Commit cd9eae4

Browse files
author
remi Taylor
authored
Merge pull request #50 from GoogleCloudPlatform/vision
Ruby Sample for Google Cloud Vision API
2 parents ca664cc + 48d1795 commit cd9eae4

13 files changed

Lines changed: 444 additions & 1 deletion

File tree

.rubocop.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ Performance/RedundantBlockCall:
7676
Style/EmptyLinesAroundBlockBody:
7777
Enabled: false
7878

79+
# Allow any level of comment indentation for documentation region tag comments
80+
Style/CommentIndentation:
81+
Enabled: false
82+
83+
# Methods in this repository are often used to wrap code snippets
84+
# These snippets may be long, so the method length cop is disabled
85+
Style/MethodLength:
86+
Enabled: false
87+
7988
Style/NumericLiterals:
8089
Enabled: false
8190
Style/SpaceAroundOperators:
@@ -109,4 +118,4 @@ Style/DotPosition:
109118
Style/WordArray:
110119
MinSize: 4
111120
Metrics/AbcSize:
112-
Max: 20
121+
Enabled: false

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ env:
3939
- TEST_DIR=translate
4040
- TEST_DIR=language
4141
- TEST_DIR=appengine/endpoints
42+
- TEST_DIR=vision
4243

4344
before_install:
4445
- openssl aes-256-cbc -K $encrypted_aeb4e2af7332_key -iv $encrypted_aeb4e2af7332_iv

vision/.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--tty --color --format documentation --order random

vision/Gemfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2016 Google, Inc
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+
source "https://rubygems.org"
16+
17+
gem "google-cloud-vision"
18+
gem "rmagick"
19+
20+
group :test do
21+
gem "rake"
22+
gem "rubocop"
23+
gem "rspec"
24+
gem "rack-test"
25+
end

vision/Gemfile.lock

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.4.0)
5+
ast (2.3.0)
6+
diff-lcs (1.2.5)
7+
faraday (0.9.2)
8+
multipart-post (>= 1.2, < 3)
9+
google-api-client (0.9.13)
10+
addressable (~> 2.3)
11+
googleauth (~> 0.5)
12+
httpclient (~> 2.7)
13+
hurley (~> 0.1)
14+
memoist (~> 0.11)
15+
mime-types (>= 1.6)
16+
representable (~> 2.3.0)
17+
retriable (~> 2.0)
18+
google-cloud-core (0.20.1)
19+
google-cloud-vision (0.20.0)
20+
google-api-client (~> 0.9.11)
21+
google-cloud-core (~> 0.20.0)
22+
googleauth (0.5.1)
23+
faraday (~> 0.9)
24+
jwt (~> 1.4)
25+
logging (~> 2.0)
26+
memoist (~> 0.12)
27+
multi_json (~> 1.11)
28+
os (~> 0.9)
29+
signet (~> 0.7)
30+
httpclient (2.8.2.3)
31+
hurley (0.2)
32+
jwt (1.5.4)
33+
little-plugger (1.1.4)
34+
logging (2.1.0)
35+
little-plugger (~> 1.1)
36+
multi_json (~> 1.10)
37+
memoist (0.15.0)
38+
mime-types (3.1)
39+
mime-types-data (~> 3.2015)
40+
mime-types-data (3.2016.0521)
41+
multi_json (1.12.1)
42+
multipart-post (2.0.0)
43+
os (0.9.6)
44+
parser (2.3.1.2)
45+
ast (~> 2.2)
46+
powerpack (0.1.1)
47+
rack (1.6.4)
48+
rack-test (0.6.3)
49+
rack (>= 1.0)
50+
rainbow (2.1.0)
51+
rake (11.1.2)
52+
representable (2.3.0)
53+
uber (~> 0.0.7)
54+
retriable (2.1.0)
55+
rmagick (2.16.0)
56+
rspec (3.4.0)
57+
rspec-core (~> 3.4.0)
58+
rspec-expectations (~> 3.4.0)
59+
rspec-mocks (~> 3.4.0)
60+
rspec-core (3.4.4)
61+
rspec-support (~> 3.4.0)
62+
rspec-expectations (3.4.0)
63+
diff-lcs (>= 1.2.0, < 2.0)
64+
rspec-support (~> 3.4.0)
65+
rspec-mocks (3.4.1)
66+
diff-lcs (>= 1.2.0, < 2.0)
67+
rspec-support (~> 3.4.0)
68+
rspec-support (3.4.1)
69+
rubocop (0.42.0)
70+
parser (>= 2.3.1.1, < 3.0)
71+
powerpack (~> 0.1)
72+
rainbow (>= 1.99.1, < 3.0)
73+
ruby-progressbar (~> 1.7)
74+
unicode-display_width (~> 1.0, >= 1.0.1)
75+
ruby-progressbar (1.8.1)
76+
signet (0.7.3)
77+
addressable (~> 2.3)
78+
faraday (~> 0.9)
79+
jwt (~> 1.5)
80+
multi_json (~> 1.10)
81+
uber (0.0.15)
82+
unicode-display_width (1.1.0)
83+
84+
PLATFORMS
85+
ruby
86+
87+
DEPENDENCIES
88+
google-cloud-vision
89+
rack-test
90+
rake
91+
rmagick
92+
rspec
93+
rubocop
94+
95+
BUNDLED WITH
96+
1.12.5

vision/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
2+
3+
# Google Cloud Vision API Ruby Samples
4+
5+
The [Cloud Vision API][vision_docs] allows developers to easily integrate vision
6+
detection features within applications, including image labeling, face and
7+
landmark detection, optical character recognition (OCR), and tagging of explicit
8+
content.
9+
10+
[vision_docs]: https://cloud.google.com/vision/docs/
11+
12+
## Run sample
13+
14+
To run the sample, first install dependencies:
15+
16+
bundle install
17+
18+
Run the sample:
19+
20+
bundle exec ruby vision_samples.rb
21+
22+
Usage:
23+
24+
Usage: ruby vision_samples.rb <command> [arguments]
25+
26+
Commands:
27+
labels <image-path>
28+
landmark <image-path>
29+
faces <image-path> <output-image-path>
30+
31+
Example:
32+
33+
ruby vision_samples.rb labels /path/to/cat.jpg
34+
ruby vision_samples.rb landmark /path/to/grand-canyon.jpg
35+
ruby vision_samples.rb faces /path/to/faces.jpg output-image.jpg

vision/Rakefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2016 Google, Inc
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+
require "rspec/core/rake_task"
16+
RSpec::Core::RakeTask.new(:spec)
17+
18+
require "rubocop/rake_task"
19+
RuboCop::RakeTask.new
20+
21+
task default: :spec

vision/detect.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2016 Google, Inc
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 write, 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+
require_relative "label_detection"
16+
require_relative "landmark_detection"
17+
require_relative "face_detection"
18+
19+
detection_type = ARGV.shift
20+
path_to_image_file = ARGV.shift
21+
path_to_output_file = ARGV.shift
22+
23+
case detection_type
24+
when "label"
25+
detect_labels path_to_image_file
26+
when "landmark"
27+
detect_landmark path_to_image_file
28+
when "faces"
29+
detect_faces path_to_image_file, path_to_output_file
30+
else
31+
puts "Usage: detect.rb [type] [image path] [output path]"
32+
puts
33+
puts " detect.rb label /path/to/image.jpg"
34+
puts " detect.rb landmark /path/to/image.jpg"
35+
puts " detect.rb faces /path/to/image.jpg /path/to/output.jpg"
36+
end

vision/images/cat.jpg

72.8 KB
Loading

vision/images/eiffel_tower.jpg

162 KB
Loading

0 commit comments

Comments
 (0)