rtesseract 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b00b784a8ad22b0a84816a7c814e587726567972
4
- data.tar.gz: a7b1da64782e6d5d5a8bdaf098e6412cd53ca626
3
+ metadata.gz: 2184c2ed467331288d1f86523677d1dd108cd988
4
+ data.tar.gz: 63f39ebbdb2ba9e945ac8f503bd542a7b4fce46c
5
5
  SHA512:
6
- metadata.gz: ccc32c5ce1b558407f3331ada80aa20c1df91409b95b60b4b7c8a534e6e920e643a214744c848acdd2fafcba615edeae22b7612f5c04257e98c7ea8d9a0b31af
7
- data.tar.gz: 87430d4c193b95960d28e55002e838d862fd25fe7d3dee1f9be59aa080a3b3dad857957150cc64a8eb6d0a3838ac1dccd0878084f91ff21da3a3a17a6d16012a
6
+ metadata.gz: b247ec0bbd34adbf345ac57034244c51550dbb7e5d733e566bfe8a70e60cb8f2afb395890c520d251d03bc51d0a11308ea9995bcd42c76cb42e17a9c9c7af598
7
+ data.tar.gz: 553ef6e51ec48ca563d96539efadeffed32938e58e034e036d52c93492946e072b66001039803bf3324ae65ee04c5ee61edd00eb6cf6f314fb53eea5f0547ac7
@@ -3,6 +3,7 @@
3
3
  {<img src="https://travis-ci.org/dannnylo/rtesseract.png?branch=master" alt="Build Status" />}[https://travis-ci.org/dannnylo/rtesseract]
4
4
  {<img src="https://coveralls.io/repos/dannnylo/rtesseract/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/dannnylo/rtesseract?branch=master]
5
5
  {<img src="https://codeclimate.com/github/dannnylo/rtesseract.png" />}[https://codeclimate.com/github/dannnylo/rtesseract]
6
+ {<img src="http://badgr.co/gittip/dannnylo.png" />}[https://www.gittip.com/dannnylo/]
6
7
 
7
8
  Ruby library for working with the Tesseract OCR.
8
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -14,11 +14,15 @@ module QuickMagickProcessor
14
14
  cat = source.is_a?(Pathname) ? read_with_processor(source.to_s) : source
15
15
  cat.compress = 'None'
16
16
  cat.format = 'tif'
17
- cat.crop("#{w}x#{h}+#{x}+#{y}") unless [x, y, w, h].compact == []
17
+ cat.crop("#{w}x#{h}+#{x}+#{y}") if need_crop?( x, y, w, h)
18
18
  cat.write tmp_file.path.to_s
19
19
  tmp_file
20
20
  end
21
21
 
22
+ def self.need_crop?(x = nil, y = nil, w = nil, h = nil)
23
+ x.to_f + y.to_f + w.to_f + h.to_f > 0
24
+ end
25
+
22
26
  def self.read_with_processor(path)
23
27
  QuickMagick::Image.read(path.to_s).first
24
28
  end
@@ -29,7 +29,7 @@ class RTesseract
29
29
  def initialize(src = '', options = {})
30
30
  @options = command_line_options(options)
31
31
  @value, @x, @y, @w, @h = ['']
32
- choose_processor!
32
+ @processor = RTesseract.choose_processor!(@processor)
33
33
  @source = @processor.image?(src) ? src : Pathname.new(src)
34
34
  end
35
35
 
@@ -59,12 +59,9 @@ class RTesseract
59
59
 
60
60
  def self.read(src = nil, options = {}, &block)
61
61
  fail RTesseract::ImageNotSelectedError if src.nil?
62
- processor = options.delete(:processor) || options.delete('processor')
63
- if processor == 'mini_magick'
64
- image = MiniMagickProcessor.read_with_processor(src.to_s)
65
- else
66
- image = RMagickProcessor.read_with_processor(src.to_s)
67
- end
62
+ processor = RTesseract.choose_processor!(options.delete(:processor) || options.delete('processor'))
63
+ image = processor.read_with_processor(src.to_s)
64
+
68
65
  yield image
69
66
  object = RTesseract.new('', options)
70
67
  object.from_blob(image.to_blob)
@@ -123,7 +120,7 @@ class RTesseract
123
120
 
124
121
  # Page Segment Mode
125
122
  def psm
126
- @psm.nil? ? '' : " -psm #{@psm} "
123
+ (@psm.nil? ? '' : " -psm #{@psm} ")
127
124
  rescue
128
125
  ''
129
126
  end
@@ -193,17 +190,16 @@ class RTesseract
193
190
  to_s.gsub(' ', '').gsub("\n", '').gsub("\r", '')
194
191
  end
195
192
 
196
- private
197
-
198
- def choose_processor!
199
- @processor = if MiniMagickProcessor.a_name?(@processor.to_s)
193
+ def self.choose_processor!(processor)
194
+ processor = if MiniMagickProcessor.a_name?(processor.to_s)
200
195
  MiniMagickProcessor
201
- elsif QuickMagickProcessor.a_name?(@processor.to_s)
196
+ elsif QuickMagickProcessor.a_name?(processor.to_s)
202
197
  QuickMagickProcessor
203
198
  else
204
199
  RMagickProcessor
205
200
  end
206
- @processor.setup
201
+ processor.setup
202
+ processor
207
203
  end
208
204
  end
209
205
 
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: rtesseract 1.2.0 ruby lib
5
+ # stub: rtesseract 1.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rtesseract"
9
- s.version = "1.2.0"
9
+ s.version = "1.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Danilo Jeremias da Silva"]
14
- s.date = "2014-02-21"
14
+ s.date = "2014-02-26"
15
15
  s.description = "Ruby library for working with the Tesseract OCR."
16
16
  s.email = "dannnylo@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -1,6 +1,11 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  # encoding: UTF-8
3
3
  require 'pathname'
4
+ class MakeStringError
5
+ def to_s
6
+ raise "error"
7
+ end
8
+ end
4
9
 
5
10
  describe "Rtesseract" do
6
11
  before do
@@ -64,6 +69,9 @@ describe "Rtesseract" do
64
69
  RTesseract.new(@image_tiff,{:lang=>"por"}).to_s_without_spaces.should eql("43ZZ")
65
70
 
66
71
  RTesseract.new(@image_tiff,{:lang=>"eng"}).lang.should eql(" -l eng ")
72
+
73
+ #Inválid lang object
74
+ RTesseract.new(@image_tiff,{:lang=>MakeStringError.new}).lang.should eql("")
67
75
  end
68
76
 
69
77
  it " be configurable" do
@@ -102,6 +110,10 @@ describe "Rtesseract" do
102
110
  MiniMagickProcessor.a_name?('teste').should == false
103
111
  MiniMagickProcessor.a_name?('mini_magick').should == true
104
112
  MiniMagickProcessor.a_name?('MiniMagickProcessor').should == true
113
+
114
+ QuickMagickProcessor.a_name?('teste').should == false
115
+ QuickMagickProcessor.a_name?('quick_magick').should == true
116
+ QuickMagickProcessor.a_name?('QuickMagickProcessor').should == true
105
117
  end
106
118
 
107
119
  it " change image in a block" do
@@ -116,8 +128,6 @@ describe "Rtesseract" do
116
128
  end
117
129
  test.to_s_without_spaces.should eql("3R8Z")
118
130
 
119
- require 'mini_magick'
120
-
121
131
  test = RTesseract.read(@path.join("images","test.jpg").to_s,{:lang=>'en', :processor => 'mini_magick'}) do |image|
122
132
  #image.white_threshold(245)
123
133
  image.gravity "south"
@@ -128,6 +138,9 @@ describe "Rtesseract" do
128
138
  it " get a error" do
129
139
  expect{ RTesseract.new(@path.join("images","test.jpg").to_s, {:command => "tesseract_error"}).to_s }.to raise_error(RTesseract::ConversionError)
130
140
  expect{ RTesseract.new(@path.join("images","test_not_exists.png").to_s).to_s }.to raise_error(RTesseract::ImageNotSelectedError)
141
+
142
+ #Inválid psm object
143
+ RTesseract.new(@image_tiff,{:psm=>MakeStringError.new}).psm.should eql("")
131
144
  end
132
145
 
133
146
  it "remove a file" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtesseract
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Jeremias da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec