2015-10-26 13:55:46 +00:00
|
|
|
require 'spec_helper'
|
2015-10-30 03:32:02 +00:00
|
|
|
require 'fileutils'
|
2016-02-28 09:39:59 +00:00
|
|
|
require 'tmpdir'
|
2015-10-26 13:55:46 +00:00
|
|
|
|
|
|
|
describe 'OCR' do
|
|
|
|
before do
|
2016-02-28 09:39:59 +00:00
|
|
|
@tmp_dir = Dir.mktmpdir
|
2015-10-26 13:55:46 +00:00
|
|
|
@samples = []
|
|
|
|
10.times do
|
|
|
|
@samples << SecureRandom.hex(2)
|
|
|
|
end
|
|
|
|
@filenames = []
|
|
|
|
@samples.each do |chars|
|
2016-02-28 09:39:59 +00:00
|
|
|
fname = File.join(@tmp_dir, "#{chars}.png")
|
2015-10-26 13:55:46 +00:00
|
|
|
img = RuCaptcha::Captcha.create(chars)
|
|
|
|
File.open(fname, 'w+') do |f|
|
|
|
|
f.puts img
|
|
|
|
end
|
|
|
|
@filenames << fname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2016-02-28 09:39:59 +00:00
|
|
|
FileUtils.rm_f(@tmp_dir)
|
2015-10-26 13:55:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not read by OCR lib' do
|
|
|
|
results = []
|
|
|
|
@samples.each do |chars|
|
2016-02-28 09:39:59 +00:00
|
|
|
str = RTesseract.new(File.join(@tmp_dir, "#{chars}.png"), processor: 'mini_magick').to_s
|
2015-10-26 13:55:46 +00:00
|
|
|
results << "- Chars: #{chars}, OCR read #{str.strip}"
|
|
|
|
expect(chars).not_to eq(str)
|
|
|
|
end
|
|
|
|
|
2015-10-29 10:22:27 +00:00
|
|
|
puts %(\n------------------------\nOCR all results: \n#{results.join("\n")})
|
2015-10-26 13:55:46 +00:00
|
|
|
end
|
|
|
|
end
|