4

I built Tesseract 3.04.01 on Cygwin. It can recognize .bmp files, but it fails on .png files:

$ tesseract.exe testing/phototest.png output
Tesseract Open Source OCR Engine v3.04.01 with Leptonica
Error in pixReadMemPng: function not present
Error in pixReadMem: png: no pix returned
Error during processing.

I thought that leptopnica added support for png?

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

4

After some more digging, it turned out that leptonica is more like a wrapper around standard libraries like libpng and libtiff, and it will silently disable support for an image type if its lib can't be found.

It was giving me this when running ./configure:

checking for png_read_png in -lpng... no

So I had to download and build libpng. After that it still didn't work, because libpng installed in /usr/local/lib, and apparently that is not a default library path for cygwin. So I had to use add it using LDFLAGS:

LDFLAGS=-L/usr/local/lib ./configure

After that it finally built with PNG support, giving this message:

checking for png_read_png in -lpng... yes

For some reason the link order of was mixed up in the Makefile - -lpng -lz, which caused linking liblept.la to fail with:

png.c:(.text+0x13ab): undefined reference to `crc32'

The only way I could fix that was by running make V=1 (verbose mode) to see the actual command, which was:

make[2]: Entering directory '/home/sasho/leptonica-1.73/src'
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2 -no-undefined -version-info 5:0:0 -Wl,--as-needed -L/usr/local/lib -o liblept.la -rpath /usr/local/lib adaptmap.lo affine.lo affinecompose.lo arrayaccess.lo bardecode.lo baseline.lo bbuffer.lo bilateral.lo bilinear.lo binarize.lo binexpand.lo binreduce.lo blend.lo bmf.lo bmpio.lo bmpiostub.lo bootnumgen1.lo bootnumgen2.lo boxbasic.lo boxfunc1.lo boxfunc2.lo boxfunc3.lo boxfunc4.lo bytearray.lo ccbord.lo ccthin.lo classapp.lo colorcontent.lo coloring.lo colormap.lo colormorph.lo colorquant1.lo colorquant2.lo colorseg.lo colorspace.lo compare.lo conncomp.lo convertfiles.lo convolve.lo correlscore.lo dewarp1.lo dewarp2.lo dewarp3.lo dewarp4.lo dnabasic.lo dwacomb.2.lo dwacomblow.2.lo edge.lo encoding.lo enhance.lo fhmtauto.lo fhmtgen.1.lo fhmtgenlow.1.lo finditalic.lo flipdetect.lo fliphmtgen.lo fmorphauto.lo fmorphgen.1.lo fmorphgenlow.1.lo fpix1.lo fpix2.lo gifio.lo gifiostub.lo gplot.lo graphics.lo graymorph.lo grayquant.lo grayquantlow.lo heap.lo jbclass.lo jp2kheader.lo jp2kheaderstub.lo jp2kio.lo jp2kiostub.lo jpegio.lo jpegiostub.lo kernel.lo leptwin.lo libversions.lo list.lo map.lo maze.lo morph.lo morphapp.lo morphdwa.lo morphseq.lo numabasic.lo numafunc1.lo numafunc2.lo pageseg.lo paintcmap.lo parseprotos.lo partition.lo pdfio1.lo pdfio1stub.lo pdfio2.lo pdfio2stub.lo pix1.lo pix2.lo pix3.lo pix4.lo pix5.lo pixabasic.lo pixacc.lo pixafunc1.lo pixafunc2.lo pixalloc.lo pixarith.lo pixcomp.lo pixconv.lo pixlabel.lo pixtiling.lo pngio.lo pngiostub.lo pnmio.lo pnmiostub.lo projective.lo psio1.lo psio1stub.lo psio2.lo psio2stub.lo ptabasic.lo ptafunc1.lo ptra.lo quadtree.lo queue.lo rank.lo rbtree.lo readbarcode.lo readfile.lo recogbasic.lo recogdid.lo recogident.lo recogtrain.lo regutils.lo rop.lo ropiplow.lo roplow.lo rotate.lo rotateam.lo rotateamlow.lo rotateorth.lo rotateshear.lo runlength.lo sarray.lo scale.lo scalelow.lo seedfill.lo seedfilllow.lo sel1.lo sel2.lo selgen.lo shear.lo skew.lo spixio.lo stack.lo stringcode.lo sudoku.lo textops.lo tiffio.lo tiffiostub.lo utils.lo viewfiles.lo warper.lo watershed.lo webpio.lo webpiostub.lo writefile.lo zlibmem.lo zlibmemstub.lo  -lz -lpng       

I then executed the same command (from ./src as the current directory or it won't work), but I appended another -lz at the end, which caused it to succeed. After that I just reran make, and it continued building the rest of the library.

cd src
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2 -no-undefined -version-info 5:0:0 -Wl,--as-needed -L/usr/local/lib -o liblept.la -rpath /usr/local/lib adaptmap.lo affine.lo affinecompose.lo arrayaccess.lo bardecode.lo baseline.lo bbuffer.lo bilateral.lo bilinear.lo binarize.lo binexpand.lo binreduce.lo blend.lo bmf.lo bmpio.lo bmpiostub.lo bootnumgen1.lo bootnumgen2.lo boxbasic.lo boxfunc1.lo boxfunc2.lo boxfunc3.lo boxfunc4.lo bytearray.lo ccbord.lo ccthin.lo classapp.lo colorcontent.lo coloring.lo colormap.lo colormorph.lo colorquant1.lo colorquant2.lo colorseg.lo colorspace.lo compare.lo conncomp.lo convertfiles.lo convolve.lo correlscore.lo dewarp1.lo dewarp2.lo dewarp3.lo dewarp4.lo dnabasic.lo dwacomb.2.lo dwacomblow.2.lo edge.lo encoding.lo enhance.lo fhmtauto.lo fhmtgen.1.lo fhmtgenlow.1.lo finditalic.lo flipdetect.lo fliphmtgen.lo fmorphauto.lo fmorphgen.1.lo fmorphgenlow.1.lo fpix1.lo fpix2.lo gifio.lo gifiostub.lo gplot.lo graphics.lo graymorph.lo grayquant.lo grayquantlow.lo heap.lo jbclass.lo jp2kheader.lo jp2kheaderstub.lo jp2kio.lo jp2kiostub.lo jpegio.lo jpegiostub.lo kernel.lo leptwin.lo libversions.lo list.lo map.lo maze.lo morph.lo morphapp.lo morphdwa.lo morphseq.lo numabasic.lo numafunc1.lo numafunc2.lo pageseg.lo paintcmap.lo parseprotos.lo partition.lo pdfio1.lo pdfio1stub.lo pdfio2.lo pdfio2stub.lo pix1.lo pix2.lo pix3.lo pix4.lo pix5.lo pixabasic.lo pixacc.lo pixafunc1.lo pixafunc2.lo pixalloc.lo pixarith.lo pixcomp.lo pixconv.lo pixlabel.lo pixtiling.lo pngio.lo pngiostub.lo pnmio.lo pnmiostub.lo projective.lo psio1.lo psio1stub.lo psio2.lo psio2stub.lo ptabasic.lo ptafunc1.lo ptra.lo quadtree.lo queue.lo rank.lo rbtree.lo readbarcode.lo readfile.lo recogbasic.lo recogdid.lo recogident.lo recogtrain.lo regutils.lo rop.lo ropiplow.lo roplow.lo rotate.lo rotateam.lo rotateamlow.lo rotateorth.lo rotateshear.lo runlength.lo sarray.lo scale.lo scalelow.lo seedfill.lo seedfilllow.lo sel1.lo sel2.lo selgen.lo shear.lo skew.lo spixio.lo stack.lo stringcode.lo sudoku.lo textops.lo tiffio.lo tiffiostub.lo utils.lo viewfiles.lo warper.lo watershed.lo webpio.lo webpiostub.lo writefile.lo zlibmem.lo zlibmemstub.lo  -lz -lpng -lz      
cd -
make
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 1
    why you are not using the standard `libpng16-devel` package for compilation instead of building it by yourself ?. PS: cygwin also has a tesseract 3.04.01 package. – matzeri Jul 01 '16 at 16:32
  • @matzeri Because I don't know where to get it from. I don't know what command to type to get it. There was no `apt-get`. – sashoalm Jul 01 '16 at 16:47
  • The standard tool : Use Setup `https://cygwin.com/cygwin-ug-net/setup-net.html#setup-packages` – matzeri Jul 01 '16 at 17:06
  • 1
    I'm adding a section on "Common Linking Failures" to the libpng INSTALL document. Among other things it mentions the need to have "-lpng -lz" in the right order. – Glenn Randers-Pehrson Jul 02 '16 at 14:12
3

When the above error occurs, it may be not installing libpng-devel before compiling and installing leptonica. you can try

yum install libpng-devel

then compiling and installing leptonica

cd leptonica/ make clean ./configure make make install It's work on my centos7.

pinetree
  • 61
  • 1