擅长:python、mysql、java
<p>这是您需要的包装:
<a href="https://pypi.python.org/pypi/tesserocr/2.0.0" rel="nofollow noreferrer">https://pypi.python.org/pypi/tesserocr/2.0.0</a>。此外,还有大量的Python包装器,但这个库是最接近包装器,几乎覆盖了所有的C++ API。</p>
<p>示例:</p>
<pre><code>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)
</code></pre>