Heroku で実行されている Django アプリに OCR 機能を追加したいと考えています。最も簡単な方法はTesseractを使用することだと思います。Tesseract の API 用の Python ラッパーが多数あることに気付きましたが、Heroku に Tesseract をインストールして実行するための最良の方法は何ですか? heroku-buildpack-tesseract のようなカスタム ビルドパック経由でしょうか?
2173 次
2 に答える
1
ここでたどり着いた解決策についていくつかメモを取ろうと思います。
私の.buildpacks
ファイル:
https://github.com/heroku/heroku-buildpack-python
https://github.com/clearideas/heroku-buildpack-ghostscript
https://github.com/marcolinux/heroku-buildpack-libraries
私の.buildpacks_bin_download
ファイル:
tesseract-ocr https://s3.amazonaws.com/tesseract-ocr/heroku/tesseract-ocr-3.02.02.tar.gz 3.02 eng,spa
これは、pdf ファイルの OCRing を行う python の重要な部分です。
# Additional processing
document_path = Path(str(document.attachment_file))
if document_path.ext == '.pdf':
working_path = Path('temp', document.directory)
working_path.mkdir(parents=True)
input_path = Path(working_path, name)
input_path.write_file(document.attachment_file.read(), 'w')
rb = ReadBot()
args = [
'VBEZ',
# '-sDEVICE=tiffg4',
'-sDEVICE=pnggray',
'-dNOPAUSE',
'-r600x600',
'-sOutputFile=' + str(working_path) + '/page-%00d.png',
str(input_path)
]
ghostscript.Ghostscript(*args)
image_paths = working_path.listdir(pattern='*.png')
txt = ''
for image_path in image_paths:
ocrtext = rb.interpret(str(image_path))
txt = txt + ocrtext
document.notes = txt
document.save()
working_path.rmtree()
于 2013-11-17T23:10:38.190 に答える