Develop and Download Open Source Software

View NHocr-OCRopus(0.2) bridge

category(Tag) tree

file info

category(Tag)
利用ガイド
file name
ocropus-bridge-0.2-090510
last update
2009-05-10 22:38
type
HTML
editor
H. Goto
description
NHocr-OCRopus(0.2) 簡易ブリッジについて
language
Japanese
translate

NHocr-OCRopus(0.2) 簡易ブリッジについて

Last update: May 10, 2009


使い方

OCRopus(0.2系)から NHocr の一行認識プログラム rec_line を呼び出すことで、 OCRopusのレイアウト解析部を利用して文書画像全体を 認識できるようになります。 超簡易型のブリッジのソース(Luaスクリプト)を以下に示します。 OCRopus 0.2 と NHocr 1.3e-36 で動作確認しています。

rec-nhocr.lua:
---- ここから ----
-- Quick and dirty script of NHocr-OCRopus(0.2) bridge
--   by Hideaki Goto on Sep. 26, 2008
--
-- Example of using NHocr (rec_line) as a line recognizer
-- together with OCRopus layout analysis.
--
-- Installation:
--   Put this Lua script into
--    ${OCROPUS_INSTALLDIR}/share/ocropus/scripts/

if #arg < 1 then
    print("Usage: ocroscript rec-nhocr input_image_file > output.euc-jp.txt ")
    os.exit(1)
end

pages = Pages()
pages:parseSpec(arg[1])

segmenter = make_SegmentPageByRAST()
page_image = bytearray()
page_segmentation = intarray()
line_image = bytearray()

while pages:nextPage() do
   pages:getBinary(page_image)
   segmenter:segment(page_segmentation,page_image)
   regions = RegionExtractor()
   regions:setPageLines(page_segmentation)
   for i = 1,regions:length()-1 do
      regions:extract(line_image,page_image,i,1)
      write_pgm("line.pgm", line_image)
      system("/opt/nhocr/bin/rec_line -o - line.pgm ; rm line.pgm")
   end
end
---- ここまで ----

rec-nhocr.lua というファイル名で OCRopus のインストール先の share/ocropus/scrpits/ に保存します。 必要に応じて rec_line のパス名を変更してください。

下のように実行すれば、認識結果が output.euc-jp.txt に入ります。

  $ ocroscript rec-nhocr input_image_file > output.euc-jp.txt

OCRopus を標準と異なる場所にインストールした場合は、 スクリプトの位置を示す環境変数の設定が必要です。

  (例)
  $ OCROSCRIPTS=/opt/ocropus/share/ocropus/scripts \
    ocroscript rec-nhocr input_image_file > output.euc-jp.txt

制限事項

このブリッジは至極簡易なものです。 OCRopusのレイアウト解析の出力を利用するだけで、 言語後処理機能などは一切利用できません。 トレーニングもできません。 オーバーヘッドも大きいです。

カレントディレクトリに作業ファイル line.pgm が作成されます。

OCRopusのバージョンアップに伴って、 使用できなくなるかもしれません。

参考サイト