Win10 使用MinGW-w64編譯Tesseract4.0

一開始嘗試使用mingw+msys編譯tesseract, 可是苦於mingw-get安裝的軟件版本都太舊,要安裝新版本只能下載源碼編譯安裝。git

在編譯過程當中遇到了不少麻煩,最後還遇到了包直接循環依賴問題(glib和pkg-config),最終只能做罷。github

1. 下載安裝mysy2

地址: https://www.msys2.org/web

安裝後打開msys2.exe, 務必要先更新軟件包數據庫和核心繫統包(很重要),不然在安裝tesseract過程當中出現莫名奇妙的問題。
數據庫

pacman -Syu
# -y, --refresh 從服務器下載新的軟件包數據庫 (-yy 強制更新軟件包數據庫) # -u, --sysupgrade 升級全部已安裝的軟件包 (-uu 可啓用降級)

2. 更新軟件源

默認的MSYS2 源升級軟件或是安裝新軟件的較慢,這裏爲了提升速度使用中科大的源windows

編輯 /etc/pacman.d/mirrorlist.mingw32 ,在文件開頭添加:服務器

Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686

編輯 /etc/pacman.d/mirrorlist.mingw64 ,在文件開頭添加:工具

Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64

編輯 /etc/pacman.d/mirrorlist.msys ,在文件開頭添加:測試

Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch
# 刷新軟件包數據
pacman -Sy

3. 環境搭建

pacman -S base-devel
pacman -S automake autoconf make mingw-w64-i686-gcc mingw-w64-i686-gdb mingw-w64-i686-SDL mingw-w64-i686-SDL_ttf mingw-w64-i686-make
pacman -S autoconf-archive libtool pkg-config
pacman -S icu-devel  mingw-w64-i686-pango mingw-w64-i686-cairo


# 選擇安裝(optional)
pacman -S msys2-devel
pacman -S mingw-w64-i686-toolchain

4. 安裝Tesseract4.0

目前使用pcman直接安裝的Tesseract版本爲3.0.5spa

tesseract安裝依賴leptonica,而leptonica又依賴libgif、libjpeg、libpng、libtiff、zlib、libwebp、libopenjp二、xz等庫。命令行

# 安裝leptonica
pacman -S mingw-w64-i686-leptonica

# 安裝git 
pacman -S git

# 下載tesserat4.0源碼
git clone https://github.com/tesseract-ocr/tesseract.git tesseract-ocr

# autogen.sh的做用也是檢測你的編譯工具和依賴關係包是否完整
./autogen.sh
./configure --enable-debug
make -j4 
make install
 

若是安裝tesseract3.0.5,只須要:

# 安裝
pacman -S mingw-w64-i686-tesseract-ocr

# 卸載
pacman -S mingw-w64-i686-tesseract-ocr

5. 遇到的錯誤

1)

pacman -S mpfr

2)

嘗試更新軟件包:

pacman -Syu

6. 測試:

若是想要在windows的命令行中也是能夠使用tesseract,將tesseract.exe拷貝到其餘目錄,而後雙擊運行,這時確定會報錯

根據提示拷貝對應的dll到當前tesseract.exe所在目錄便可。

效果:

參考:

https://github.com/mangband/mangband/wiki/MSYS2

https://github.com/tesseract-ocr/tesseract/wiki

https://github.com/tesseract-ocr/tesseract/wiki/Compiling

相關文章
相關標籤/搜索