Getting started with tesseract-ocr in a web app.

3,105 views
Skip to first unread message

Clint William Theron

unread,
Sep 10, 2019, 5:55:45 PM9/10/19
to tesseract-ocr
Hey. How do I develop a web app using tesseract-ocr? For example, I would create an online UI with a "pick a file" button and when the user picks an image, from computer storage, the ocr process starts. I'll do the UI myself with html5 & JS code but I need assistance with tesseract-ocr. Like which files to upload and what to include in the script and then how to call the recognize method.

To give you an example of what I mean I'll demonstrate with a different tesseact project. The one from project naptha: I made a web app using this tutorial and I got to perform ocr on images. Everything works as expected. Now I want to do more or less the same thing with tesseract-ocr, the one from Google. I downloaded the tesseract-master.zip file, upload it to my web server and unzipped it. Since tesseract-ocr doesn't have a UI I don't know what to do next. There must be some file, script, I should include in my main script in order to call tesseract.recognize.

Even if my question doesn't make full sense I'm sure you have an idea of what I want to achieve. 

Thanks for any advice

René Hansen

unread,
Sep 11, 2019, 12:05:39 AM9/11/19
to tesser...@googlegroups.com
Hey Clint,


Theres a ton of different ways you could build a system such as that. It all comes down to your experience level with the different technologies involved.

E.g. if you know how to use the command-line version of tesseract, what you could do, is write a web application, that handles the image upload and then simply calls a shell script, which wraps the interaction with tesseract. This approach assumes you are familiar with building web applications in general, as well as how to shell out into e.g. bash.

Another approach could be to build your server backend completely in C++ and actually load tesseract as a library and do the processing inside of the same process, which will be hosting the web application.

I think the reason, you've not had much luck on the mailing list so far, is because there's really a huge number of assumptions needing to be made, before it's even possible to start answering your questions in earnest. You need to decide how you'd like to build your web application first. E.g. What web-server are you going to be using? What language and/or framework will you be writing the backend in? Saying html5 and JS doesn't really provide enough information. Do you mean you'll be writing Node.JS or do you mean you only have access to a static file web host?

Here's a question on Quora about doing a web application for OpenCV:

https://www.quora.com/How-do-I-use-opencv-image-processing-in-web-application

You might find some inspiration there and in the related questions.


/René







--
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/20d26401-4011-47a5-a3c2-b67bb33fa393%40googlegroups.com.


--
Never fear, Linux is here.

Clint William Theron

unread,
Sep 11, 2019, 4:48:59 PM9/11/19
to tesseract-ocr
Thanks René. I only have access to a static file web host. Below is a image describing the information of the server.

server_info.jpg



I usually write my back-end  scripts in PHP but if I have to I'll try C++. 

You said: 
"Another approach could be to build your server backend completely in C++ and actually load tesseract as a library and do the processing inside of the same process, which will be hosting the web application."

I think the best solution we can write, given everything you said, is the C++ back-end solution. So what should we do first? I'm assuming downloading the tesseract-master.zip file, upload it to the server and unzipping it. Is that correct? If yes, then what? Else?

Thanks in advance for an efficient solution.

Clint William Theron

unread,
Sep 12, 2019, 5:07:45 PM9/12/19
to tesseract-ocr
I really don't think my question is that hard to understand or broad. All I want to do is use tesseract-ocr in a web app on a apache http server like the one I'm referring to in the image above. I have tried to search for a working solution but I couldn't find anything useful. If I take the C++ as server backend approach how would I do that? 

Ps. If my question doesn't fall in the scope of questions I can ask here would you tell me what I can ask then? 

Thanks :-(

René Hansen

unread,
Sep 12, 2019, 6:02:08 PM9/12/19
to tesser...@googlegroups.com
Your question isn't hard to understand at all. A web app that does OCR using tesseract. Simple. It's figuring out *how* to explain it that's hard.


E.g., in your first email in this thread, you write:

"I downloaded the tesseract-master.zip file, upload it to my web server and unzipped it"

This sounds like you downloaded the source of tesseract from github and uploaded it to your static file hosted php web server? Please correct me if I'm wrong.

Obviously that wouldn't work for a slew of reasons. You cannot "run" C++ source code. It needs to be compiled into a program before you run it. PHP is a completely different programming paradigm in the sense that it's interpreted, and "runs" on Apache because it has an interpreter bundled with it.

The reason it's a hard question to answer is, that if something that fundamental is already misapprehended, the list of things you need to read up on beforehand is way outside the scope of single email.


/René



--
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.

Clint William Theron

unread,
Sep 12, 2019, 6:40:13 PM9/12/19
to tesseract-ocr
This sounds like you downloaded the source of tesseract from github and uploaded it to your static file hosted php web server? Please correct me if I'm wrong.
That's correct. 

What I'm understanding is that the next best approach would be a node.js server. I found a free node.js server on gitpod. Would you tell me how to go about the node.js approach? Would you also tell me is there no way to do this on the static file hosted php web server. I found this tutorial but I can't figure out how to implement it and if it's the tesseract-ocr from Google (not project naptha). 

Thanks :-)

Timothy Snyder

unread,
Sep 13, 2019, 9:13:47 AM9/13/19
to tesser...@googlegroups.com
All your web server has to do is facilitate command line calls to the Tesseract installation on your web server. The web server part is totally independent from Tesseract and as such, I think it exceeds the scope of this forum. Are you comfortable with developing client-server web applications? 

--
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.

Clint William Theron

unread,
Sep 13, 2019, 9:25:49 AM9/13/19
to tesseract-ocr
 Are you comfortable with developing client-server web applications? 
Yes.

I just need help implementing Tesseract. I know how to install it in Windows and call it from command line but I want to do it online. I don't know how to do it on a server so that the client can call it where server is any implementation where Tesseract is ready to receive OCR work and client is a browser sending a image for OCR.

Timothy Snyder

unread,
Sep 13, 2019, 10:07:28 AM9/13/19
to tesser...@googlegroups.com
Perfect. All you have to do is develop services on your server to receive images and send back OCR text. With whatever scripting language you are using on your server, just make a programmatic command line call to Tesseract with the uploaded image and send that text back to the user however you want.

--
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.

Lorenzo Bolzani

unread,
Sep 13, 2019, 10:59:27 AM9/13/19
to tesser...@googlegroups.com
Hi Clint,
after you install tesseract and tesseract libraries and tesseract dev libraries (using packages or from source) you can call it from your program. If you are using C++ just call it, if you are using other languages you need to find a wrapper/bindings library (for example tesserocr for python). Or you can call the "tesseract" executable as an external process from your program like you would do on command line.

It makes absolutely no difference if you are doing it from a web application or from a simple command line application. Google "tesseract YOUR_LANGUAGE library". The tesseract library for your language will give you the examples on how to use it.

I suppose you have the permissions to install software on the server you are using, globally (as root) or as local user. I would recommend using your distribution packages if possible.

If you cannot install software on the server you cannot use tesseract. Use Tesseract.js as you did. If you can only upload static files you cannot use tesseract. You need a process running server-side (PHP, Python, Node, ...).


Lorenzo



Clint William Theron

unread,
Sep 13, 2019, 2:02:57 PM9/13/19
to tesseract-ocr
Hey. I hope you have a pleasant time. 

I got the tesseract server up and running on gitpot, I think, so how do I call it now?

Below is an image illustrating the server...

download.png


Clint William Theron

unread,
Sep 13, 2019, 3:07:25 PM9/13/19
to tesser...@googlegroups.com
Do I call the tesseract command (tesseract image output) to the url in the image above?


On Friday, September 13, 2019, Clint William Theron <theroncli...@gmail.com> wrote:
> Hey. I hope you have a pleasant time. 
> I got the tesseract server up and running on gitpot, I think, so how do I call it now?
> Below is an image illustrating the server...
>
> </mail/u/0/s/?view=att&th=16d2bcaeffe8ee21&attid=0.1&disp=emb&realattid=f3c71d58-3b88-4780-a728-737381b279c1&zw&atsh=1>

>
> --
> 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/ee9d02dc-8c6b-4d41-9679-ee8a2cc9e31e%40googlegroups.com.
>

Clint William Theron

unread,
Sep 13, 2019, 5:40:29 PM9/13/19
to tesseract-ocr
I was wrong. The tesseract server is not yet running. There is still something I should do. Maybe installing  tesseract libraries and tesseract dev libraries like @Timothy suggested. The following image represent what I have tried but was unsuccessful: 

Untitled.png


Lorenzo Bolzani

unread,
Sep 14, 2019, 3:01:14 AM9/14/19
to tesser...@googlegroups.com
I googled "node.js tesseract".

Try one of these:


Just follow the instructions.


Tesseract does not run as a server, is a library.


Lorenzo


Il giorno ven 13 set 2019 alle ore 23:40 Clint William Theron <theroncli...@gmail.com> ha scritto:
I was wrong. The tesseract server is not yet running. There is still something I should do. Maybe installing  tesseract libraries and tesseract dev libraries like @Timothy suggested. The following image represent what I have tried but was unsuccessful: 

Untitled.png


--
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.

Clint William Theron

unread,
Sep 15, 2019, 9:23:57 PM9/15/19
to tesseract-ocr
Thanks @Lorenzo for making it clear that tesseract is not a server but a library and for the link. I still want to know how to start calling tesseract. In know this is not a place to ask about gitpot.io but do I need to set the environment variable because in gitpot.io is a feature to do that. Below is an image demonstrating my current level of progress...

Untitled.png

I just want to know where can I write the code to call the recognize method of tesseract. Thanks

Clint William Theron

unread,
Sep 16, 2019, 1:35:38 PM9/16/19
to tesseract-ocr
So I visited the pull request page of tesseract-ocr, copied the url, added a # in front of the url and concatenated it with the url of gitpot.io. This allowed me to auto install tesseract-ocr. Afterwards I ran those two commands in the link from @Lorenzo but I think the first one is redundant. I can see the node-tesseract-ocr folder in the project. Everything till here is presented in the image above. I'm lost now...what's next? 

Clint William Theron

unread,
Sep 16, 2019, 5:13:20 PM9/16/19
to tesseract-ocr
com'on guys, you might think this should be easy for me but it's not. I admit, I lack to see the simplicity. ;-)

Timothy Snyder

unread,
Sep 16, 2019, 5:22:23 PM9/16/19
to tesseract-ocr
Have you tried calling the tesseract executable from the command line yet? Can we confirm that you've successfully downloaded and compiled Tesseract?

Clint William Theron

unread,
Sep 16, 2019, 5:23:48 PM9/16/19
to tesseract-ocr
The question of this post is not really applicable anymore. For now I just want to do OCR with tesseract on a node.js server which I have on gitpod.io service. I said what I have done till now...

ps. What questions go through your mind while reading this that I omitted to answer that's preventing you from answering me?

Clint William Theron

unread,
Sep 16, 2019, 5:48:15 PM9/16/19
to tesseract-ocr
Have you tried calling the tesseract executable from the command line yet?

Like so: 

Untitled.png


Can we confirm that you've successfully downloaded and compiled Tesseract?

It's downloaded but not sure about compile...I'll research how to do that now.

Timothy Snyder

unread,
Sep 16, 2019, 5:56:34 PM9/16/19
to tesser...@googlegroups.com
If you downloaded Tesseract's source code from GitHub (which I think you did), you will have to follow the compilation steps for Linux on this page https://github.com/tesseract-ocr/tesseract/wiki/Compiling#linux



--
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.

Clint William Theron

unread,
Sep 16, 2019, 6:00:08 PM9/16/19
to tesseract-ocr
should I run the following command

apt-get install automake ca-certificates g++ git libtool libleptonica-dev make pkg-config

I just want to make sure.

Up until now all I did was:
1. Register on gitpod.io
2. concatenated gitpod.io with #https://github.com/tesseract-ocr/tesseract/pulls to download tesseract-ocr
3. I ran this command 
npm install node-tesseract-ocr


This is where I'm at

Clint William Theron

unread,
Sep 16, 2019, 6:04:54 PM9/16/19
to tesseract-ocr
Consider the following screenshot...

Untitled.png


This is a sudo problem on gitpod.io. Is that correct? If yes, is there another way I can do this?


Clint William Theron

unread,
Sep 16, 2019, 6:16:29 PM9/16/19
to tesseract-ocr
I also tried this:



gitpod
/workspace/tesseract $ sudo apt install libtesseract-dev
sudo
: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
gitpod
/workspace/tesseract $ apt install tesseract-ocr
E
: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E
: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
gitpod
/workspace/tesseract $ apt install libtesseract-dev
E
: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E
: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
gitpod
/workspace/tesseract $ ./autogen.sh
Running aclocal
Running /usr/bin/libtoolize
libtoolize
: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config'.
libtoolize
: copying file 'config/ltmain.sh'
libtoolize
: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize
: copying file 'm4/libtool.m4'
libtoolize
: copying file 'm4/ltoptions.m4'
libtoolize
: copying file 'm4/ltsugar.m4'
libtoolize
: copying file 'm4/ltversion.m4'
libtoolize
: copying file 'm4/lt~obsolete.m4'
Running autoconf
Running autoheader
Running automake --add-missing --copy
configure
.ac:349: installing 'config/compile'
configure
.ac:86: installing 'config/config.guess'
configure
.ac:86: installing 'config/config.sub'
configure
.ac:27: installing 'config/install-sh'
configure
.ac:27: installing 'config/missing'
src
/api/Makefile.am: installing 'config/depcomp'
parallel
-tests: installing 'config/test-driver'


All done.
To build the software now, do something like:


$
./configure [--enable-debug] [...other options]
gitpod
/workspace/tesseract $ ./configure --prefix=$HOME/local/
checking
for g++... g++
checking whether the C
++ compiler works... yes
checking
for C++ compiler default output file name... a.out
checking
for suffix of executables...
checking whether we are cross compiling
... no
checking
for suffix of object files... o
checking whether we are
using the GNU C++ compiler... yes
checking whether g
++ accepts -g... yes
checking
for a BSD-compatible install... /usr/bin/install -c
checking whether build environment
is sane... yes
checking
for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking
for gawk... gawk
checking whether make sets $
(MAKE)... yes
checking whether make supports the include directive
... yes (GNU style)
checking whether make supports nested variables
... yes
checking dependency style of g
++... gcc3
checking
for a sed that does not truncate output... /usr/bin/sed
checking
Major version... 5
checking
Minor version... 0
checking
Point version... 0-alpha-419-g91b3
checking build system type
... x86_64-pc-linux-gnu
checking host system type
... x86_64-pc-linux-gnu
checking whether C
++ compiler accepts -Werror=unused-command-line-argument... no
checking whether C
++ compiler accepts -mavx... yes
checking whether C
++ compiler accepts -mavx2... yes
checking whether C
++ compiler accepts -mfma... yes
checking whether C
++ compiler accepts -msse4.1... yes
checking whether C
++ compiler accepts -march=native... yes
checking
--enable-graphics argument...
checking
--enable-legacy argument...
checking
for g++ option to support OpenMP... -fopenmp
checking how to run the C
++ preprocessor... g++ -E
checking
for grep that handles long lines and -e... /usr/bin/grep
checking
for egrep... /usr/bin/grep -E
checking
for ANSI C header files... yes
checking
for sys/types.h... yes
checking
for sys/stat.h... yes
checking
for stdlib.h... yes
checking
for string.h... yes
checking
for memory.h... yes
checking
for strings.h... yes
checking
for inttypes.h... yes
checking
for stdint.h... yes
checking
for unistd.h... yes
checking tiffio
.h usability... yes
checking tiffio
.h presence... yes
checking
for tiffio.h... yes
checking
--enable-opencl argument...
checking tensorflow
/core/framework/graph.pb.h usability... no
checking tensorflow
/core/framework/graph.pb.h presence... no
checking
for tensorflow/core/framework/graph.pb.h... no
checking
--enable-visibility argument...
checking whether to
use tessdata-prefix... yes
checking
if compiling with clang... no
checking whether to enable debugging
...
checking whether
byte ordering is bigendian... no
checking how to
print strings... printf
checking
for gcc... gcc
checking whether we are
using the GNU C compiler... yes
checking whether gcc accepts
-g... yes
checking
for gcc option to accept ISO C89... none needed
checking whether gcc understands
-c and -o together... yes
checking dependency style of gcc
... gcc3
checking
for a sed that does not truncate output... (cached) /usr/bin/sed
checking
for fgrep... /usr/bin/grep -F
checking
for ld used by gcc... /usr/bin/ld
checking
if the linker (/usr/bin/ld) is GNU ld... yes
checking
for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister
(/usr/bin/nm -B) interface... BSD nm
checking whether ln
-s works... yes
checking the maximum length of command line arguments
... 1572864
checking how to convert x86_64
-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64
-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking
for /usr/bin/ld option to reload object files... -r
checking
for objdump... objdump
checking how to recognize dependent libraries
... pass_all
checking
for dlltool... no
checking how to associate runtime
and link libraries... printf %s\n
checking
for ar... ar
checking
for archiver @FILE support... @
checking
for strip... strip
checking
for ranlib... ranlib
checking command to parse
/usr/bin/nm -B output from gcc object... ok
checking
for sysroot... no
checking
for a working dd... /usr/bin/dd
checking how to truncate binary pipes
... /usr/bin/dd bs=4096 count=1
checking
for mt... no
checking
if : is a manifest tool... no
checking
for dlfcn.h... yes
checking
for objdir... .libs
checking
if gcc supports -fno-rtti -fno-exceptions... no
checking
for gcc option to produce PIC... -fPIC -DPIC
checking
if gcc PIC flag -fPIC -DPIC works... yes
checking
if gcc static flag -static works... yes
checking
if gcc supports -c -o file.o... yes
checking
if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker
(/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether
-lc should be explicitly linked in... no
checking
dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths
into programs... immediate
checking whether stripping libraries
is possible... yes
checking
if libtool supports shared libraries... yes
checking whether to build shared libraries
... yes
checking whether to build
static libraries... yes
checking how to run the C
++ preprocessor... g++ -E
checking
for ld used by g++... /usr/bin/ld -m elf_x86_64
checking
if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g
++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking
for g++ option to produce PIC... -fPIC -DPIC
checking
if g++ PIC flag -fPIC -DPIC works... yes
checking
if g++ static flag -static works... yes
checking
if g++ supports -c -o file.o... yes
checking
if g++ supports -c -o file.o... (cached) yes
checking whether the g
++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking
dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths
into programs... immediate
checking whether C
++ compiler accepts -std=c++11... yes
checking whether C
++ compiler accepts -std=c++14... yes
checking whether C
++ compiler accepts -std=c++17... yes
checking
for library containing pthread_create... -lpthread
checking
for ANSI C header files... (cached) yes
checking whether time
.h and sys/time.h may both be included... yes
checking
for sys/wait.h that is POSIX.1 compatible... yes
checking sys
/ipc.h usability... yes
checking sys
/ipc.h presence... yes
checking
for sys/ipc.h... yes
checking sys
/shm.h usability... yes
checking sys
/shm.h presence... yes
checking
for sys/shm.h... yes
checking limits
.h usability... yes
checking limits
.h presence... yes
checking
for limits.h... yes
checking malloc
.h usability... yes
checking malloc
.h presence... yes
checking
for malloc.h... yes
checking
for stdbool.h that conforms to C99... no
checking
for _Bool... no
checking
for asciidoc... false
checking
for xsltproc... false
checking
for wchar_t... yes
checking
for long long int... yes
checking
for off_t... yes
checking
for mbstate_t... yes
checking
for pkg-config... /usr/bin/pkg-config
checking pkg
-config is at least version 0.9.0... yes
checking
for LEPTONICA... no
configure
: error: Leptonica 1.74 or higher is required. Try to install libleptonica-dev package.
gitpod
/workspace/tesseract $ make
make
: *** No targets specified and no makefile found.  Stop.
gitpod
/workspace/tesseract $ make install
make
: *** No rule to make target 'install'.  Stop.
gitpod
/workspace/tesseract $

Clint William Theron

unread,
Sep 16, 2019, 6:19:07 PM9/16/19
to tesseract-ocr
The above commands (with output) I found here

Clint William Theron

unread,
Sep 17, 2019, 11:13:39 AM9/17/19
to tesseract-ocr
I'm struggling to install Leptonica so I tried this solution but still unsuccessful. Below is the output:

Untitled.png


Any advice?

 
Reply all
Reply to author
Forward
0 new messages