ocr_space 1.0 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -19
- data/exe/ocrspace +3 -2
- data/lib/ocr_space.rb +17 -2
- data/lib/ocr_space/convert.rb +26 -0
- data/lib/ocr_space/version.rb +1 -1
- metadata +2 -3
- data/lib/ocr_space/from_file.rb +0 -20
- data/lib/ocr_space/from_url.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482aa09d94f5f2a4eb0bffba5b4a3a4e3eebb2ba
|
4
|
+
data.tar.gz: 343592d8b308393c5fd62b516b754cd4af7cabb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b08e263106cd8c8b04e6bba34eccaf5e1727892794a954f168a3d28f4dad951469175a58fb59cb1de1e390392702e76af92365e6454f6bb104034d3c0e54c6f
|
7
|
+
data.tar.gz: a14245907adc60dc9493b7018ee72578e413180f5600dddd573f4a141083f27994520c8da287084f540ea2a4764b84534e21d146cda0cf7006dd798cf2792293
|
data/README.md
CHANGED
@@ -28,12 +28,26 @@ Hosted at [rubygems.org](https://rubygems.org/gems/ocr_space)
|
|
28
28
|
|
29
29
|
![Nicola Tesla](http://bit.ly/2ih9aXt)
|
30
30
|
|
31
|
-
|
31
|
+
## Instantiate OcrSpace resource with apikey
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
require 'ocr_space'
|
35
35
|
|
36
|
-
|
36
|
+
resource = OcrSpace::Resource.new(apikey: "YOUR API KEY")
|
37
|
+
#By default it picks up ocr_api_key='YOUR API KEY' from your env variables
|
38
|
+
```
|
39
|
+
#ENV Variables (Optional)
|
40
|
+
setting env variables with api key is optional but for commandline interface to work you will have to set ENV variable 'ocr_api_key' to your apikey. For more details on Command line interface, scroll to the bottom of this page.
|
41
|
+
|
42
|
+
```
|
43
|
+
$ export ocr_api_key='YOUR API KEY'
|
44
|
+
```
|
45
|
+
|
46
|
+
#To convert images from url
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
|
50
|
+
result = resource.convert url: "http://bit.ly/2ih9aXt"
|
37
51
|
|
38
52
|
puts result.data
|
39
53
|
=> #[{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}]
|
@@ -47,9 +61,8 @@ puts result.text_data #Clean result
|
|
47
61
|
#To convert images from file upload
|
48
62
|
|
49
63
|
```ruby
|
50
|
-
require 'ocr_space'
|
51
64
|
|
52
|
-
result =
|
65
|
+
result = resource.convert file: "/Users/suyesh/Desktop/nicola_tesla.jpg"
|
53
66
|
|
54
67
|
puts result.data #Raw result
|
55
68
|
|
@@ -63,27 +76,13 @@ puts result.text_data #Clean result
|
|
63
76
|
|
64
77
|
#COMMAND LINE INTERFACE ***BONUS***
|
65
78
|
|
66
|
-
You can run ocr_space through shell to get quick result from a image using filepath
|
79
|
+
You can run ocr_space through shell to get quick result from a image using filepath or url
|
67
80
|
|
68
81
|
```
|
69
82
|
$ ocrspace /Users/suyesh/Desktop/nicola_tesla.jpg
|
70
83
|
|
71
84
|
=> If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES
|
72
85
|
|
73
|
-
```
|
74
|
-
#NOTE
|
75
|
-
For commandline interface to work you will have to set ENV variable 'ocr_api_key' to your apikey.
|
76
|
-
|
77
|
-
```
|
78
|
-
$ export ocr_api_key='YOUR API KEY'
|
79
|
-
```
|
80
|
-
Also if you set env variable then you don't need to include apikey in your ruby scripts. You can just do the following -
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
result = OcrSpace::FromFile.new(files: "./nicola_tesla.jpg") #for File based
|
84
|
-
|
85
|
-
result = OcrSpace::FromUrl.new(url: "http://bit.ly/2ih9aXt") #for URL based
|
86
|
-
|
87
86
|
```
|
88
87
|
|
89
88
|
#Optional
|
data/exe/ocrspace
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# !/usr/bin/env ruby
|
2
2
|
require 'colorize'
|
3
3
|
|
4
|
-
require_relative "../lib/ocr_space/
|
4
|
+
require_relative "../lib/ocr_space/convert"
|
5
5
|
|
6
6
|
if ARGV.empty?
|
7
7
|
puts "You need to mention the image path".colorize(:red)
|
8
8
|
else
|
9
9
|
begin
|
10
|
-
|
10
|
+
resource = OcrSpace::Resource.new
|
11
|
+
result = resource.convert file: ARGV[0]
|
11
12
|
puts result.text_data.colorize(:orange)
|
12
13
|
rescue
|
13
14
|
puts "Something went wrong, Please try again.".colorize(:red)
|
data/lib/ocr_space.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
require 'ocr_space/version'
|
2
|
-
require 'ocr_space/
|
3
|
-
require 'ocr_space/from_file'
|
2
|
+
require 'ocr_space/convert'
|
4
3
|
require 'ocr_space/banner'
|
4
|
+
|
5
|
+
module OcrSpace
|
6
|
+
class Resource
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
include OcrSpace::Convert
|
10
|
+
|
11
|
+
def initialize(apikey: ENV['ocr_api_key'])
|
12
|
+
@api_key = apikey
|
13
|
+
end
|
14
|
+
|
15
|
+
def text_data
|
16
|
+
data[0]['ParsedText'].delete("\n").delete("\r").strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ocr_space/file_post'
|
2
|
+
|
3
|
+
module OcrSpace
|
4
|
+
module Convert
|
5
|
+
def convert(apikey: @api_key, language: 'eng', isOverlayRequired: false, file: nil, url: nil)
|
6
|
+
if file
|
7
|
+
@files = File.new(file)
|
8
|
+
@data = OcrSpace::FilePost.post('/parse/image',
|
9
|
+
body: { apikey: apikey,
|
10
|
+
language: language,
|
11
|
+
isOverlayRequired: isOverlayRequired,
|
12
|
+
file: @files })
|
13
|
+
@data = @data.parsed_response['ParsedResults']
|
14
|
+
elsif url
|
15
|
+
@data = HTTParty.post('https://api.ocr.space/parse/image',
|
16
|
+
body: { apikey: apikey,
|
17
|
+
language: language,
|
18
|
+
isOverlayRequired: isOverlayRequired,
|
19
|
+
url: url })
|
20
|
+
@data = @data.parsed_response['ParsedResults']
|
21
|
+
else
|
22
|
+
"You need to Pass either file or url."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ocr_space/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocr_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Suyesh Bhandari
|
@@ -114,9 +114,8 @@ files:
|
|
114
114
|
- exe/ocrspace
|
115
115
|
- lib/ocr_space.rb
|
116
116
|
- lib/ocr_space/banner.rb
|
117
|
+
- lib/ocr_space/convert.rb
|
117
118
|
- lib/ocr_space/file_post.rb
|
118
|
-
- lib/ocr_space/from_file.rb
|
119
|
-
- lib/ocr_space/from_url.rb
|
120
119
|
- lib/ocr_space/version.rb
|
121
120
|
- ocr_space.gemspec
|
122
121
|
homepage: https://github.com/suyesh/ocr_space
|
data/lib/ocr_space/from_file.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'ocr_space/file_post'
|
2
|
-
|
3
|
-
module OcrSpace
|
4
|
-
class File
|
5
|
-
attr_reader :data
|
6
|
-
def initialize(apikey: ENV['ocr_api_key'], language: 'eng', isOverlayRequired: false, file: nil)
|
7
|
-
@files = File.new(file)
|
8
|
-
@data = OcrSpace::FilePost.post('/parse/image',
|
9
|
-
body: { apikey: apikey,
|
10
|
-
language: language,
|
11
|
-
isOverlayRequired: isOverlayRequired,
|
12
|
-
file: @files })
|
13
|
-
@data = @data.parsed_response['ParsedResults']
|
14
|
-
end
|
15
|
-
|
16
|
-
def text_data
|
17
|
-
data[0]['ParsedText'].delete("\n").delete("\r").strip
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/ocr_space/from_url.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
module OcrSpace
|
4
|
-
class Url
|
5
|
-
attr_reader :data
|
6
|
-
def initialize(apikey: ENV['ocr_api_key'], language: 'eng', isOverlayRequired: false, url: nil, ocr_space: 'https://api.ocr.space/parse/image')
|
7
|
-
@data = HTTParty.post(ocr_space,
|
8
|
-
body: { apikey: apikey,
|
9
|
-
language: language,
|
10
|
-
isOverlayRequired: isOverlayRequired,
|
11
|
-
url: url })
|
12
|
-
@data = @data.parsed_response['ParsedResults']
|
13
|
-
end
|
14
|
-
|
15
|
-
def text_data
|
16
|
-
data[0]['ParsedText'].delete("\n").delete("\r").strip
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|