2016-09-05 9 views
0

pyocrまたはTesseractを使用して画像からフォントサイズを取得することはできますか? 以下は私のコードです。PythonでTesseractとPyocrを使ってフォントサイズを取得

tools = pyocr.get_available_tools() 
tool = tools[0] 
txt = tool.image_to_string(
     Imagee.open(io.BytesIO(req_image)), 
     lang=lang, 
     builder=pyocr.builders.TextBuilder() 
) 

ここでは、関数image_to_stringを使用して画像からテキストを取得します。そして今、私の質問は、もし私がfont-size(番号)も私のテキストを得ることができるということです。 tesserocrを使用して

+0

[MCVE]であるためにあなたのサンプルコードを修正してください。 – boardrider

答えて

0

、あなたはあなたが必要な情報を取得するためにWordFontAttributesメソッドを呼び出すことができたために、あなたの画像、上Recognizeを呼び出した後ResultIteratorを得ることができます。詳細については、メソッドのドキュメントを参照してください。

import io 
import tesserocr 
from PIL import Image 

with tesserocr.PyTessBaseAPI() as api: 
    image = Image.open(io.BytesIO(req_image)) 
    api.SetImage(image) 
    api.Recognize() # required to get result from the next line 
    iterator = api.GetIterator() 
    print iterator.WordFontAttributes() 

出力例:

{'bold': False, 
'font_id': 283, 
'font_name': u'Times_New_Roman', 
'italic': False, 
'monospace': False, 
'pointsize': 9, 
'serif': True, 
'smallcaps': False, 
'underlined': False} 
関連する問題