meh / ruby-tesseract-ocr

A Ruby wrapper library to the tesseract-ocr API.
629 stars 74 forks source link

Tesseract.prefix is not honoured #36

Closed whoward closed 10 years ago

whoward commented 10 years ago

Unfortunately it doesn't look like the API honours the environment variable or the assignment to Tesseract.prefix

irb> Tesseract.prefix = Rails.root.join("db","tessdata").to_s
irb> eng = Tesseract::Engine.new {|e| e.language = :eng }
Error opening data file /home/will/test-app/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
RuntimeError: the API did not Init correctly
from /home/will/.rvm/gems/ruby-2.0.0-p247@hipyard-web/gems/tesseract-ocr-0.1.6/lib/tesseract/api.rb:104:in `init'

I've made a quick monkey patch that does the job but I'd imagine you want a more elegant solution for a PR - so I'll just post this hack for now:

module Tesseract
  class API
    def init (datapath = nil, language = 'eng', mode = :DEFAULT)
      datapath = Tesseract.prefix
      unless C::BaseAPI.init(to_ffi, datapath, language.to_s, mode).zero?
        raise 'the API did not Init correctly'
      end
    end
  end
end
meh commented 10 years ago

That should have been dealt with internally by the tesseract-ocr library, but alas, fixed it on master.

Thanks.

daveslutzkin commented 9 years ago

Any chance of a new gem version with this change included?

meh commented 9 years ago

Ye, pushed a new version.

daveslutzkin commented 9 years ago

:+1: