[英]Extract only characters from a image opencv or OCR
查看 tesserocr 中的GetComponentImage 示例並對其進行調整:
from PIL import Image, ImageOps
from tesserocr import PyTessBaseAPI, RIL
image = ImageOps.grayscale(Image.open('test.png'))).convert('L')
with PyTessBaseAPI(path=tessdata_path, psm=tesserocr.PSM.SPARSE_TEXT) as api:
api.SetImage(image)
api.Recognize()
boxes = api.GetComponentImages(RIL.SYMBOL, True)
print('Found {} symbol image components.'.format(len(boxes)))
for i, (im, box, _, _) in enumerate(boxes):
print("Box[{0}]: x={x}, y={y}, w={w}, h={h}".format(i, **box))
# display(im)
如果框不准確,請嘗試將oem=tesserocr.OEM.TESSERACT_ONLY
與正確的訓練數據一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.