Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error setting up the tesseract OCR in gem in rails #24

Closed
seanhinton opened this issue Nov 12, 2013 · 21 comments
Closed

Error setting up the tesseract OCR in gem in rails #24

seanhinton opened this issue Nov 12, 2013 · 21 comments

Comments

@seanhinton
Copy link

I'm trying to setup the tesseract-ocr gem in my rails environment. I have ran brew install tesseract and then ran a bundle install on the app and that all runs without errors however when starting the app (rails s) the following error is throw:

/Users/xxxx/.rvm/gems/ruby-1.9.2-p290@xxxx/gems/ffi-inline-0.0.4.3/lib/ffi/inline/compilers/gcc.rb:35:in `compile': compile error: see logs at /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.log (CompilationError)

It reference the following log file:

g++ -dynamic -bundle -fPIC  -L/usr/local/Cellar/tesseract/3.02.02/lib -I/usr/local/Cellar/tesseract/3.02.02/include -o /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.dylib /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.cpp -llept 2>>/var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.log
/var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.cpp:1:10: fatal error: 'leptonica/allheaders.h' file not found
#include <leptonica/allheaders.h>

I followed these two issues:
#3 and #21

It talks about setting ENV vars which i have done. I created a test.rb file in the initalizers folder with the following vars set:

ENV['CFLAGS'] = '-I/usr/local/Cellar/tesseract/3.02.02/include' 
ENV['LDFLAGS'] = '-L/usr/local/Cellar/tesseract/3.02.02/lib'

However this makes no difference to the error when starting the app.

I don't understand what it means when it says update the headers. I was wondering if someone could tell me exactly what to do to get this working.

Thanks.

@meh
Copy link
Owner

meh commented Nov 12, 2013

Are the environment variables set before the gem is required?

@seanhinton
Copy link
Author

Hi, thanks for replying, here's some more details to answer you question...

I haven't put 'require' anywhere yet because the rails server is throwing the error on start up.

The only place 'tesseract-ocr' is referenced is in the Gemfile and the Gemfile.lock file.

The ENV vars are sat in the initializer folder. However I tried putting them in the application.rb before the rails app is initialized and even putting them at the start of the Gemfile before gem tesseract-ocr but that made no difference.

@meh
Copy link
Owner

meh commented Nov 12, 2013

I don't know much about rails, so I don't know when it runs the Bundler.required, but you should try exporting the env variables in the shell before starting the rails app.

@seanhinton
Copy link
Author

I tried running:

export CFLAGS=-I/usr/local/Cellar/tesseract/3.02.02/include
export LDFLAGS=-L/usr/local/Cellar/tesseract/3.02.02/lib

In the shell before running 'rails s' however that still threw the same error on start up.

I don't know if this is relevant but I'm on Mavericks.

@meh
Copy link
Owner

meh commented Nov 12, 2013

Could you give me the output of find /usr/local/Cellar/tesseract/3.02.02/include please?

@seanhinton
Copy link
Author

Sure it's:

/usr/local/Cellar/tesseract/3.02.02/include
/usr/local/Cellar/tesseract/3.02.02/include/tesseract
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/apitypes.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/baseapi.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/basedir.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/capi.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/errcode.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/fileerr.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/genericvector.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/helpers.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/host.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/ltrresultiterator.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/memry.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/ndminx.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/pageiterator.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/params.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/platform.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/publictypes.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/resultiterator.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/serialis.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/strngs.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/tesscallback.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/thresholder.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/unichar.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/unicharmap.h
/usr/local/Cellar/tesseract/3.02.02/include/tesseract/unicharset.h

@meh
Copy link
Owner

meh commented Nov 12, 2013

Oh right, it was looking for the leptonica headers, I think you have to also add the path to leptonica.

@seanhinton
Copy link
Author

Ok, how do I do that? Do I first need to brew install leptonica too? (thanks for your help by the way)

@meh
Copy link
Owner

meh commented Nov 12, 2013

No, it's a dependency of tesseract, it should have installed it along, you just have to find where it put it.

@seanhinton
Copy link
Author

I did a locate and found /usr/local/Library/Formula/leptonica.rb and brew says it's already installed.

Sorry about all the questions, now where do I put the reference to '/usr/local/Library/Formula/leptonica.rb' does this need another env var?

@meh
Copy link
Owner

meh commented Nov 12, 2013

It's not that one, it should have its own include dir like tesseract, try installing it tho.

@seanhinton
Copy link
Author

I've brew re-installed leptonica and it has it's own dir like tesseract now in '/usr/local/Cellar/leptonica/1.69' with a lib and bin, however the error is still getting throw.

@meh
Copy link
Owner

meh commented Nov 12, 2013

So there's no include dir? The error is thrown because it can't find leptonica's headers.

Try running a locate for allheaders.h (and make sure to updatedb, or use find instead).

@seanhinton
Copy link
Author

Yep, there's an include folder too with those files in it:

/usr/local/Cellar/leptonica/1.69/include/leptonica
/usr/local/Cellar/leptonica/1.69/include/leptonica/allheaders.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/alltypes.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/array.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/arrayaccess.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/bbuffer.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/bmf.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/bmp.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/ccbord.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/dewarp.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/endianness.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/environ.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/gplot.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/heap.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/imageio.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/jbclass.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/leptwin.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/list.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/morph.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/pix.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/ptra.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/queue.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/readbarcode.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/regutils.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/stack.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/sudoku.h
/usr/local/Cellar/leptonica/1.69/include/leptonica/watershed.h

So that's all there too.

@meh
Copy link
Owner

meh commented Nov 12, 2013

Then just add those paths to the two env vars too.

@seanhinton
Copy link
Author

Thanks!

That's it, perfect! My guess is this is Mavericks related.

Just incase anyone else has a problem here's exactly how it was fixed in mine:

Firstly had to run both:
brew install tesseract
and
brew install leptonica

Then in the Gemfile NOT in an initializer you have to put both paths to the libraries as env vars:

ENV['CFLAGS'] = '-I/usr/local/Cellar/tesseract/3.02.02/include -I/usr/local/Cellar/leptonica/1.69/include'
ENV['LDFLAGS'] = '-L/usr/local/Cellar/tesseract/3.02.02/lib -L/usr/local/Cellar/leptonica/1.69/lib'

@meh
Copy link
Owner

meh commented Nov 12, 2013

Thanks for summing it up.

@meh meh closed this as completed Nov 12, 2013
@ExReanimator
Copy link

Hi guys!
I have the same problem, but this solution doesn't work.

ENV['CFLAGS'] = '-I/usr/local/Cellar/tesseract/3.04.00/include -I/usr/local/Cellar/leptonica /1.72/include'
ENV['LDFLAGS'] = '-L/usr/local/Cellar/tesseract/3.04.00/lib -L/usr/local/Cellar/leptonica/1.72/lib'

@ExReanimator
Copy link

Maybe it's helpful.
In errors list I found a wrong path forming:

g++ -dynamic -bundle -fPIC  -L/usr/local/Cellar/tesseract/3.04.00/lib -L/usr/local/Cellar/leptonica/1.72/lib -I/usr/local/Cellar/tesseract/3.04.00/include -I/usr/local/Cellar/leptonica /1.72/include -o /var/folders/xg/g9n7qvns5z1gsr_yjh09n1nm0000gn/T/.ffi-inline-501/d2f8bb8a1867b800ff8ad69a3b850c91521b3760.dylib /var/folders/xg/g9n7qvns5z1gsr_yjh09n1nm0000gn/T/.ffi-inline-501/d2f8bb8a1867b800ff8ad69a3b850c91521b3760.cpp -ltesseract 2>>/var/folders/xg/g9n7qvns5z1gsr_yjh09n1nm0000gn/T/.ffi-inline-501/d2f8bb8a1867b800ff8ad69a3b850c91521b3760.log
clang: error: no such file or directory: '/1.72/include'

-I/usr/local/Cellar/leptonica**[unuseful space]**/1.72/include

@travisgalloway
Copy link

I have the same error with tesseract 3.04 and leptronica 1.72 installed via brew.

I tried setting the ENV flags according to above and reinstalling the ffi and ffi-inline gems.

The log file output:

g++ -dynamic -bundle -fPIC    -o /var/folders/b8/2plq0vx56hsb5_zxz7xqrgwc0000gn/T/.ffi-inline-501/8f22b8bfc158eaaf371cbe8a8112eaaa9ec0782d.dylib /var/folders/b8/2plq0vx56hsb5_zx$
/Users/travisgalloway/.rvm/gems/ruby-2.2.3/gems/tesseract-ocr-0.1.8/lib/tesseract/c/baseapi.rb:171:10: error: no matching member function for call to 'SetImage'
                                api->SetImage(pix);
                                ~~~~~^~~~~~~~
/usr/local/include/tesseract/baseapi.h:354:8: note: candidate function not viable: 1st argument ('const Pix *') would lose const qualifier
  void SetImage(Pix* pix);
       ^
/usr/local/include/tesseract/baseapi.h:341:8: note: candidate function not viable: requires 5 arguments, but 1 was provided
  void SetImage(const unsigned char* imagedata, int width, int height,
       ^
/Users/travisgalloway/.rvm/gems/ruby-2.2.3/gems/tesseract-ocr-0.1.8/lib/tesseract/c/baseapi.rb:183:49: error: cannot initialize a parameter of type 'tesseract::TessResultRendere$
                                return api->ProcessPages(filename, NULL, 0, output);
                                                                             ^~~~~~
/usr/local/include/tesseract/baseapi.h:542:63: note: passing argument to parameter 'renderer' here
                    int timeout_millisec, TessResultRenderer* renderer);
                                                              ^
/Users/travisgalloway/.rvm/gems/ruby-2.2.3/gems/tesseract-ocr-0.1.8/lib/tesseract/c/baseapi.rb:189:65: error: cannot initialize a parameter of type 'tesseract::TessResultRendere$
                                return api->ProcessPage(pix, page_index, filename, NULL, 0, output);
                                                                                            ^~~~~~
/usr/local/include/tesseract/baseapi.h:558:40: note: passing argument to parameter 'renderer' here
                   TessResultRenderer* renderer);
                                       ^
3 errors generated

Was there a breaking API change?

@nateklaiber
Copy link

@travisgalloway - I was able to past this by following the instructions found here.

brew uninstall tesseract
brew install https://raw.githubusercontent.com/Homebrew/homebrew/8ba134eda537d2cee7daa7ebdd9f728389d9c53e/Library/Formula/tesseract.rb

Then I had to updated my ENV variables to point to the new path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants