character_recognition_by_vision_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d02b880bd9f86ac9e9c4c4a5b5640b90eebd968a
4
+ data.tar.gz: 2d25edd934172d75d35d1aca9ffd4c3b95df4afa
5
+ SHA512:
6
+ metadata.gz: 9367ab1e607beb97142179f17e8e114e5ff87104d40990785f3f670ddcb6faaf04ae4ba4cf195ceaf273f98e3a41f836149e8eff8db337bf9de14eae12564bcd
7
+ data.tar.gz: ad7d4b08c1f7149e76258f406a3d8ac19c9569047357785666cb1498c3dd2aba3f867d0c8cf334575adea68b1554729035832239a9b8719cc2d2041c878344ef
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in character_recognition_by_vision_api.gemspec
6
+ gemspec
7
+
8
+ gem 'rest-client'
9
+ gem 'rspec'
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ character_recognition_by_vision_api (0.1.0)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ domain_name (0.5.20170404)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.3)
14
+ domain_name (~> 0.5)
15
+ mime-types (3.1)
16
+ mime-types-data (~> 3.2015)
17
+ mime-types-data (3.2016.0521)
18
+ netrc (0.11.0)
19
+ rake (10.5.0)
20
+ rest-client (2.0.2)
21
+ http-cookie (>= 1.0.2, < 2.0)
22
+ mime-types (>= 1.16, < 4.0)
23
+ netrc (~> 0.8)
24
+ rspec (3.7.0)
25
+ rspec-core (~> 3.7.0)
26
+ rspec-expectations (~> 3.7.0)
27
+ rspec-mocks (~> 3.7.0)
28
+ rspec-core (3.7.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-expectations (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-mocks (3.7.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-support (3.7.0)
37
+ unf (0.1.4)
38
+ unf_ext
39
+ unf_ext (0.0.7.4)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.16)
46
+ character_recognition_by_vision_api!
47
+ rake (~> 10.0)
48
+ rest-client
49
+ rspec
50
+
51
+ BUNDLED WITH
52
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 corselia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ [![CircleCI](https://circleci.com/gh/corselia/character-recognition-by-vision-api/tree/master.svg?style=svg)](https://circleci.com/gh/corselia/character-recognition-by-vision-api/tree/master)
2
+
3
+ # Overview
4
+ - you get the characters as text format from the image file with characters
5
+ - first step
6
+ - you prepare the image file with characters (any language, of course Japanese too)
7
+ - you prepare the `API Key` of `Google Cloud Vision API`
8
+ - second step
9
+ - exec method in this gem
10
+ - third step
11
+ - you get the characters as text format :)
12
+
13
+ # Installation
14
+ ```ruby
15
+ $ gem install character_recognition_by_vision_api
16
+ ```
17
+
18
+ # Usage
19
+
20
+ #### 1. prepare the image file
21
+ in this repository, I prepare [sample_image.png](spec/sample_image.png)
22
+
23
+ ![spec/sample_image.png](sample_image.png "sample_image.png")
24
+
25
+ #### 2. prepare api_key of Google Cloud Vision API
26
+ - the official site of Google Cloud Vision API is here
27
+ - [Vision API | Google Cloud Platform](https://cloud.google.com/vision/)
28
+ - you acquire `API Key` at [Google Cloud Platform Service](https://console.cloud.google.com/)
29
+ - the detail of procedure is omitted on this document
30
+ - the blue part of below image contains `API Key`
31
+
32
+ ![api_key](api_key.png "api_key.png")
33
+
34
+ #### 3. require gem
35
+ ```ruby
36
+ require 'character_recognition_by_vision_api'
37
+ ```
38
+
39
+ #### 4. exec method
40
+ ```ruby
41
+ CharacterRecognitionByVisionApi.(image_file, api_key)
42
+ ```
43
+
44
+ #### 5. return the characters as text format
45
+ - 🎉you get the characters as text format🎉
46
+
47
+ # Example
48
+
49
+ #### when the image file is below
50
+
51
+ ![sample_image](sample_image.png "spec/sample_image.png")
52
+
53
+ #### the result is here
54
+
55
+ ```
56
+ あいうえおかきくけこさしすせそた
57
+ ちってとなにぬねのはひふへぼまみ
58
+ むめもやゆよらりる丸ろわをんーゑ
59
+ H本語表示サンプJ 1 2 3 4 5 60
60
+ ABCDE FGHIJKLMNOP
61
+ ```
62
+
63
+ - looks alomst good :)
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/character_recognition_by_vision_api.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
Binary file
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "character_recognition_by_vision_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "character_recognition_by_vision_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "character_recognition_by_vision_api"
8
+ spec.version = CharacterRecognitionByVisionApi::VERSION
9
+ spec.authors = ["Osamu Takiya"]
10
+ spec.email = ["takiya@toran.sakura.ne.jp"]
11
+
12
+ spec.summary = %q{Recognize characters in image file by Vision API}
13
+ spec.description = %q{With Google Vision API, you can extract the characters by text format from image file}
14
+ spec.homepage = "https://github.com/corselia/character-recognition-by-vision-api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_dependency 'rest-client'
38
+ end
@@ -0,0 +1,54 @@
1
+ require "character_recognition_by_vision_api/version"
2
+ require 'rest-client'
3
+ require 'base64'
4
+ require 'json'
5
+
6
+ module CharacterRecognitionByVisionApi
7
+ extend self
8
+
9
+ def extract_to_text(image_file, api_key)
10
+ JSON.parse(response_json(image_file, api_key))['responses'][0]['fullTextAnnotation']['text']
11
+ end
12
+
13
+ def payload(image_file)
14
+ {
15
+ requests: [
16
+ {
17
+ image:
18
+ {
19
+ content: Base64.encode64(open(image_file).read)
20
+ },
21
+ features: [
22
+ {
23
+ type: "TEXT_DETECTION",
24
+ maxResults: 10,
25
+ }
26
+ ]
27
+ }
28
+ ]
29
+ }
30
+ end
31
+
32
+ def headers_for_post
33
+ {
34
+ 'Content-Type': 'application/json',
35
+ }
36
+ end
37
+
38
+ def request_uri(api_key)
39
+ "https://vision.googleapis.com/v1/images:annotate?key=#{api_key}"
40
+ end
41
+
42
+ def response_json(image_file, api_key)
43
+ begin
44
+ RestClient.post(
45
+ request_uri(api_key),
46
+ payload(image_file).to_json,
47
+ headers_for_post,
48
+ )
49
+ rescue => e
50
+ puts e
51
+ exit(1)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module CharacterRecognitionByVisionApi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: character_recognition_by_vision_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Osamu Takiya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: With Google Vision API, you can extract the characters by text format
70
+ from image file
71
+ email:
72
+ - takiya@toran.sakura.ne.jp
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - api_key.png
86
+ - bin/console
87
+ - bin/setup
88
+ - character_recognition_by_vision_api.gemspec
89
+ - lib/character_recognition_by_vision_api.rb
90
+ - lib/character_recognition_by_vision_api/version.rb
91
+ homepage: https://github.com/corselia/character-recognition-by-vision-api
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.13
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Recognize characters in image file by Vision API
115
+ test_files: []