• (原创)交叉编译 tesseract


     
    官方参考资料说明:
            
      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
     
  • 相关阅读:
    燃尽的一个不便之处修改
    jquery给元素添加样式表的方法
    http协议
    春节读书
    file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known
    jQuery on(),live(),trigger()
    jquery ui中的dialog,官网上经典的例子
    问题:循环元素,被选中元素个数,全选
    3.5星|《小学问》:年轻人思维与婚恋常见误区解析
    正念疗法入门介绍,作者是日籍美国正念疗法医生:3星|《高效休息法》
  • 原文地址:https://www.cnblogs.com/tan-v/p/7158268.html
Copyright © 2020-2023  润新知