LoginSignup
55
56

More than 5 years have passed since last update.

日本語OCRライブラリNHocrを利用してみる

Last updated at Posted at 2014-09-23

NHocrは日本語用OCR(光学文字認識)用ライブラリ。

割と世界的に有名なtesseract-ocrより日本語の性能は良いということで使ってみることにした。
ちなみに、どちらもライセンスはApache License V2.0。

性能を評価してくれているブログ( http://g86.dbcls.jp/~yag/wordpress/archives/1351 )を見つけたのだけれど、これにインストールできなかったとかいてあるとおり、すんなりとはインストールできなかったのでインストールの仕方を書いておく。

./configureでのfailの解決

$ configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Users/aikawa/Downloads/nhocr-0.22':
configure: error: C compiler cannot create executables
See `config.log' for more details

config.logをみてみる。

config.log
...
configure:2898: checking whether the C compiler works
configure:2920: gcc -O3 --unroll-loops  -DDICDIR=\"${datarootdir}\"  conftest.c  >&5
clang: error: unsupported option '--unroll-loops'
configure:2924: $? = 1
configure:2962: result: no
...

となっているので、configureファイルから--unroll-loopsフラグを全て削除。

configure
+ test "x$CFLAGS" = "x" && CFLAGS="-O3"
+ test "x$CXXFLAGS" = "x" && CXXFLAGS="-O3"
- test "x$CFLAGS" = "x" && CFLAGS="-O3 --unroll-loops"
- test "x$CXXFLAGS" = "x" && CXXFLAGS="-O3 --unroll-loops"

makeでのfailの解決

$ make
...
In file included from makechar.cpp:18:
/usr/local/include/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found
#include <freetype/config/ftheader.h>
         ^
1 error generated.
...

となる。

sudo ln -s /usr/local/include/freetype2/freetype /usr/include/freetype

としてあげれば良い。

テスト

まずはテスト用画像の作成。とりあえず、この投稿をスクリーンショットでとったものを利用してみた。

nhocr.png
nhocr.png

入力の形式はPBM/PGM/PPMのどれかということなので、convertを使ってpngから変換。

convert nhocr.png nhocr.pgm

性能テスト

$ NHOCR_DICDIR=dic nhocr/nhocr -block -o - nhocr.pgm
日ホ語OERライブラリHHOErを利用レてみる
H世ffは日本語用OEft光学丈宇認諦ユ用ライ7ラリ。
割と世界的に有括な±壁事Et%上\エ【よp日本語の性能は良いということ7使ってみ舌ことにした。
写なみに、 ヒ葦ちもライセンスはA叩Ch巳 LtC巳Ti3E V10。
性龍左綱して<れている7口7仁 リ上tyノ屯革fjd典\ij上<\gg/世M町阜\坤pfjye\ユ華ユ ユ左見っけたのだけれど、 これ
にインユト‐ル7葦なかコたとかいT講6と持p、 すん#pとはインユト一ル7葦堪か7たの7インユト一ルの仕方を\いて措<。

うーん、まずまず・・・?

55
56
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
55
56