Androidでtesseractを使う(ビルド)
ここを参考にtesseractをAndroid Studioにインクルードして使おうとしました。
tess-twoをビルドするのにまずandroid ndkが必要になります。
以下のサイトからandroid ndkの最新版(11b)をダウンロード http://developer.android.com/intl/ja/ndk/downloads/index.html#download
そしてパスを通します。自分はbashを使っているので.bash_profileに以下を追記しました。
#~/.bash_profile export PATH="/Users/[oreno_namae]/android-ndk-r11b:$PATH"
次にtess-twoをgit cloneします。
tess-two/tess-twoに移動してndk-buildを実行すると通ります。
$ ndk-build [armeabi] Compile thumb : jpgt <= jaricom.c [armeabi] Compile thumb : jpgt <= jcapimin.c [armeabi] Compile thumb : jpgt <= jcapistd.c [armeabi] Compile thumb : jpgt <= jcarith.c [armeabi] Compile thumb : jpgt <= jccoefct.c [armeabi] Compile thumb : jpgt <= jccolor.c [armeabi] Compile thumb : jpgt <= jcdctmgr.c [armeabi] Compile thumb : jpgt <= jchuff.c [armeabi] Compile thumb : jpgt <= jcinit.c
ndk-buildでエラー
エラーが出ます
$ ndk-build [armeabi] Install : libjpgt.so => libs/armeabi/libjpgt.so [armeabi] Install : liblept.so => libs/armeabi/liblept.so [armeabi] Install : libpngt.so => libs/armeabi/libpngt.so [armeabi] SharedLibrary : libtess.so jni/com_googlecode_tesseract_android/src/classify/featdefs.cpp:228: error: undefined reference to 'isnanf' jni/com_googlecode_tesseract_android/src/classify/featdefs.cpp:228: error: undefined reference to '__isinff' jni/com_googlecode_tesseract_android/src/classify/mf.cpp:75: error: undefined reference to 'isnanf' clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [obj/local/armeabi/libtess.so] Error 1
stackoverflowさん。
「10eなら通ったで」
10eにします。1Gある・・・ http://dl.google.com/android/repository/android-ndk-r10e-darwin-x86_64.zip
ダウンロードして.bash_profileを変更してもう一度ndk-buildしたら通りました。
ant
次の手順は
$ android update project --path . $ ant release
です。 ※androidとantはbrewでインストールしました
ここでもエラーが出ました。
$ android update project --path . Error: The project either has no target set or the target is invalid. Please provide a --target to the 'android update' command.
以下を参考にしました。
targetを指定しなければならないのか。targetの確認。
$ android list targets Available Android targets:
ない。
$ android sdk
からインストールします。
インストールしたらこうなります
Available Android targets: ---------- id: 1 or "android-23" Name: Android 6.0 Type: Platform API level: 23 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86 ---------- id: 2 or "android-N" Name: Android N (Preview) Type: Platform API level: N Revision: 1 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in Tag/ABIs : no ABIs.
これで再度android updateを実行
$ android update project --path . --target 1 Updated project.properties Updated local.properties Added file ./proguard-project.txt
よっしゃ
最後に
$ ant release
これは何事もなく完了。これで準備が整いました。
参考
http://tech.jsa.co.jp/?=Tesseract
How to build Tesseract OCR library for Android Studio?priyankvex.wordpress.com