サーバ

Google のオープンソース OCR ソフト、OCRopus 速攻レビュー

・Google がサポートするオープンソースの OCR ソフト、OCRopus 速攻レビュー
Google + OCRopus がもたらすインパクト
スパム業者 + OCRopus の脅威

OCRopus というオープンソースの OCR ソフトが Google より発表されました。

・グーグル、文字認識研究OCRopusへ資金提供
http://japan.cnet.com/news/media/story/0,2000056023,20346962,00.htm

ちょうど最近フリーで使える OCR ソフトがないか探していたところ。ピッタリのタイミングです。
早速コンパイルしてみました。
Java 屋なので何か効率悪いことしているかもしれませんが参考までにインストールの記録を取っておきます。
環境は MacBook Pro(Core 2 Duo) / Mac OSX 10.4.9。

・tesseract-ocr のビルド
メインのコンポーネントらしい、tesseract-ocr
をチェックアウト

~$ svn checkout http://tesseract-ocr.googlecode.com/svn/trunk/ tesseract-ocr
A tesseract-ocr/configure
A tesseract-ocr/image
.
.
.
A tesseract-ocr/classify/Makefile.am
A tesseract-ocr/classify/picofeat.cpp
Checked out revision 30.
$

$ cd tesseract-ocr
$ ./configure
checking build system type… i686-apple-darwin8.9.1
checking host system type… i686-apple-darwin8.9.1
checking for cl.exe… no
checking for g++… g++
.
.
config.status: creating config_auto.h
config.status: error: cannot find input file: config/config.h.in

失敗。
失敗した場合は runautoconf を読んでリトライしろとのことなので・・

$ ./runautoconf
Running aclocal
Running autoheader
Running autoconf
Running automake –add-missing –copy
ccmain/Makefile.am: installing `config/depcomp'
All done.
To build the software now, do something like:

% mkdir build-directory
% cd build-directory
% ../configure [–with-debug] […other options]

$ ./configure
checking build system type… i686-apple-darwin8.9.1
checking host system type… i686-apple-darwin8.9.1
checking for cl.exe… no
checking for g++… g++
checking for C++ compiler default output file name… a.out
checking whether the C++ compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
.
.
.
config.status: creating config_auto.h
config.status: executing depfiles commands

Configuration is done.
You can now build Tesseract by running:

% make

今度は成功。あとは make

$ make
make all-recursive
Making all in ccstruct
source='blobbox.cpp' object='blobbox.o' libtool=no \
depfile='.deps/blobbox.Po' tmpdepfile='.deps/blobbox.TPo' \
depmode=gcc3 /bin/sh ../config/depcomp \
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../ccutil -I../cutil -I../image -I../viewer -I/sw/include -g -O2 -c -o blobbox.o `test -f 'blobbox.cpp' || echo './'`blobbox.cpp
.
.
.
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../ccutil -I../ccstruct -I../image -I../viewer -I../ccops -I../dict -I../classify -I../display -I../wordrec -I../cutil -I../textord -I/sw/include -g -O2 -c -o mergenf.o `test -f 'mergenf.cpp' || echo './'`mergenf.cpp
g++ -g -O2 -L/sw/lib -o mftraining mfTraining.o mergenf.o libtesseract_training.a ../textord/libtesseract_textord.a ../classify/libtesseract_classify.a ../dict/libtesseract_dict.a ../image/libtesseract_image.a ../cutil/libtesseract_cutil.a ../ccstruct/libtesseract_ccstruct.a ../viewer/libtesseract_viewer.a ../ccutil/libtesseract_ccutil.a
Making all in tessdata
make[2]: Nothing to be done for `all'.
make[2]: Nothing to be done for `all-am'.

$ sudo make install
mkdir /usr/local/share/tessdata
/usr/bin/install -c -m 644 DangAmbigs /usr/local/share/tessdata/DangAmbigs
/usr/bin/install -c -m 644 freq-dawg /usr/local/share/tessdata/freq-dawg
/usr/bin/install -c -m 644 inttemp /usr/local/share/tessdata/inttemp
/usr/bin/install -c -m 644 normproto /usr/local/share/tessdata/normproto
/usr/bin/install -c -m 644 pffmtable /usr/local/share/tessdata/pffmtable
/usr/bin/install -c -m 644 user-words /usr/local/share/tessdata/user-words
/usr/bin/install -c -m 644 word-dawg /usr/local/share/tessdata/word-dawg
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.

・aspell のインストール
スペルチェッカらしい。apt-get でインストールしたものはうまく認識されなかったのでソースからインストールした。
http://aspell.net/

$ ./configure
$ make
$ sudo make install

・aspell-en のインストール
aspell の英語辞書らしい。

$ sudo apt-get install aspell-en
Reading Package Lists… Done
Building Dependency Tree… Done
The following NEW packages will be installed:
aspell-en
0 packages upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 1948kB of archives. After unpacking 4411kB will be used.
Get:1 http://bindist.finkmirrors.net 10.4/release/main aspell-en 0.51-0-11 [1948kB]
Fetched 1948kB in 12s (151kB/s)
Selecting previously deselected package aspell-en.
(Reading database … 4605 files and directories currently installed.)
Unpacking aspell-en (from …/aspell-en_0.51-0-11_darwin-i386.deb) …
Setting up aspell-en (0.51-0-11) …

・libpng のインストール
http://prdownloads.sourceforge.net/libpng/libpng-1.2.16.tar.bz2?downloadからソースをダウンロード

$ ./configure
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for gawk… no
checking for mawk… no
checking for nawk… no
checking for awk… awk
checking whether make sets $(MAKE)… yes
checking whether to enable maintainer-specific portions of Makefiles… no
checking for gcc… gcc
.
.
config.status: creating Makefile
config.status: creating libpng.pc
config.status: creating libpng-config
config.status: creating config.h
config.status: executing depfiles commands
$ make
.
.
(cd .libs && rm -f libpng.3.dylib && ln -s libpng.3.16.0.dylib libpng.3.dylib)
(cd .libs && rm -f libpng.dylib && ln -s libpng.3.16.0.dylib libpng.dylib)
ar cru .libs/libpng.a libpng_la-png.o libpng_la-pngset.o libpng_la-pngget.o libpng_la-pngrutil.o libpng_la-pngtrans.o libpng_la-pngwutil.o libpng_la-pngread.o libpng_la-pngrio.o libpng_la-pngwio.o libpng_la-pngwrite.o libpng_la-pngrtran.o libpng_la-pngwtran.o libpng_la-pngmem.o libpng_la-pngerror.o libpng_la-pngpread.o libpng_la-pnggccrd.o
ranlib .libs/libpng.a
creating libpng.la
(cd .libs && rm -f libpng.la && ln -s ../libpng.la libpng.la)
cp libpng-config libpng12-config
cp libpng.pc libpng12.pc

$ sudo make install
Password:
test -z “/usr/local/bin” || /bin/sh ./mkinstalldirs “/usr/local/bin”
/usr/bin/install -c 'libpng12-config' '/usr/local/bin/libpng12-config'
test -z “/usr/local/lib” || /bin/sh ./mkinstalldirs “/usr/local/lib”
/bin/sh ./libtool –mode=install /usr/bin/install -c 'libpng12.la' '/usr/local/lib/libpng12.la'
/usr/bin/install -c .libs/libpng12.0.16.0.dylib /usr/local/lib/libpng12.0.16.0.dylib
(cd /usr/local/lib && { ln -s -f libpng12.0.16.0.dylib libpng12.0.dylib || { rm -f libpng12.0.dylib && ln -s libpng12.0.16.0.dylib libpng12.0.dylib; }; })
(cd /usr/local/lib && { ln -s -f libpng12.0.16.0.dylib libpng12.dylib || { rm -f libpng12.dylib && ln -s libpng12.0.16.0.dylib libpng12.dylib; }; })
/usr/bin/install -c .libs/libpng12.lai /usr/local/lib/libpng12.la
/usr/bin/install -c .libs/libpng12.a /usr/local/lib/libpng12.a
chmod 644 /usr/local/lib/libpng12.a
ranlib /usr/local/lib/libpng12.a
.
.
.
make install-data-hook
cd /usr/local/include; rm -f png.h pngconf.h
cd /usr/local/include; ln -s libpng12/png.h png.h
cd /usr/local/include; ln -s libpng12/pngconf.h pngconf.h
cd /usr/local/lib/pkgconfig; rm -f libpng.pc
cd /usr/local/lib/pkgconfig; ln -s libpng12.pc libpng.pc

libtool のダウンロード、インストール。libjpeg のビルドに必要だった。
http://www.gnu.org/software/libtool/

$./configure
$ make
$ sudo make install

・libjpeg のインストール
apt-get でインストールしたけど、ocropus の configure でヘッダがみつからないと言われたのでhttp://www.ijg.org/files/からソースをダウンロードしてインストール。
manとか man1 というディレクトリがないというエラーがでたのでとりあえず作ったらインストールできた。

$ ./configure –enable-shared
$ ln -s /usr/local/bin/libtool ./
$ make
$ sudo mkdir /usr/local/man
$ sudo mkdir /usr/local/man/man1
$ sudo make install
/usr/bin/install -c cjpeg /usr/local/bin/cjpeg
/usr/bin/install -c djpeg /usr/local/bin/djpeg
/usr/bin/install -c jpegtran /usr/local/bin/jpegtran
/usr/bin/install -c rdjpgcom /usr/local/bin/rdjpgcom
/usr/bin/install -c wrjpgcom /usr/local/bin/wrjpgcom
/usr/bin/install -c -m 644 ./cjpeg.1 /usr/local/man/man1/cjpeg.1
/usr/bin/install -c -m 644 ./djpeg.1 /usr/local/man/man1/djpeg.1
/usr/bin/install -c -m 644 ./jpegtran.1 /usr/local/man/man1/jpegtran.1
/usr/bin/install -c -m 644 ./rdjpgcom.1 /usr/local/man/man1/rdjpgcom.1
/usr/bin/install -c -m 644 ./wrjpgcom.1 /usr/local/man/man1/wrjpgcom.1

libtiff も必要らしい。
http://dl.maptools.org/dl/libtiff/

$ ./configure
$ make
$ sudo make install
$ svn checkout http://ocropus.googlecode.com/svn/trunk/ ocropus
A ocropus/run-check
A ocropus/configure
A ocropus/ocr-utils
A ocropus/ocr-utils/test-ocr-utils.cc
A ocropus/ocr-utils/ocr-utils.cc
A ocropus/ocr-utils/Jamfile
A ocropus/ocr-utils/ocr-u
.
.
.
A ocropus/ocr-tesseract/Jamfile
A ocropus/ocr-tesseract/test-list
A ocropus/ocr-tesseract/README
A ocropus/ocr-tesseract/000002_line_image.png
A ocropus/ocr-tesseract/test-tesseract.cc
Checked out revision 76.

$ cd ocropus/
$ ./configure
.
.
.

OK! Now you can build OCRopus by typing “jam”.
If compilation will be successful, you can try this:
ocropus-cmd/ocropus ocr data-test-pages/alice_1.png | tee output.html

調べてみると、jam っていうのはソースコード管理ツールを出している perforce が出しているビルドツールみたい。
Mac OSX に含まれているというけれども見つからなかった。
perforce からダウンロード/makeした。
http://www.perforce.com/jam/jam.html

$ ~/jam/bin.macosxx86/jam
…found 337 target(s)…
…updating 91 target(s)…
C++ imgio/io_pbm.o
C++ imgio/io_png.o
C++ imgio/io_jpeg.o
C++ imgio/autoinvert.o
C++ imgio/imgio.o
Archive imgio/libimgio.a
ar: creating archive imgio/libimgio.a
Ranlib imgio/
.
.
Link ocr-engine/test-process
Chmod1 ocr-engine/test-process
C++ ocr-engine/test-spell.o
Link ocr-engine/test-spell
Chmod1 ocr-engine/test-spell
C++ ocropus-cmd/ocr-distance.o
Link ocropus-cmd/ocr-distance
Chmod1 ocropus-cmd/ocr-distance
C++ ocropus-cmd/ocropus.o
GenerateVersion ocropus-cmd/version.cc
C++ ocropus-cmd/version.o
Link ocropus-cmd/ocropus
Chmod1 ocropus-cmd/ocropus
…updated 91 target(s)…

ocropus-cmd ディレクトリが出来ていればビルド成功とのこと。
うまく出来ました。

$ ls ocropus-cmd/
Jamfile ocr-distance ocropus ocropus.cc smoketest.out version.cc
README ocr-distance.cc ocropus-adaptive.sh ocropus.o test-ocr-simple version.h
debug ocr-distance.o ocropus-gray.sh ocropus.sh test-ocr-simple.png version.o

試しに OCRopus のサイトのスクリーンショットをとって動かしてみました。

スクリーンショット

$ ./ocropus ocr ~/screenshot_01-large.jpg >out.html
OCRopus pre-alpha (sauvola, rast, curved, tesseract, aspell)
Revision: 76; Sun Apr 15 02:16:41 JST 2007; Darwin yusukey.local 8.9.1 Darwin Kernel Version 8.9.1: Thu Feb 22 20:55:00 PST 2007; root:xnu-792.18.15~1/RELEASE_I386 i386 i386
$

おぉ、動いた!

読み取り結果はこちら

読み取り精度はまずます。
ぱっとみたところ妙だったのは、
———
GettingStarted -> Getting5tarted
won't work -> won`t
a state-of-the-art -> s stateof-theart
———
といったところ。
あとはカンマとピリオド、ダブルクオーテーションとシングルクオーテーションといった記号の読み分けは弱い感じです。
OCRopus 0.1.0 リリース
スパム業者 + OCRopus の脅威
Google + OCRopus がもたらすインパクト