build QT and Tesseract on Windows 10

447 views
Skip to first unread message

Fish Money

unread,
May 30, 2022, 5:19:54 AM5/30/22
to tesseract-ocr

Hello! How can i amend the pro file to make the program work?

Googled a lot about QT and Tesseract, could not find a solution yet.

QT += core
QT -= gui

CONFIG += c++11

TARGET = openCV
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app
INCLUDEPATH += C:\opencv\release\install\include

LIBS += C:\opencv\release\bin\libopencv_core455.dll
LIBS += C:\opencv\release\bin\libopencv_highgui455.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs455.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc455.dll
LIBS += C:\opencv\release\bin\libopencv_calib3d455.dll
LIBS += C:\opencv\release\bin\libopencv_features2d455.dll
LIBS += C:\opencv\release\bin\libopencv_video455.dll
LIBS += C:\opencv\release\bin\libopencv_videoio455.dll
LIBS += -L"(C:\Program Files(x86)\Tesseract-OCR)" -ltesseract

INCLUDEPATH += /usr/include/tesseract

INCLUDEPATH += C:\Program Files(x86)\Tesseract-OCR)

LIBS += C:\Program Files(x86)\Tesseract-OCR)

LIBS +=-LC:\Program Files(x86)\Tesseract-OCR)
-ltesseract.dll
-llept.dll

LIBS += -LC:\Qt\opencv_cv2\OPENCV1\build-qt\lib
-lopencv_calib3d249d
-lopencv_contrib249d
-lopencv_core249d
-lopencv_features2d249d
-lopencv_flann249d
-lopencv_gpu249d
-lopencv_highgui249d
-lopencv_imgproc249d
-lopencv_legacy249d
-lopencv_ml249d
-lopencv_nonfree249d
-lopencv_objdetect249d
-lopencv_ocl249d
-lopencv_photo249d
-lopencv_stitching249d
-lopencv_superres249d
-lopencv_ts249d
-lopencv_video249d
-lopencv_videostab249d

SOURCES += main.cpp

DEFINES += QT_DEPRECATED_WARNINGS

Errors:


still saying D:\PROG\May\Tesseract\main.cpp:1: error: tesseract/baseapi.h: No such file or directory
D:\PROG\May\Tesseract\main.cpp:1:10: fatal error: tesseract/baseapi.h: No such file or directory
1 | #include <tesseract/baseapi.h>
| ^~~~~~~~~~~~~~~~~~~~~


Might be incorrect install, because SW file and SW gui could not be executed.

Strongly need advice! 

Zdenko Podobny

unread,
May 31, 2022, 2:56:32 AM5/31/22
to tesser...@googlegroups.com
INCLUDEPATH += /usr/include/tesseract
This does not seem correct on windows.

error: tesseract/baseapi.h: No such file or directory
So you have installed tesseract header files?

You did not mention which compiler you used: "*.dll" indicates Visual studio, but what is in "C:\Program Files(x86)\Tesseract-OCR"?

Zdenko


po 30. 5. 2022 o 11:19 Fish Money <fishmo...@gmail.com> napísal(a):
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/923f5b9b-def7-4171-9ac6-d342a3a99dc9n%40googlegroups.com.

Fish Money

unread,
May 31, 2022, 11:00:13 AM5/31/22
to tesseract-ocr
I actually stuck, because I could not execute SW and SW_GUI files.
My tesseract folder contains in screen shot attached.

Dear Zdenko,
Is there any chance we can talk via WhatsApp?
Stuck so bad here in my project...
You gonna save my life :D

вторник, 31 мая 2022 г. в 13:56:32 UTC+7, zdenop:
tesseract_ver.png

Zdenko Podobny

unread,
May 31, 2022, 11:36:55 AM5/31/22
to tesser...@googlegroups.com
I am not sure why you mentioned SW, as your screenshot indicates you have installed gcc (mingw?) runtime libs:

image.png

Do you plan to build your project with mingw? Is opencv built with mingw too? You can not mix VS libraries with mingw libraries...
Also another part of your project file looks suspicious:
 "LIBS += C:\opencv\release\bin\libopencv_core455.dll" 
Do you know what are you there? Maybe you should start with a simple project to understand how to use external libraries...

 

Zdenko


ut 31. 5. 2022 o 17:00 Fish Money <fishmo...@gmail.com> napísal(a):

Fish Money

unread,
May 31, 2022, 12:37:09 PM5/31/22
to tesseract-ocr
I'm usuing mingw + openCV in my current project.
It has been built for work in QT IDE...

I just need to use OCR into my project and yet, could not find any instruction on internet.
I actually need to run the code below from QT...


What are my next steps to make this happen?
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
using namespace std;

int main()
{
    char *outText;

    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    // Initialize tesseract-ocr with English, without specifying tessdata path
    if (api->Init(NULL, "eng")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }

    // Open input image with leptonica library
    Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif");
    api->SetImage(image);
    // Get OCR result
    outText = api->GetUTF8Text();
    cout << ("OCR output:\n%s", outText);

    // Destroy used object and release memory
    api->End();
    delete api;
    delete [] outText;
    pixDestroy(&image);

    return 0;
}
вторник, 31 мая 2022 г. в 22:36:55 UTC+7, zdenop:

Zdenko Podobny

unread,
Jun 1, 2022, 1:57:58 PM6/1/22
to tesser...@googlegroups.com
You need to build tesseract and leptonica by yourself (+ needed dependencies) with MinGW. If I got it right - you have installed just runtime libraries, but for creating your app you need libraries useable for linking (and header files).

I am afraid the same you will need to do with OpenCV, as OpenCV just provides VS library which is not usable with MinGW[2],[1]
I really doubt this is worthy of time - it is better is to switch to Visual Studio on Windows (and you still can use Qt Creator)


ut 31. 5. 2022 o 18:37 Fish Money <fishmo...@gmail.com> napísal(a):

Дмитрий Кочкин

unread,
Jun 13, 2022, 2:22:14 PM6/13/22
to tesseract-ocr
Can you please help to install!
I could pay for your work

четверг, 2 июня 2022 г. в 00:57:58 UTC+7, zdenop:

Zdenko Podobny

unread,
Jun 13, 2022, 2:29:35 PM6/13/22
to tesser...@googlegroups.com
Do you really need mingw or can you use/switch to MSVC (which would make sense if you would like to use opencv)?

(IMO) In the case of MSVC you can download and you can try to use the artifact from Github Action "cmake-win64"
e.g.  https://github.com/tesseract-ocr/tesseract/actions/runs/2485126735 (an artifact is available for 5 days, but GA is run each night)...

Zdenko


po 13. 6. 2022 o 20:22 Дмитрий Кочкин <yky...@gmail.com> napísal(a):
Message has been deleted
Message has been deleted

Fish Money

unread,
Jun 14, 2022, 6:37:56 AM6/14/22
to tesseract-ocr
I have everything ready with current setup mingw-QT (QtCreator)-OpenCV

Can you please message me on Whatsap +79672508779
I really need your help! My project on hold for looooong time, and I'm too dumb to install it myself )


вторник, 14 июня 2022 г. в 01:29:35 UTC+7, zdenop:
Message has been deleted

Fish Money

unread,
Jun 14, 2022, 9:17:32 AM6/14/22
to tesseract-ocr
I passed first part of installation guide:

Build the latest library (using Software Network client)
  1. Download the latest SW (Software Network https://software-network.org/) client from https://software-network.org/client/.
  2. Run sw setup (may require administrator access)
  3. Run sw build org.sw.demo.google.tesseract.tesseract-master.

Now Im stuck here

Mingw-w64

Mingw-w64 allows building 32- or 64-bit executables for Windows. It can be used for native compilations on Windows, but also for cross compilations on Linux (which are easier and faster than native compilations). Most large Linux distributions already contain packages with the tools need for a cross build. Before building Tesseract, it is necessary to build some prerequisites.

For Debian and similar distributions (e. g. Ubuntu), the cross tools can be installed like that:

# Development environment targeting 32- and 64-bit Windows (required) apt-get install mingw-w64 # Development tools for 32- and 64-bit Windows (optional) apt-get install mingw-w64-tools

These prerequisites will be needed:


Tried to execute commands from shell and from QT Mingw commandline. Failed

'apt-get' is not recognized as an internal or external command,
operable program or batch file.

C:\Qt\6.2.3\mingw_64>bin


What should I do next?


вторник, 14 июня 2022 г. в 17:37:56 UTC+7, Fish Money:

Zdenko Podobny

unread,
Jun 14, 2022, 1:53:25 PM6/14/22
to tesser...@googlegroups.com
First of all - it seems you are not familiar with the tools you decide to use.  If you were able to build OpenCV with MinGW, building leptonica and tesseract should be a question of seconds for you...

Software Network is a tool similar to autotools or cmake and uses VS on windows, so you do not need to invest your time in it if you want to use mingw... 

I used QT Creator with MinGW years ago and I witch to VS, so I can not help you easily/quickly (anyway I am not available this week). Maybe better would be to follow the steps at msys2 GitHub action: https://github.com/tesseract-ocr/tesseract/actions/runs/2496886885/workflow - I think it creates leptonica and tesseract compatible with MinGW...

If it is problem, I suggest this:
AFAIK the latest QT creator is able to import and use cmake project. libzip, libpng, leptonica and tesseract have cmake configuration, so can import it and build them within QT Creator with the desired compiler... You do not need more libs/dependencies, you do not need to create training tools...

Zdenko


ut 14. 6. 2022 o 15:17 Fish Money <fishmo...@gmail.com> napísal(a):

Fish Money

unread,
Jun 17, 2022, 12:35:54 PM6/17/22
to tesseract-ocr
Now, im stuck here!
Configuration is done.
You can now build tesseract by running:

% make
 /bin/sh ./config.status
config.status: creating Makefile
config.status: creating tesseract.pc
config.status: creating api/Makefile
config.status: creating ccmain/Makefile
config.status: creating ccstruct/Makefile
config.status: creating ccutil/Makefile
config.status: creating classify/Makefile
config.status: creating cube/Makefile
config.status: creating cutil/Makefile
config.status: creating dict/Makefile
config.status: creating image/Makefile
config.status: creating neural_networks/runtime/Makefile
config.status: creating textord/Makefile
config.status: creating viewer/Makefile
config.status: creating wordrec/Makefile
config.status: creating training/Makefile
config.status: creating tessdata/Makefile
config.status: creating tessdata/configs/Makefile
config.status: creating tessdata/tessconfigs/Makefile
config.status: creating testing/Makefile
config.status: creating java/Makefile
config.status: creating java/com/Makefile
config.status: creating java/com/google/Makefile
config.status: creating java/com/google/scrollview/Makefile
config.status: creating java/com/google/scrollview/events/Makefile
config.status: creating java/com/google/scrollview/ui/Makefile
config.status: creating doc/Makefile
config.status: creating config_auto.h
config.status: executing libtool commands
config.status: executing depfiles commands
make  all-recursive
make[1]: Entering directory `/D/libs/tesseract'
Making all in ccutil
make[2]: Entering directory `/D/libs/tesseract/ccutil'
make[3]: Entering directory `/D/libs/tesseract/ccutil'
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -D__BLOB_T_DEFINED -O3 -DNDEBUG  -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/  -D__MSW32__-O2 -MT basedir.lo -MD -MP -MF .deps/basedir.Tpo -c -o basedir.lo basedir.cpp
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -D__BLOB_T_DEFINED -O3 -DNDEBUG  -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/  -D__MSW32__-O2 -MT bits16.lo -MD -MP -MF .deps/bits16.Tpo -c -o bits16.lo bits16.cpp
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -D__BLOB_T_DEFINED -O3 -DNDEBUG  -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/  -D__MSW32__-O2 -MT bitvector.lo -MD -MP -MF .deps/bitvector.Tpo -c -o bitvector.lo bitvector.cpp
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -D__BLOB_T_DEFINED -O3 -DNDEBUG  -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/  -D__MSW32__-O2 -MT ccutil.lo -MD -MP -MF .deps/ccutil.Tpo -c -o ccutil.lo ccutil.cpp
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT basedir.lo -MD -MP -MF .deps/basedir.Tpo -c basedir.cpp  -DDLL_EXPORT -DPIC -o .libs/basedir.o
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT bits16.lo -MD -MP -MF .deps/bits16.Tpo -c bits16.cpp  -DDLL_EXPORT -DPIC -o .libs/bits16.o
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT bitvector.lo -MD -MP -MF .deps/bitvector.Tpo -c bitvector.cpp  -DDLL_EXPORT -DPIC -o .libs/bitvector.olibtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT ccutil.lo -MD -MP -MF .deps/ccutil.Tpo -c ccutil.cpp  -DDLL_EXPORT -DPIC -o .libs/ccutil.o
<command-line>:0:10: warning: ISO C++11 requires whitespace after the macro name
<command-line>:0:10: warning: ISO C++11 requires whitespace after the macro name
<command-line>:0:10: warning: ISO C++11 requires whitespace after the macro name
<command-line>:0:10: warning: ISO C++11 requires whitespace after the macro name
In file included from strngs.h:23:0,
                 from basedir.h:24,
                 from basedir.cpp:20:
d:\mingw\include\stdio.h:345:12: error: expected initializer before '__mingw__snprintf'
 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
            ^
d:\mingw\include\stdio.h:349:12: error: expected initializer before '__mingw__vsnprintf'
 extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST);
            ^
make[3]: *** [basedir.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT bits16.lo -MD -MP -MF .deps/bits16.Tpo -c bits16.cpp -o bits16.o >/dev/null 2>&1
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT bitvector.lo -MD -MP -MF .deps/bitvector.Tpo -c bitvector.cpp -o bitvector.o >/dev/null 2>&1
mv -f .deps/bits16.Tpo .deps/bits16.Plo
mv -f .deps/bitvector.Tpo .deps/bitvector.Plo
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -D__BLOB_T_DEFINED -O3 -DNDEBUG -I../vs2008/port -DWINDLLNAME=\"libtesseract\" -I/mingw/include/leptonica -DTESSDATA_PREFIX=/mingw/share/ -D__MSW32__-O2 -MT ccutil.lo -MD -MP -MF .deps/ccutil.Tpo -c ccutil.cpp -o ccutil.o >/dev/null 2>&1
mv -f .deps/ccutil.Tpo .deps/ccutil.Plo
make[3]: Leaving directory `/D/libs/tesseract/ccutil'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/D/libs/tesseract/ccutil'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/D/libs/tesseract'
make: *** [all] Error 2

/D/libs/tesseract
$

Building Mingw with command line

среда, 15 июня 2022 г. в 00:53:25 UTC+7, zdenop:

Zdenko Podobny

unread,
Jun 17, 2022, 4:02:14 PM6/17/22
to tesser...@googlegroups.com
What version of tesseract do you try to compile? There is no basedir.cpp basedir.h in current code.

The error comes from MinGW - compiler you choose to use:
d:\mingw\include\stdio.h:345:12: error: expected initializer before '__mingw__snprintf'
 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);

Zdenko


pi 17. 6. 2022 o 18:35 Fish Money <fishmo...@gmail.com> napísal(a):

Fish Money

unread,
Jun 25, 2022, 5:18:05 AM6/25/22
to tesser...@googlegroups.com
I ve tried a lot of tutorials from web (probably tried all)
I successfully installed cygwin and tesseract, but could not compile tesseract libs
Passed all 30 points, but QT could not find include/baseapi...
Linux is fine, but I could not use Linux in my current project...
MinGW-32 installed successfully, could execute tesseract with cmd, but could not link with include/base.api as well ( https://kostyakulakov.ru/en/tesseract-ocr-mingw/)
Still need help, feel desperate :)
Can we talk by Whatsapp, please?


пт, 17 июн. 2022 г. в 23:35, Fish Money <fishmo...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages