これは、必要なラッパーです: https://pypi.python.org/pypi/tesserocr/2.0.0です。またそこにはたくさんのPythonラッパーがありますが、このライブラリはC++ APIのほぼすべてをカバーする最も近いラッパーです。
例:
from PIL import Image
from tesserocr import PyTessBaseAPI
image = Image.open('/usr/src/tesseract/testing/phototest.tif')
with PyTessBaseAPI() as api:
api.SetImage(image)
boxes = api.GetComponentImages(RIL.TEXTLINE, True)
print 'Found {} textline image components.'.format(len(boxes))
for i, (im, box, _, _) in enumerate(boxes):
# im is a PIL image object
# box is a dict with x, y, w and h keys
api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
ocrResult = api.GetUTF8Text()
conf = api.MeanTextConf()
print (u"Box[{0}]: x={x}, y={y}, w={w}, h={h}, "
"confidence: {1}, text: {2}").format(i, conf, ocrResult, **box)
私はたTesseract 4.0バージョンを使用していますが、TSVを出力する際、confに列は空です。別のバージョンのtesseract-ocrを使うべきですか? –
'txt'を 'tsv'に置き換えると、confカラムが表示されます – EdgeRover