xtractor 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/lib/xtractor/request.rb +2 -2
- data/lib/xtractor/version.rb +1 -1
- data/lib/xtractor/xtract.rb +23 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1680978fbaff54a46f6782eadc169a62fd2c390e
|
4
|
+
data.tar.gz: 05fd4bb0b9fb6313f2d52e3516a88c99e08abf63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92d4842b906384882409a8095f18b9e0586035c231203c90e4b095aa11fd0837f27c73c838600ad549de2c2586bf83d6d4f7b24adc0be35478fba0a912f19545
|
7
|
+
data.tar.gz: c71d1009526a3ebb22ff491392c7e4c49bf7ecf05895a977dc23537b7d795b7361e911e84ac11ec1cae77946415647f02a3fcaa2151f03326824204b72eaa135
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Xtractor
|
2
|
-
<img src="https://badge.fury.io/rb/xtractor.svg"
|
2
|
+
<img src="https://badge.fury.io/rb/xtractor.svg" /> <img src="https://travis-ci.org/Kamalpaneru/Xtractor.svg?branch=master" alt="Build" />
|
3
3
|
|
4
4
|
|
5
5
|
Xtractor was developed as a need to the problem of inserting data from an excelsheet image to excel.And it does the same as described.
|
@@ -28,7 +28,11 @@ Used to split cells from excel sheet images and extracts data. <br>
|
|
28
28
|
```ruby
|
29
29
|
require 'xtractor'
|
30
30
|
|
31
|
-
|
31
|
+
api_key = "Your_api_key_here"
|
32
|
+
|
33
|
+
process = Xtractor::Execute.new('Image_Filename', api_key)
|
34
|
+
|
35
|
+
process.begin_process
|
32
36
|
|
33
37
|
```
|
34
38
|
## Sample Image
|
@@ -36,7 +40,7 @@ Used to split cells from excel sheet images and extracts data. <br>
|
|
36
40
|
![image_f3](https://user-images.githubusercontent.com/13826932/31273813-03dde45a-aab0-11e7-942f-c77202f996d1.jpg)
|
37
41
|
|
38
42
|
## Generate API key
|
39
|
-
|
43
|
+
Generate your API key <br>
|
40
44
|
```https://azure.microsoft.com/en-gb/try/cognitive-services/ ```
|
41
45
|
|
42
46
|
## Contributing
|
data/lib/xtractor/request.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
|
4
4
|
class Azure_API
|
5
5
|
|
6
|
-
def request_API
|
6
|
+
def request_API(api_key)
|
7
7
|
uri = URI('https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/ocr')
|
8
8
|
uri.query = URI.encode_www_form({
|
9
9
|
|
@@ -13,7 +13,7 @@ class Azure_API
|
|
13
13
|
|
14
14
|
request = Net::HTTP::Post.new(uri.request_uri)
|
15
15
|
|
16
|
-
request['Ocp-Apim-Subscription-Key'] =
|
16
|
+
request['Ocp-Apim-Subscription-Key'] = api_key
|
17
17
|
|
18
18
|
request['Content-Type'] = 'application/octet-stream'
|
19
19
|
|
data/lib/xtractor/version.rb
CHANGED
data/lib/xtractor/xtract.rb
CHANGED
@@ -5,23 +5,28 @@ require_relative "request"
|
|
5
5
|
module Xtractor
|
6
6
|
class Execute
|
7
7
|
|
8
|
-
def initialize(image)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
def initialize(image, api_key)
|
9
|
+
@image = image
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def begin_process
|
14
|
+
img = Magick::Image::read(@image).first
|
15
|
+
|
16
|
+
if %w(TIFF).include? img.format
|
17
|
+
crop_throw(img)
|
18
|
+
else
|
19
|
+
img.write('Conv_img.tif')
|
20
|
+
img = Magick::Image::read('Conv_img.tif').first
|
21
|
+
crop_throw(img)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
def crop_throw(img)
|
21
|
-
|
22
|
-
box =
|
23
|
-
|
24
|
-
start(
|
26
|
+
image = img.resize_to_fit(2500,906)
|
27
|
+
box = image.bounding_box
|
28
|
+
image.crop!(box.x, box.y, box.width, box.height)
|
29
|
+
start(image)
|
25
30
|
end
|
26
31
|
|
27
32
|
def store_line_rows(img)
|
@@ -88,13 +93,13 @@ module Xtractor
|
|
88
93
|
|
89
94
|
end
|
90
95
|
end
|
91
|
-
collect_hash(img)
|
96
|
+
collect_hash(img, @api_key)
|
92
97
|
end
|
93
98
|
|
94
|
-
def collect_hash(
|
99
|
+
def collect_hash(*args)
|
95
100
|
api = Azure_API.new
|
96
|
-
api.request_API
|
97
|
-
out_final(
|
101
|
+
api.request_API(args[1])
|
102
|
+
out_final(args[0])
|
98
103
|
end
|
99
104
|
|
100
105
|
def out_final(img)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xtractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kamalpaneru
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|