Tesseract Installation Guidance for access by OpenCV build under Ubuntu 23.10

I need to use the Tesseract functionality for OCR with OpenCV. Steps that I have performed are:

  • Browsed for similar topics; couldn’t reproduce the recommendations from the one dated Sept 2022, owing perhaps to my incompetence.
  • Installed tesseract-ocr, leptonica-dev, etc using apt; no tesseract include files were installed, so in my naive wisdom I uninstalled these packages promptly.
  • Built OpenCV v.4.6.0 from GitHub repository using mostly defaults in ccmake/cmake
  • Specified EXTRA_CONTRIB and WITH_TESSERACT but Tesseract was not installed
  • Installed Leptonica from GitHub using website guidance (i.e. only include files seem to have been installed:
reza@BeUlta:~/projects$ which leptonica
reza@BeUlta:~/projects$ locate leptonica
/usr/include/leptonica
/usr/include/leptonica/allheaders.h
...
/usr/share/doc/libleptonica-dev/version-notes.html
/var/lib/dpkg/info/libleptonica-dev.list
/var/lib/dpkg/info/libleptonica-dev.md5sums
  • Cloned Tesseract from GitHub but did not build/install it.
  • Used the well trodden ccmake/cmake approach for OpenCV but don’t know how OpenCV will use this clone since it presumably expects Tesseract to be built in advance (the three Tesseract parameters are all set to NOT FOUND) for use during the OpenCV build process(es).

Don’t know how to proceed with the next steps! :face_with_raised_eyebrow: I need access to <tesseract/baseapi.h> for a simple Hello Text C++ sample test.

There are some dated docs for the Windows platform, but I’m on Ubuntu 23.10. Can someone point me in the right direction so that the OpenCV OCR samples will work for me? Thanks.

Regards.

So install tesseract and leptonica from github build and install using cmake
then install opencv and opencv_contrib from github. use cmake and check that tesseract is detected in cmake output

1 Like

Yes, @laurent.berger, you are correct!

I did that exactly last night and everything worked step-by-step. Your reassurance (because the OpenCV ccmake only detected the Tesseract_DIR value) is very helpful because now I am on the right track.

Tesseract_DIR                    /usr/local/lib/cmake/tesseract
Tesseract_INCLUDE_DIR NOT FOUND
Tesseract_LIBRARY           NOT FOUND

I rebuilt OpenCV and my sample test program that had an include directive for baseapi.h that was successfully read. Unless you have further comment or observation on the NOT FOUND settings for the 2nd and 3rd parameter, I consider the issue resolved to my satisfaction. Of course, I still have to do some more browsing and reading to understand the details beneath the covers, but at least the sample code works! Thanks again because I understand it gets tedious helping out newbies like myself, but I want you to know that your dedication helps countless others.

Regards.

1 Like