2015-10-26 13:55:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'OCR' do
|
|
|
|
before do
|
|
|
|
@samples = []
|
|
|
|
10.times do
|
|
|
|
@samples << SecureRandom.hex(2)
|
|
|
|
end
|
|
|
|
@filenames = []
|
|
|
|
@samples.each do |chars|
|
|
|
|
fname = File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png")
|
|
|
|
img = RuCaptcha::Captcha.create(chars)
|
|
|
|
File.open(fname, 'w+') do |f|
|
|
|
|
f.puts img
|
|
|
|
end
|
|
|
|
@filenames << fname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
`rm #{File.join(File.dirname(__FILE__), '../tmp/*.png')}`
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not read by OCR lib' do
|
|
|
|
results = []
|
|
|
|
@samples.each do |chars|
|
|
|
|
str = RTesseract.new(File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png")).to_s
|
|
|
|
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
|