Compiling – GitInstallation - kana112233/tesseract GitHub Wiki

#从Git安装Tesseract

目录

这些是从git存储库安装Tesseract的说明. 你应该准备好面对意想不到的问题.

##使用Autoconf Tools安装

为此; 你必须安装automake,libtool,leptonica,make和pkg-config. 另外,您需要Git和C ++编译器.

On Debian or Ubuntu, you can probably install all required packages like this:

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

The optional manpages are built with asciidoc:

apt-get install --no-install-recommends asciidoc

If you want to build the Tesseract training tools as well, you'll also require Pango:

apt-get install libpango1.0-dev

Afterwards, to clone the master branch to your computer, do this:

git clone https://github.com/tesseract-ocr/tesseract.git

or to make a shallow clone with commit history truncated to the latest commit only:

git clone --depth 1  https://github.com/tesseract-ocr/tesseract.git

or to clone a different branch/version:

git clone https://github.com/tesseract-ocr/tesseract.git --branch <branchName> --single-branch

Note: Tesseract requires Leptonica v1.74 or newer. If your system has only older versions of Leptonica, you must compile it manually from source available at DanBloomberg/leptonica.

Finally, run these:

    cd tesseract
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ldconfig

If you get this error:

make  all-recursive
Making all in ccstruct
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -
I..  -I../ccutil -I../cutil -I../image -I../viewer -I/opt/local/
include -I/usr/local/include/leptonica  -g -O2 -MT blobbox.lo -MD -MP -
MF .deps/blobbox.Tpo -c -o blobbox.lo blobbox.cpp
mv -f .deps/blobbox.Tpo .deps/blobbox.Plo
mv: rename .deps/blobbox.Tpo to .deps/blobbox.Plo: No such file or
directory
make[3]: *** [blobbox.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

运行./autogen.sh后尝试运行autoreconf -i.

###使用培训工具构建

以上内容并未构建Tesseract培训工具.

如果您计划安装培训工具,还需要以下库:

sudo apt-get install libicu-dev
sudo apt-get install libpango1.0-dev
sudo apt-get install libcairo2-dev

要使用培训工具构建Tesseract,请运行以下命令:

    cd tesseract
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ldconfig
    make training
    sudo make training-install

You can specify extra options for configure, as needed. eg.

./configure --disable-openmp --disable-debug --disable-opencl --disable-graphics --disable-shared'CXXFLAGS = -g -O2 -Wall -Wextra -Wpedantic'

###单元测试构建

此类构建可用于运行自动回归测试,这些测试具有其他要求. 这包括培训工具的额外依赖关系(如上所述),以及下载所有git子模块以及模型存储库(* .traineddata):

#克隆Tesseract源代码树:      git clone https://github.com/tesseract-ocr/tesseract.git      #使用模型文件克隆存储库(来自同一目录):      git clone https://github.com/tesseract-ocr/tessdata.git      git clone https://github.com/tesseract-ocr/tessdata_best.git      git clone https://github.com/tesseract-ocr/tessdata_fast.git      git clone https://github.com/tesseract-ocr/langdata_lstm.git      #切换到Tesseract源树并获取所有子模块:      cd tesseract      git submodule update --init      #构建培训工具(见上文). 在这里,我们使用一个使用消毒剂构建的版本:      ./autogen.sh      mkdir -p bin/unittest      cd bin/unittest      ../../configure --disable-shared'CXXFLAGS = -g -O2 -Wall -Wextra -Wpedantic -fsanitize = address,undefined -fstack-protector-strong -ftrapv'      进行培训      #运行单元测试:      做检查      cd ../..

这将在bin/unittest/unittest下为所有单独测试和累积测试创建日志文件. 例如,它们也可以独立运行

斌/单元测试/单元测试/stringrenderer_test

失败的测试将突出显示为段错误或SIGILL处理程序(取决于平台).

Debug Builds

这样的构建产生Tesseract二进制文件,其运行速度非常慢. 它们对生产没用,但很适合查找或分析软件问题. 这是一个经过验证的构建序列:

cd tesseract      ./autogen.sh      mkdir -p bin/debug      cd bin/debug      ../../configure --enable-debug --disable-shared'CXXFLAGS = -g -O0 -Wall -Wextra -Wpedantic -fsanitize = address,undefined -fstack-protector-strong -ftrapv'      #构建tesseract和培训工具. 如果您不需要培训工具,请运行make.      进行培训      cd ../..

这会激活调试代码,不使用共享的Tesseract库(可以在没有安装的情况下运行tesseract),禁用编译器优化(允许使用gdb进行更好的调试),启用大量编译器警告并启用多个运行时检查 .

###分析构建

此类构建可用于调查性能问题. Tesseract运行速度比没有分析时慢,但速度可以接受. 这是一个经过验证的构建序列:

cd tesseract      ./autogen.sh      mkdir -p bin/profiling      cd bin/profiling      ../../configure --disable-shared'CXXFLAGS = -g -p -O2 -Wall -Wextra -Wpedantic'      #构建tesseract和培训工具. 如果您不需要培训工具,请运行make.      进行培训      cd ../..

这不使用共享的Tesseract库(这使得可以在没有安装的情况下运行tesseract),

启用分析代码,

启用编译器优化并启用大量编译器警告.

也可以通过添加--enable-debug并将-O2替换为'-O0`来与调试代码一起使用.

当Tesseract终止时,分析代码在当前目录中创建名为gmon.out的文件.

GNU gprof用于显示该文件的分析信息.

###发布用于批量生产的构建

默认构建创建一个Tesseract可执行文件,可以处理单个图像. 然后,Tesseract使用4个CPU内核尽快获得OCR结果.

对于具有数百或数千个图像的大规模生产,默认情况下是错误的,因为多线程执行具有非常大的开销. 最好运行Tesseract的单线程实例,以便每个可用的CPU内核都处理不同的映像.

这是一个经过验证的构建序列:

cd tesseract      ./autogen.sh      mkdir -p bin/release      cd bin/release      ../../configure --disable-openmp --disable-shared'CXXFLAGS = -g -O2 -fno-math-errno -Wall -Wextra -Wpedantic'      #构建tesseract和培训工具. 如果您不需要培训工具,请运行make.      进行培训      cd ../..

这个禁用的OpenMP(多线程)不使用共享的Tesseract库(可以在没有安装的情况下运行tesseract),支持编译器优化,

禁用数学函数的“errno”设置(执行速度更快!)并启用大量编译器警告.

###为模糊测试而构建

Fuzzing用于测试Tesseract API的bug. Tesseract使用OSS-Fuzz,

模糊测试也可以在本地运行. 需要更新的Clang ++编译器.

构建示例(为可用的clang ++修复CXX的值):

cd tesseract      ./autogen.sh      mkdir -p bin/fuzzer      cd bin/fuzzer      ../../configure --disable-openmp --disable-shared CXX = clang ++ - 7 CXXFLAGS =' - g -O2 -Wall -Wextra -Wpedantic -D_GLIBCXX_DEBUG -fsanitize = fuzzer-no-link,address,undefined'      #构建fuzzer可执行文件.      制作fuzzer-api      cd ../..

示例(显示帮助信息):

bin/fuzzer/fuzzer-api -help = 1

示例(运行带有已知测试用例的模糊器):

bin/fuzzer/fuzzer-api clusterfuzz-testcase-minimize-fuzzer-api-5670045835853824

示例(运行fuzzer以查找新错误):

示例(运行带有已知测试用例的模糊器):

漂亮的bin/fuzzer/fuzzer-api -jobs = 16 -workers = 16

##使用Windows Visual Studio构建

请参阅Windows编译.

⚠️ **GitHub.com Fallback** ⚠️