1. 程式人生 > >交叉編譯 tesseract

交叉編譯 tesseract

.org reference 設置 fork ref readme 語言 leptonica 鏈接

官方參考資料說明:   tesseract 依賴庫: (https://github.com/tesseract-ocr/tesseract/wiki/Compiling#linux) 技術分享   leptonica 依賴庫: ( http://www.leptonica.org/source/README.html ) 技術分享

交叉編譯 tesseract (以 tesseract 3.01 為例) 說明:   1. 嵌入式環境:mips架構, linux 3.08   2. 交叉工具鏈: mips-linux-gnu-   3.工具鏈路徑: /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/ 一、依賴庫:   依賴庫: (官方有說明:https://github.com/tesseract-ocr/tesseract/wiki/Compiling#linux)   1. leptonica-1.67     > 其依賴庫: (官方說明:http://www.leptonica.org/source/README.html)     (1) libz (建議版本zlib_1.2.3, 實測zlib_1.2.8也可)     (2) libjpeg_9.0 (使tesseract支持jpeg,pbm圖片格式)     (3) 如需支持其他圖片格式如tif,需要安裝其他庫libtiif 二、交叉編譯 leptonica-1.67   1. 交叉編譯 libjpeg_9.0     (1)mkdir tmp     (2)./configure --host=mips-linux-gnu --target=mips-linux-gnu --prefix=$PWD/tmp        CC=mips-linux-gnu-gcc CXX=mips-linux-gnu-g++        CFLAGS=-I/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include        LDFLAGS=-L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib     (3)make -j4     (4)make install     (5)把tmp/下的include頭文件和庫文件lib復制到         /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include         /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib       工具鏈下   2. mkdir tmp   3. ./configure --host=mips-linux-gnu --target=mips-linux-gnu --prefix=$PWD/tmp     CC=mips-linux-gnu-gcc CXX=mips-linux-gnu-g++     CFLAGS=-I/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include     LDFLAGS=-L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib     --with-jpeg (表示添加jpeg庫)     --includedir=/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include     --libdir=/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib     其中:         --includedir= 表示頭文件安裝目錄         --libdir= 表示庫安裝目錄     必需配置,否則會找不到庫文件,導致編譯不通過   4. 鏈接庫環境變量     export LD_LIBRARY_PATH=/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216         :/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib   5. make -j4     出現錯誤:     /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/bin/../lib/gcc/mips-linux-gnu/4.7.2/../../../../mips-linux-gnu/bin/ld: warning: libz.so.1,     needed by ./.libs/liblept.so, not found (try using -rpath or -rpath-link)     ./.libs/liblept.so: undefined reference to `inflate‘     ./.libs/liblept.so: undefined reference to `powf‘     ./.libs/liblept.so: undefined reference to `ceil‘     ./.libs/liblept.so: undefined reference to `atan2‘     ./.libs/liblept.so: undefined reference to `expf‘     ./.libs/liblept.so: undefined reference to `deflate‘     ./.libs/liblept.so: undefined reference to `floorf‘     ./.libs/liblept.so: undefined reference to `deflateInit_‘     ./.libs/liblept.so: undefined reference to `sin‘     ./.libs/liblept.so: undefined reference to `inflateEnd‘     ./.libs/liblept.so: undefined reference to `atan‘     ./.libs/liblept.so: undefined reference to `deflateEnd‘     ./.libs/liblept.so: undefined reference to `tan‘     ./.libs/liblept.so: undefined reference to `inflateInit_‘     ./.libs/liblept.so: undefined reference to `cos‘     ./.libs/liblept.so: undefined reference to `log‘     ./.libs/liblept.so: undefined reference to `sqrt‘     collect2: error: ld returned 1 exit status          原因:找不到libz庫,缺少math庫     解決:修改 Makefile         對於當前路徑下 src/Makefile 和 Makefile:       (1) LIBS =           -> LIBS = -lm       (2) ZLIB_LIBS =           -> ZLIB_LIBS = -lz       (3) LDFLAGS = -L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/mips-linux-gnu/libc/lib                -L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib   6. make install   7. 把tmp/下的include頭文件和庫文件lib復制到     /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include     /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib    工具鏈下(如已配置 --includedir --libdir, 則make install時已經安裝到以上目錄) 三、交叉編譯tesseract 3.01   1. ./autogen.sh   2. mkdir tmp   3. ./configure --host=mips-linux-gnu --target=mips-linux-gnu --prefix=$PWD/tmp     CC=mips-linux-gnu-gcc CXX=mips-linux-gnu-g++     CFLAGS=-I/home/newton_linux/prebuilts/toolchains/mips-gcc472- glibc216/include     LDFLAGS=-L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib     報錯:        checking for leptonica... configure: error: leptonica not found:     修改為:     ./configure --host=mips-linux-gnu --target=mips-linux-gnu --prefix=$PWD/tmp     CC=mips-linux-gnu-gcc CXX=mips-linux-gnu-g++     CFLAGS=-I/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include     LDFLAGS=-L/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib     LIBLEPT_HEADERSDIR=/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/include (指定leptonica庫路徑)     如果再報錯:         checking for leptonica... yes         checking for pixCreate in -llept... no         configure: error: leptonica library missing         則刪除 configure 文件中的以下內容的帶”*“的行           * if test "x$ac_cv_lib_lept_pixCreate" = xyes; then :             cat >>confdefs.h <<_ACEOF             #define HAVE_LIBLEPT 1             _ACEOF             LIBS="-llept $LIBS"           * else             * as_fn_error $? "leptonica library missing" "$LINENO" 5           * fi   4. 鏈接庫環境變量不變     export LD_LIBRARY_PATH=/home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216:                  /home/newton_linux/prebuilts/toolchains/mips-gcc472-glibc216/lib   5. make -j4     出現錯誤:       svutil.cpp: In static member function ‘static void SVSync::StartProcess(const char*, const char*)‘:       svutil.cpp:89:18: error: ‘fork‘ was not declared in this scope       svutil.cpp:119:28: error: ‘execvp‘ was not declared in this scope       svutil.cpp: In member function ‘void SVNetwork::Close()‘:       svutil.cpp:262:16: error: ‘close‘ was not declared in this scope       svutil.cpp: In constructor ‘SVNetwork::SVNetwork(const char*, int)‘:       svutil.cpp:417:14: error: ‘sleep‘ was not declared in this scope     原因:無對應頭文件     解決:        svutil.cpp 文件開始出添加頭文件: #include <unistd.h>   6. make install 四、開發板上使用tesseract   1. 分別把tesseract、leptonica、libjpeg_9、libz的tmp/下的include頭文件和庫文件lib復制到開發板/include和/lib目錄下   2. 在開發板上設置語言數據路徑:     export TESSDATA_PREFIX=/alg     即把語言數據文件放置在/alg/tessdata之下   3. 開發板上執行:     tesseract xxx.jpg out -l eng

交叉編譯 tesseract