ruby-tesseract-ocr icon indicating copy to clipboard operation
ruby-tesseract-ocr copied to clipboard

Could not open library

Open movihus opened this issue 11 years ago • 15 comments

I'm trying to deploy an application that uses tesseract-ocr with passenger and when I open the website I see this error: Could not open library '/tmp/.ffi-inline-500/985899750dd2ded7660e51be030ff964c9d21dc8.so': libtesseract.so.3: cannot open shared object file: No such file or directory (LoadError)

I have installed: tesseract 3.02.02 leptonica-1.70 libjpeg 6b : libpng 1.2.49 : libtiff 3.9.4 : zlib 1.2.3

What could I do?. Thanks in advance.

movihus avatar Feb 21 '14 19:02 movihus

I'm using rbenv 0.4.0-89-g14bc162 with ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux] on a CentOS release 6.4

movihus avatar Feb 21 '14 19:02 movihus

I have run sudo ldconfig after installing tesseract but I get the same error

movihus avatar Feb 21 '14 19:02 movihus

Is the file actually present?

Is the LDPATH environment variable proper?

meh avatar Feb 24 '14 03:02 meh

After a lot of work I could run the web app, but now I possibly discovered a bug. I got this output when I want to use Tesseract::Engine

index >= 0 && index < size_used_:Error:Assert failed:in file ../ccutil/genericvector.h, line 512 /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.5/lib/tesseract/api.rb:157: [BUG] Segmentation fault ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

All the trace here https://gist.github.com/movihus/226e7a4f49ff4fc6ad0e#file-gistfile1-txt

movihus avatar Feb 24 '14 15:02 movihus

What's the code that caused it?

meh avatar Feb 24 '14 18:02 meh

I tried with this code:

path = 'image.jpg'
engine = Tesseract::Engine.new()
result = engine.text_for(path)

movihus avatar Feb 24 '14 18:02 movihus

Could you post the image as well please?

meh avatar Feb 24 '14 18:02 meh

I tried with different images, for example this: eurotext

movihus avatar Feb 24 '14 18:02 movihus

I pushed a new gem version since it works for me on master, can you try with this new version please?

meh avatar Feb 24 '14 18:02 meh

I installed and now I have compilation errors:

g++ -shared -fPIC -o /tmp/.ffi-inline-500/f6b0bffaa19644042f282b7bf04377398eed387c.so /tmp/.ffi-inline-500/f6b0bffaa19644042f282b7bf04377398eed387c.cpp -ltesseract 2>>/tmp/.ffi-inline-500/f6b0bffaa19644042f282b7bf04377398eed387c.log /tmp/.ffi-inline-500/f6b0bffaa19644042f282b7bf04377398eed387c.cpp:1:30: error: tesseract/strngs.h: No existe el fichero o el directorio /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:57: error: expected constructor, destructor, or type conversion before ‘*’ token /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:63: error: se declaró la variable o campo ‘destroy_string’ como void /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:63: error: ‘STRING’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:63: error: ‘value’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:69: error: ‘STRING’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:69: error: ‘value’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:69: error: expected ‘,’ or ‘;’ before ‘{’ token /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:75: error: ‘STRING’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:75: error: ‘value’ no se declaró en este ámbito /home/deployer/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/tesseract-ocr-0.1.6/lib/tesseract/c.rb:75: error: expected ‘,’ or ‘;’ before ‘{’ token

I found this thread https://github.com/meh/ruby-tesseract-ocr/issues/7, but it supposses I installed the tesseract-devel package, I use this method: https://github.com/grossws/tesseract-ocr-specs

yum list | grep tesseract* tesseract.x86_64 3.02-1.el6 @/tesseract-3.02-1.el6.x86_64 tesseract-devel.x86_64 3.02-1.el6 @/tesseract-devel-3.02-1.el6.x86_64

yum list | grep leptonica* leptonica.x86_64 1.69-1.el6 @/leptonica-1.69-1.el6.x86_64 leptonica-devel.x86_64 1.69-1.el6 @/leptonica-devel-1.69-1.el6.x86_64

movihus avatar Feb 24 '14 18:02 movihus

I think I missed the issue, https://github.com/meh/ruby-tesseract-ocr/issues/3 is the correct

movihus avatar Feb 24 '14 19:02 movihus

I found the headers in /home/makerpm/rpmbuild/BUILD/tesseract-ocr/ccutil/, copy it to /home/deployer/rpmbuild/BUILD/tesseract-ocr/ccutil/ (to have the correct permissions), modified my ~/.bashrc adding:

export CFLAGS=-I/home/deployer/rpmbuild/BUILD/tesseract-ocr/ccutil/

And the libs copied to /home/deployer/rpmbuild/BUILD/tesseract-ocr/api/.libs and then added to .bashrc

export LDFLAGS=-L/home/deployer/rpmbuild/BUILD/tesseract-ocr/api/.libs

But when I try to access the console througth rails console I get the same error.

What I'm doing wrong?.

movihus avatar Feb 24 '14 19:02 movihus

I don't know, I don't use the system you use.

meh avatar Feb 24 '14 20:02 meh

For me compiling and installing the latest Leptonica http://leptonica.org/download.html fixed this. The apt-get repository version won't suffice.

danielpclark avatar May 25 '14 02:05 danielpclark

Solution for Redhat installation of leptonica and tesseract with the correct arguments to make it run

inspired from this .sh install file which did not work completely for me

yum -y update
yum -y install libstdc++ autoconf automake libtool autoconf-archive pkg-config gcc gcc-c++ make libjpeg-devel libpng-devel libtiff-devel zlib-devel

#Install AutoConf-Archive
wget ftp://mirror.switch.ch/pool/4/mirror/epel/7/ppc64/a/autoconf-archive-2016.09.16-1.el7.noarch.rpm
rpm -i autoconf-archive-2016.09.16-1.el7.noarch.rpm

# install leptonica from github
wget https://github.com/DanBloomberg/leptonica/archive/v1.72.tar.gz
tar -zxvf v1.72.tar.gz
cd leptonica-1.72
chmod +x configure # this is only if you have permission problems.
./configure --prefix=$HOME/local/
make
make install
cd ..

# install tesseract from github
wget https://github.com/tesseract-ocr/tesseract/archive/3.04.01.tar.gz
tar -zxvf 3.04.01.tar.gz
cd tesseract-3.04.01/
./autogen.sh
LIBLEPT_HEADERSDIR=$HOME/local/include ./configure --prefix=$HOME/local/ --with-extra-libraries=$HOME/local/lib
make
make install
LD_LIBRARY_PATH=#{home_dir}/local/lib CFLAGS=-I#{home_dir}/local/include LDFLAGS=-L#{home_dir}/local/lib bundle exec irb -r 'tesseract'
# you should see no errors

This will solve this issue and issue #3

I might be important to add $HOME/local/lib into /etc/ld.so.conf and run sudo ldconfig

pgericson avatar Jul 25 '17 15:07 pgericson