前提・実現したいこと
pyocrをtesseractから呼び出し、画像の文字部分を別画像として保存したい。
発生している問題
公式ドキュメント(https://gitlab.gnome.org/World/OpenPaperwork/pyocr)で確認しましたが、よく分かりません。
文字検出後にtxtにするのではなく、文字検出部分を画像として保存するのは可能なのでしょうか??
該当のソースコード
python
1from PIL import Image 2import sys 3 4import pyocr 5import pyocr.builders 6 7tools = pyocr.get_available_tools() 8if len(tools) == 0: 9 print("No OCR tool found") 10 sys.exit(1) 11# The tools are returned in the recommended order of usage 12tool = tools[0] 13print("Will use tool '%s'" % (tool.get_name())) 14# Ex: Will use tool 'libtesseract' 15 16langs = tool.get_available_languages() 17print("Available languages: %s" % ", ".join(langs)) 18lang = langs[0] 19print("Will use lang '%s'" % (lang)) 20# Ex: Will use lang 'fra' 21# Note that languages are NOT sorted in any way. Please refer 22# to the system locale settings for the default language 23# to use. 24 25txt = tool.image_to_string( 26 Image.open('images/sample02.jpg'), 27 lang="jpn", 28 builder=pyocr.builders.TextBuilder(tesseract_layout=6) 29) 30print( txt ) 31# txt is a Python string
参考にしたもの
補足情報(FW/ツールのバージョンなど)
python3.6.5
pyocr0.7.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/18 00:10
2019/08/18 03:02