rtesseract 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/.document +1 -2
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +13 -11
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -16
  8. data/Gemfile.lock +42 -82
  9. data/LICENSE.txt +18 -17
  10. data/README.md +137 -0
  11. data/Rakefile +4 -48
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/rtesseract/box.rb +15 -60
  15. data/lib/rtesseract/check.rb +14 -0
  16. data/lib/rtesseract/command.rb +41 -0
  17. data/lib/rtesseract/configuration.rb +15 -64
  18. data/lib/rtesseract/pdf.rb +18 -0
  19. data/lib/rtesseract/text.rb +9 -0
  20. data/lib/rtesseract/tsv.rb +18 -0
  21. data/lib/rtesseract/version.rb +3 -0
  22. data/lib/rtesseract.rb +22 -214
  23. data/rtesseract.gemspec +27 -93
  24. metadata +38 -71
  25. data/README.rdoc +0 -156
  26. data/VERSION +0 -1
  27. data/lib/processors/mini_magick.rb +0 -43
  28. data/lib/processors/none.rb +0 -34
  29. data/lib/processors/rmagick.rb +0 -46
  30. data/lib/rtesseract/blob.rb +0 -34
  31. data/lib/rtesseract/box_char.rb +0 -31
  32. data/lib/rtesseract/errors.rb +0 -21
  33. data/lib/rtesseract/mixed.rb +0 -54
  34. data/lib/rtesseract/processor.rb +0 -19
  35. data/lib/rtesseract/utils.rb +0 -44
  36. data/spec/configs/eng.user-words.txt +0 -13
  37. data/spec/images/README.pdf +0 -0
  38. data/spec/images/blank.tif +0 -0
  39. data/spec/images/mixed.tif +0 -0
  40. data/spec/images/orientation_reverse.png +0 -0
  41. data/spec/images/test with spaces.tif +0 -0
  42. data/spec/images/test-pdf.png +0 -0
  43. data/spec/images/test.bmp +0 -0
  44. data/spec/images/test.jpg +0 -0
  45. data/spec/images/test.png +0 -0
  46. data/spec/images/test.tif +0 -0
  47. data/spec/images/test1.tif +0 -0
  48. data/spec/images/test_words.png +0 -0
  49. data/spec/rtesseract_box_char_spec.rb +0 -82
  50. data/spec/rtesseract_box_spec.rb +0 -36
  51. data/spec/rtesseract_mixed_spec.rb +0 -49
  52. data/spec/rtesseract_spec.rb +0 -274
  53. data/spec/spec_helper.rb +0 -18
@@ -1,13 +0,0 @@
1
- you
2
- are
3
- a
4
- friend
5
- you
6
- speak
7
- the
8
- password
9
- and
10
- the
11
- doors
12
- will
13
- open
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/spec/images/test.bmp DELETED
Binary file
data/spec/images/test.jpg DELETED
Binary file
data/spec/images/test.png DELETED
Binary file
data/spec/images/test.tif DELETED
Binary file
Binary file
Binary file
@@ -1,82 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe 'Rtesseract::BoxChar' do
5
- before do
6
- @path = Pathname.new(__FILE__.gsub('rtesseract_box_char_spec.rb', '')).expand_path
7
- @image_tiff = @path.join('images', 'test.tif').to_s
8
- @words_image = @path.join('images', 'test_words.png').to_s
9
- @values = [
10
- { char: 'I', x_start: 52, y_start: 91, x_end: 54, y_end: 104 },
11
- { char: 'f', x_start: 56, y_start: 91, x_end: 63, y_end: 105 },
12
- { char: 'y', x_start: 69, y_start: 87, x_end: 79, y_end: 101 },
13
- { char: 'o', x_start: 80, y_start: 91, x_end: 90, y_end: 101 },
14
- { char: 'u', x_start: 92, y_start: 91, x_end: 100, y_end: 101 },
15
- { char: 'a', x_start: 108, y_start: 91, x_end: 116, y_end: 101 },
16
- { char: 'r', x_start: 119, y_start: 91, x_end: 125, y_end: 101 },
17
- { char: 'e', x_start: 126, y_start: 91, x_end: 136, y_end: 101 },
18
- { char: 'a', x_start: 143, y_start: 91, x_end: 151, y_end: 101 },
19
- { char: 'f', x_start: 158, y_start: 91, x_end: 165, y_end: 105 },
20
- { char: 'r', x_start: 166, y_start: 91, x_end: 172, y_end: 101 },
21
- { char: 'i', x_start: 174, y_start: 91, x_end: 176, y_end: 105 },
22
- { char: 'e', x_start: 178, y_start: 91, x_end: 188, y_end: 101 },
23
- { char: 'n', x_start: 190, y_start: 91, x_end: 198, y_end: 101 },
24
- { char: 'd', x_start: 200, y_start: 91, x_end: 209, y_end: 105 },
25
- { char: ',', x_start: 211, y_start: 89, x_end: 214, y_end: 93 },
26
- { char: 'y', x_start: 51, y_start: 65, x_end: 61, y_end: 79 },
27
- { char: 'o', x_start: 62, y_start: 69, x_end: 72, y_end: 79 },
28
- { char: 'u', x_start: 74, y_start: 69, x_end: 82, y_end: 79 },
29
- { char: 's', x_start: 90, y_start: 69, x_end: 97, y_end: 79 },
30
- { char: 'p', x_start: 99, y_start: 65, x_end: 108, y_end: 79 },
31
- { char: 'e', x_start: 109, y_start: 69, x_end: 119, y_end: 79 },
32
- { char: 'a', x_start: 120, y_start: 69, x_end: 128, y_end: 79 },
33
- { char: 'k', x_start: 131, y_start: 69, x_end: 140, y_end: 83 },
34
- { char: 't', x_start: 146, y_start: 69, x_end: 152, y_end: 82 },
35
- { char: 'h', x_start: 154, y_start: 69, x_end: 162, y_end: 83 },
36
- { char: 'e', x_start: 164, y_start: 69, x_end: 174, y_end: 79 },
37
- { char: 'p', x_start: 182, y_start: 65, x_end: 191, y_end: 79 },
38
- { char: 'a', x_start: 192, y_start: 69, x_end: 200, y_end: 79 },
39
- { char: 's', x_start: 202, y_start: 69, x_end: 209, y_end: 79 },
40
- { char: 's', x_start: 210, y_start: 69, x_end: 217, y_end: 79 },
41
- { char: 'w', x_start: 219, y_start: 69, x_end: 232, y_end: 79 },
42
- { char: 'o', x_start: 234, y_start: 69, x_end: 244, y_end: 79 },
43
- { char: 'r', x_start: 246, y_start: 69, x_end: 252, y_end: 79 },
44
- { char: 'd', x_start: 253, y_start: 69, x_end: 262, y_end: 83 },
45
- { char: ',', x_start: 264, y_start: 67, x_end: 267, y_end: 71 },
46
- { char: 'a', x_start: 51, y_start: 47, x_end: 59, y_end: 57 },
47
- { char: 'n', x_start: 62, y_start: 47, x_end: 70, y_end: 57 },
48
- { char: 'd', x_start: 72, y_start: 47, x_end: 81, y_end: 61 },
49
- { char: 't', x_start: 89, y_start: 47, x_end: 95, y_end: 60 },
50
- { char: 'h', x_start: 97, y_start: 47, x_end: 105, y_end: 61 },
51
- { char: 'e', x_start: 107, y_start: 47, x_end: 117, y_end: 57 },
52
- { char: 'd', x_start: 124, y_start: 47, x_end: 133, y_end: 61 },
53
- { char: 'o', x_start: 135, y_start: 47, x_end: 145, y_end: 57 },
54
- { char: 'o', x_start: 146, y_start: 47, x_end: 156, y_end: 57 },
55
- { char: 'r', x_start: 158, y_start: 47, x_end: 164, y_end: 57 },
56
- { char: 's', x_start: 165, y_start: 47, x_end: 172, y_end: 57 },
57
- { char: 'w', x_start: 180, y_start: 47, x_end: 193, y_end: 57 },
58
- { char: 'i', x_start: 196, y_start: 47, x_end: 198, y_end: 61 },
59
- { char: 'l', x_start: 201, y_start: 47, x_end: 203, y_end: 61 },
60
- { char: 'l', x_start: 206, y_start: 47, x_end: 208, y_end: 61 },
61
- { char: 'o', x_start: 216, y_start: 47, x_end: 226, y_end: 57 },
62
- { char: 'p', x_start: 228, y_start: 43, x_end: 237, y_end: 57 },
63
- { char: 'e', x_start: 238, y_start: 47, x_end: 248, y_end: 57 },
64
- { char: 'n', x_start: 250, y_start: 47, x_end: 258, y_end: 57 },
65
- { char: '.', x_start: 261, y_start: 47, x_end: 263, y_end: 49 }]
66
- end
67
-
68
- it 'bounding box by char' do
69
- expect(RTesseract::BoxChar.new(@image_tiff).characters.is_a?(Array)).to eql(true)
70
- expect(RTesseract::BoxChar.new(@image_tiff).characters).to eql([
71
- { char: '4', x_start: 145, y_start: 14, x_end: 159, y_end: 33 },
72
- { char: '3', x_start: 184, y_start: 14, x_end: 196, y_end: 33 },
73
- { char: 'X', x_start: 222, y_start: 14, x_end: 238, y_end: 32 },
74
- { char: 'F', x_start: 260, y_start: 14, x_end: 273, y_end: 32 }])
75
-
76
- expect(RTesseract::BoxChar.new(@words_image).characters).to eql(@values)
77
-
78
- expect { RTesseract::BoxChar.new(@image_tiff, command: 'tesseract_error').to_s }.to raise_error(RTesseract::ConversionError)
79
- expect { RTesseract::BoxChar.new(@image_tiff + '_not_exist').to_s }.to raise_error(RTesseract::ImageNotSelectedError)
80
- # expect(RTesseract::BoxChar.new(@path.join('images', 'blank.tif').to_s, options: :digits).characters).to eql([])
81
- end
82
- end
@@ -1,36 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe 'Rtesseract::Box' do
5
- before do
6
- @path = Pathname.new(__FILE__.gsub('rtesseract_box_spec.rb', '')).expand_path
7
- @image_tiff = @path.join('images', 'test.tif').to_s
8
- @words_image = @path.join('images', 'test_words.png').to_s
9
- end
10
-
11
- it 'bounding box' do
12
- expect(RTesseract.new(@words_image).to_s).to eql("If you are a friend,\nyou speak the password,\nand the doors will open.\n\n")
13
- expect(RTesseract::Box.new(@words_image).words).to eql([
14
- { word: 'If', x_start: 52, y_start: 13, x_end: 63, y_end: 27 },
15
- { word: 'you', x_start: 69, y_start: 17, x_end: 100, y_end: 31 },
16
- { word: 'are', x_start: 108, y_start: 17, x_end: 136, y_end: 27 },
17
- { word: 'a', x_start: 143, y_start: 17, x_end: 151, y_end: 27 },
18
- { word: 'friend,', x_start: 158, y_start: 13, x_end: 214, y_end: 29 },
19
- { word: 'you', x_start: 51, y_start: 39, x_end: 82, y_end: 53 },
20
- { word: 'speak', x_start: 90, y_start: 35, x_end: 140, y_end: 53 },
21
- { word: 'the', x_start: 146, y_start: 35, x_end: 174, y_end: 49 },
22
- { word: 'password,', x_start: 182, y_start: 35, x_end: 267, y_end: 53 },
23
- { word: 'and', x_start: 51, y_start: 57, x_end: 81, y_end: 71 },
24
- { word: 'the', x_start: 89, y_start: 57, x_end: 117, y_end: 71 },
25
- { word: 'doors', x_start: 124, y_start: 57, x_end: 172, y_end: 71 },
26
- { word: 'will', x_start: 180, y_start: 57, x_end: 208, y_end: 71 },
27
- { word: 'open.', x_start: 216, y_start: 61, x_end: 263, y_end: 75 }
28
- ])
29
-
30
- expect(RTesseract::Box.new(@image_tiff).words.is_a?(Array)).to eql(true)
31
- expect(RTesseract::Box.new(@words_image).to_s).to eql('If you are a friend, you speak the password, and the doors will open.')
32
- expect { RTesseract::Box.new(@image_tiff, command: 'tesseract_error').to_s }.to raise_error(RTesseract::ConversionError)
33
- expect { RTesseract::Box.new(@image_tiff + '_not_exist').to_s }.to raise_error(RTesseract::ImageNotSelectedError)
34
- # expect(RTesseract::Box.new(@path.join('images', 'blank.tif').to_s, options: :digits).words).to eql([])
35
- end
36
- end
@@ -1,49 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe 'Rtesseract::Mixed' do
5
- before do
6
- @path = Pathname.new(__FILE__.gsub('rtesseract_mixed_spec.rb', '')).expand_path
7
- @image_tif = @path.join('images', 'mixed.tif').to_s
8
- @image2_tif = @path.join('images', 'mixed2.tif').to_s
9
- end
10
-
11
- it 'should be instantiable' do
12
- expect(RTesseract::Mixed.new.class).to eql(RTesseract::Mixed)
13
- expect(RTesseract::Mixed.new(@image_tif).class).to eql(RTesseract::Mixed)
14
- end
15
-
16
- it 'should translate parts of the image to text' do
17
- mix_block = RTesseract::Mixed.new(@image_tif, psm: 7) do |image|
18
- image.area(x: 28, y: 19, w: 25, h: 25) # position of 4
19
- image.area(x: 180, y: 22, w: 20, h: 28) # position of 3
20
- image.area(x: 218, y: 22, w: 24, h: 28) # position of F
21
- image.area(x: 248, y: 24, w: 22, h: 22) # position of F
22
- end
23
- expect(mix_block.to_s_without_spaces).to eql('43FF')
24
- mix_block.clear_areas
25
- expect(mix_block.areas).to eql([])
26
-
27
- @areas = []
28
- @areas << { x: 28, y: 19, w: 25, h: 25 } # position of 4
29
- @areas << { x: 180, y: 22, w: 20, h: 28 } # position of 3
30
- @areas << { x: 218, y: 22, w: 24, h: 28 } # position of f
31
- @areas << { x: 248, y: 24, w: 22, h: 22 } # position of f
32
-
33
- mix_block = RTesseract::Mixed.new(@image_tif, areas: @areas, psm: 7)
34
- expect(mix_block.to_s_without_spaces).to eql('43FF')
35
-
36
- mix_block = RTesseract::Mixed.new(@path.join('images', 'blank.tif').to_s, areas: @areas, psm: 7)
37
- expect(mix_block.to_s_without_spaces).to eql('')
38
- end
39
-
40
- it ' get a error' do
41
- @areas = [{ x: 28, y: 19, w: 25, h: 25 }]
42
-
43
- mix_block = RTesseract::Mixed.new(@path.join('images', 'test_not_exists.png').to_s, areas: @areas, psm: 7)
44
- expect { mix_block.to_s_without_spaces }.to raise_error(RTesseract::ImageNotSelectedError)
45
-
46
- mix_block = RTesseract::Mixed.new(@image_tif, areas: @areas, psm: 7, command: 'tesseract_error')
47
- expect { mix_block.to_s }.to raise_error(RTesseract::ConversionError)
48
- end
49
- end
@@ -1,274 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- # encoding: UTF-8
3
- require 'pathname'
4
-
5
- # Class to rise error
6
- class MakeStringError
7
- def to_s
8
- fail 'error'
9
- end
10
- end
11
-
12
- describe 'Rtesseract' do
13
- before do
14
- @path = Pathname.new(__FILE__.gsub('rtesseract_spec.rb', '')).expand_path
15
- @image_tif = @path.join('images', 'test.tif').to_s
16
- @image_for_pdf = @path.join('images', 'test-pdf.png').to_s
17
- end
18
-
19
- it ' be instantiable' do
20
- expect(RTesseract.new.class).to eql(RTesseract)
21
- expect(RTesseract.new('').class).to eql(RTesseract)
22
- expect(RTesseract.new(@image_tif).class).to eql(RTesseract)
23
- end
24
-
25
- it ' translate image to text' do
26
- expect(RTesseract.new(@image_tif).to_s_without_spaces).to eql('43XF')
27
- expect(RTesseract.new(@image_tif, processor: 'mini_magick').to_s_without_spaces).to eql('43XF')
28
- expect(RTesseract.new(@path.join('images', 'test1.tif').to_s).to_s_without_spaces).to eql('V2V4')
29
- expect(RTesseract.new(@path.join('images', 'test with spaces.tif').to_s).to_s_without_spaces).to eql('V2V4')
30
- end
31
-
32
- it ' translate images .png, .jpg, .bmp' do
33
- expect(RTesseract.new(@path.join('images', 'test.png').to_s).to_s_without_spaces).to eql('HW9W')
34
- expect(RTesseract.new(@path.join('images', 'test.jpg').to_s).to_s_without_spaces).to eql('3R8F')
35
- expect(RTesseract.new(@path.join('images', 'test.bmp').to_s).to_s_without_spaces).to eql('FLA6')
36
- end
37
-
38
- it ' should not error with depth > 32' do
39
- # expect(RTesseract.new(@path.join('images', 'README.pdf').to_s, debug: true).to_s_without_spaces).to eql('')
40
- end
41
-
42
- it ' support different processors' do
43
- # Rmagick
44
- expect(RTesseract.new(@image_tif).to_s_without_spaces).to eql('43XF')
45
- expect(RTesseract.new(@image_tif, processor: 'rmagick').to_s_without_spaces).to eql('43XF')
46
- expect(RTesseract.new(@path.join('images', 'test.png').to_s, processor: 'rmagick').to_s_without_spaces).to eql('HW9W')
47
-
48
- # MiniMagick
49
- expect(RTesseract.new(@image_tif, processor: 'mini_magick').to_s_without_spaces).to eql('43XF')
50
- expect(RTesseract.new(@path.join('images', 'test.png').to_s, processor: 'mini_magick').to_s_without_spaces).to eql('HW9W')
51
-
52
- # NoneMagick
53
- expect(RTesseract.new(@image_tif, processor: 'none').to_s_without_spaces).to eql('43XF')
54
- end
55
-
56
- it ' change the image' do
57
- image = RTesseract.new(@image_tif)
58
- expect(image.to_s_without_spaces).to eql('43XF')
59
- image.source = @path.join('images', 'test1.tif').to_s
60
- expect(image.to_s_without_spaces).to eql('V2V4')
61
- end
62
-
63
- it ' returns the source' do
64
- image = RTesseract.new(@image_tif)
65
- expect(image.source).to eql(Pathname.new(@image_tif))
66
- end
67
-
68
- it ' select the language' do
69
- # English
70
- expect(RTesseract.new(@image_tif, lang: 'eng').lang).to eql(' -l eng ')
71
- expect(RTesseract.new(@image_tif, lang: 'en').lang).to eql(' -l eng ')
72
- expect(RTesseract.new(@image_tif, lang: 'en-US').lang).to eql(' -l eng ')
73
- expect(RTesseract.new(@image_tif, lang: 'english').lang).to eql(' -l eng ')
74
-
75
- # Portuguese
76
- expect(RTesseract.new(@image_tif, lang: 'por').lang).to eql(' -l por ')
77
- expect(RTesseract.new(@image_tif, lang: 'pt-BR').lang).to eql(' -l por ')
78
- expect(RTesseract.new(@image_tif, lang: 'pt-br').lang).to eql(' -l por ')
79
- expect(RTesseract.new(@image_tif, lang: 'pt').lang).to eql(' -l por ')
80
- expect(RTesseract.new(@image_tif, lang: 'portuguese').lang).to eql(' -l por ')
81
-
82
- expect(RTesseract.new(@image_tif, lang: 'eng').to_s_without_spaces).to eql('43XF')
83
-
84
- expect(RTesseract.new(@image_tif, lang: 'eng').lang).to eql(' -l eng ')
85
- expect(RTesseract.new(@image_tif, lang: 'it').lang).to eql(' -l ita ')
86
-
87
- # Invalid lang object
88
- expect(RTesseract.new(@image_tif, lang: MakeStringError.new).lang).to eql('')
89
- end
90
-
91
- it ' select options' do
92
- expect(RTesseract.new(@image_tif).options_cmd).to eql([])
93
- expect(RTesseract.new(@image_tif, options: 'digits').options_cmd).to eql(['digits'])
94
- expect(RTesseract.new(@image_tif, options: :digits).options_cmd).to eql([:digits])
95
- expect(RTesseract.new(@image_tif, options: [:digits, :quiet]).options_cmd).to eql([:digits, :quiet])
96
- end
97
-
98
- it ' support pdf output mode' do
99
- # Internal test. Consider 'pdf' option only when #to_pdf is called.
100
- expect(RTesseract.new(@image_tif, options: 'pdf').options_cmd).to eql([])
101
- expect(RTesseract.new(@image_for_pdf, options: :pdf).options_cmd).to eql([])
102
-
103
- pdf_ocr = RTesseract.new(@image_for_pdf)
104
- expect(File.exists?(pdf_ocr.to_pdf)).to eql(true)
105
- expect(File.extname(pdf_ocr.to_pdf)).to eql('.pdf')
106
- # Comment next line and go to tmp dir to see generated pdf.
107
- expect(pdf_ocr.clean).to eq(true)
108
- expect(File.exists?(pdf_ocr.to_pdf)).to eql(false)
109
-
110
- # Still have original functionality (i.e. #to_s, #to_s_without_spaces).
111
- pdf_ocr = RTesseract.new(@image_tif)
112
- expect(File.exists?(pdf_ocr.to_pdf)).to eql(true)
113
- expect(File.extname(pdf_ocr.to_pdf)).to eql('.pdf')
114
- expect(pdf_ocr.to_s_without_spaces).to eql('43XF')
115
- expect(pdf_ocr.clean).to eq(true)
116
- expect(File.exists?(pdf_ocr.to_pdf)).to eql(false)
117
- end
118
-
119
- it ' warn when tesseract cannot give pdf' do
120
- rtesseract = RTesseract.new(@image_for_pdf)
121
-
122
- allow(rtesseract).to receive(:tesseract_version).and_return(3.02)
123
- expect { rtesseract.to_pdf }.to raise_error(RTesseract::TesseractVersionError)
124
-
125
- allow(rtesseract).to receive(:tesseract_version).and_return(3.03)
126
- expect { rtesseract.to_pdf }.not_to raise_error
127
- end
128
-
129
- it ' be configurable' do
130
- expect(RTesseract.new(@image_tif, chop_enable: 0, enable_assoc: 0, display_text: 0).config).to eql("chop_enable 0\nenable_assoc 0\ndisplay_text 0")
131
- expect(RTesseract.new(@image_tif, chop_enable: 0).config).to eql('chop_enable 0')
132
- expect(RTesseract.new(@image_tif, chop_enable: 0, enable_assoc: 0).config).to eql("chop_enable 0\nenable_assoc 0")
133
- expect(RTesseract.new(@image_tif, chop_enable: 0).to_s_without_spaces).to eql('43XF')
134
- expect(RTesseract.new(@image_tif, tessedit_char_whitelist: 'ABCDEF12345').to_s_without_spaces).to eql('43F')
135
- end
136
-
137
- it ' crop image' do
138
- expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 36, h: 40, x: 140, y: 10).to_s_without_spaces).to eql('4')
139
- expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 36, h: 40, x: 180, y: 10).to_s_without_spaces).to eql('3')
140
- expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 20, h: 40, x: 216, y: 10).to_s_without_spaces).to eql('X')
141
- expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 30, h: 40, x: 240, y: 10).to_s_without_spaces).to eql('F')
142
- end
143
-
144
- it ' read image from blob' do
145
- image = Magick::Image.read(@path.join('images', 'test.png').to_s).first
146
- blob = image.quantize(256, Magick::GRAYColorspace).to_blob
147
-
148
- test = RTesseract.new('', psm: 7)
149
- test.from_blob(blob)
150
- expect(test.to_s_without_spaces).to eql('HW9W')
151
-
152
- test = RTesseract.new('', psm: 7)
153
- expect { test.from_blob('') }.to raise_error(RTesseract::ConversionError)
154
- end
155
-
156
- it ' use a instance' do
157
- expect(RTesseract.new(Magick::Image.read(@image_tif.to_s).first).to_s_without_spaces).to eql('43XF')
158
- expect(RTesseract::Processor::RMagickProcessor.a_name?('teste')).to eql(false)
159
- expect(RTesseract::Processor::RMagickProcessor.a_name?('rmagick')).to eql(true)
160
- expect(RTesseract::Processor::RMagickProcessor.a_name?('RMagickProcessor')).to eql(true)
161
- expect(RTesseract::Processor::MiniMagickProcessor.a_name?('teste')).to eql(false)
162
- expect(RTesseract::Processor::MiniMagickProcessor.a_name?('mini_magick')).to eql(true)
163
- expect(RTesseract::Processor::MiniMagickProcessor.a_name?('MiniMagickProcessor')).to eql(true)
164
- expect(RTesseract::Processor::NoneProcessor.a_name?('none')).to eql(true)
165
- expect(RTesseract::Processor::NoneProcessor.a_name?('NoneProcessor')).to eql(true)
166
- end
167
-
168
- it ' change image in a block' do
169
- test = RTesseract.read(@path.join('images', 'test.png').to_s) {}
170
- expect(test.class).to eql(RTesseract)
171
-
172
- test = RTesseract.new(@image_tif)
173
- test.read do |_image|
174
- _image = _image.quantize(256, Magick::GRAYColorspace)
175
- end
176
- expect(test.to_s_without_spaces).to eql('43XF')
177
-
178
- test = RTesseract.new(@path.join('images', 'blank.tif').to_s)
179
- test.read do |_image|
180
- _image
181
- end
182
- expect(test.to_s_without_spaces).to eql('')
183
-
184
- test = RTesseract.read(@path.join('images', 'test.png').to_s) do |_image|
185
- _image.rotate(90)
186
- end
187
- expect(test.to_s_without_spaces).to eql('HW9W')
188
-
189
- test = RTesseract.read(@path.join('images', 'test.jpg').to_s, lang: 'en') do |_image|
190
- _image = _image.white_threshold(245).quantize(256, Magick::GRAYColorspace)
191
- end
192
- expect(test.to_s_without_spaces).to eql('3R8F')
193
-
194
- test = RTesseract.read(@path.join('images', 'test.jpg').to_s, lang: 'en', processor: 'mini_magick') do |_image|
195
- _image.gravity 'south'
196
- end
197
- expect(test.to_s_without_spaces).to eql('3R8F')
198
- end
199
-
200
- it ' get a error' do
201
- expect { RTesseract.new(@path.join('images', 'test.jpg').to_s, command: 'tesseract_error').to_s }.to raise_error(RTesseract::ConversionError)
202
- expect { RTesseract.new(@path.join('images', 'test_not_exists.png').to_s).to_s }.to raise_error(RTesseract::ImageNotSelectedError)
203
-
204
- # Invalid psm object
205
- expect(RTesseract.new(@image_tif, psm: MakeStringError.new).psm).to eql('')
206
- end
207
-
208
- it 'remove a file' do
209
- RTesseract::Utils.remove_files(Tempfile.new('config'))
210
-
211
- expect { RTesseract::Utils.remove_files(Pathname.new(Dir.tmpdir).join('test_not_exists')) }.to raise_error(RTesseract::TempFilesNotRemovedError)
212
- end
213
-
214
- it ' get a numeric value for tesseract version' do
215
- expect(RTesseract::Utils.version_number).to be_a Float
216
- end
217
-
218
- it ' support default config processors' do
219
- # Rmagick
220
- RTesseract.configure { |config| config.processor = 'rmagick' }
221
- expect(RTesseract.new(@image_tif).processor.a_name?('rmagick')).to eql(true)
222
-
223
- # MiniMagick
224
- RTesseract.configure { |config| config.processor = 'mini_magick' }
225
- expect(RTesseract.new(@image_tif).processor.a_name?('mini_magick')).to eql(true)
226
-
227
- # NoneMagick
228
- RTesseract.configure { |config| config.processor = 'none' }
229
- expect(RTesseract.new(@image_tif).processor.a_name?('none')).to eql(true)
230
-
231
- # overwrite default
232
- RTesseract.configure { |config| config.processor = 'rmagick' }
233
- expect(RTesseract.new(@image_tif, processor: 'mini_magick').processor.a_name?('mini_magick')).to eql(true)
234
-
235
- RTesseract.configure { |config| config.lang = 'portuguese' }
236
- expect(RTesseract.new(@image_tif).lang).to eql(' -l por ')
237
-
238
- RTesseract.configure { |config| config.psm = 7 }
239
- expect(RTesseract.new(@image_tif).psm).to eql(' -psm 7 ')
240
-
241
- RTesseract.configure { |config| config.tessdata_dir = '/tmp/test' }
242
- expect(RTesseract.new(@image_tif).tessdata_dir).to eql(' --tessdata-dir /tmp/test ')
243
-
244
- RTesseract.configure { |config| config.user_words = '/tmp/test' }
245
- expect(RTesseract.new(@image_tif).user_words).to eql(' --user-words /tmp/test ')
246
-
247
- RTesseract.configure { |config| config.user_patterns = '/tmp/test' }
248
- expect(RTesseract.new(@image_tif).user_patterns).to eql(' --user-patterns /tmp/test ')
249
- end
250
-
251
- it ' configure pdf has no effect and kept in-house' do
252
- # So it does not interfere with #to_s outputting.
253
- RTesseract.configure { |config| config.options_cmd = ['pdf'] }
254
- expect(RTesseract.new(@image_tif).options_cmd).to eql([])
255
-
256
- RTesseract.configure { |config| config.options_cmd = [:pdf] }
257
- expect(RTesseract.new(@image_tif).options_cmd).to eql([])
258
-
259
- RTesseract.configure { |config| config.options_cmd = [:pdf, 'pdf'] }
260
- expect(RTesseract.new(@image_tif).options_cmd).to eql([])
261
- end
262
-
263
- it ' support new configs' do
264
- expect(RTesseract.new(@image_tif, tessdata_dir: '/tmp/test').tessdata_dir).to eql(' --tessdata-dir /tmp/test ')
265
- expect(RTesseract.new(@image_tif, user_words: '/tmp/test').user_words).to eql(' --user-words /tmp/test ')
266
- expect(RTesseract.new(@image_tif, user_patterns: '/tmp/test').user_patterns).to eql(' --user-patterns /tmp/test ')
267
-
268
- expect(RTesseract.new(@image_tif, tessdata_dir: MakeStringError.new).tessdata_dir).to eql('')
269
- expect(RTesseract.new(@image_tif, user_words: MakeStringError.new).user_words).to eql('')
270
- expect(RTesseract.new(@image_tif, user_patterns: MakeStringError.new).user_patterns).to eql('')
271
-
272
- # expect(RTesseract.new(@path.join('images', 'test_words.png').to_s, psm: 3, user_words: @path.join('configs', 'eng.user-words.txt').to_s).to_s).to eql("If you are a friend,\nyou speak the password,\nand the doors will open.\n\n")
273
- end
274
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- require 'rspec'
5
- require 'coveralls'
6
- require 'simplecov'
7
- SimpleCov.start do
8
- add_filter '/spec/'
9
- end
10
- Coveralls.wear!
11
-
12
- require 'rtesseract'
13
- # Requires supporting files with custom matchers and macros, etc,
14
- # in ./support/ and its subdirectories.
15
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
16
-
17
- RSpec.configure do # |config|
18
- end