簡體   English   中英

僅從圖像 opencv 或 OCR 中提取字符

[英]Extract only characters from a image opencv or OCR

來自如下一組文本在此處輸入圖像描述

我想在 INDIVIDUAL CHARACTER上制作一個邊界框。 但是,我無法這樣做。

我嘗試使用具有以下設置的 Easy OCR,但它只能識別單個單詞:

reader = eo.Reader(['en'],gpu=True)
result = reader.readtext(imgOriginal,y_ths=0.0000000001,x_ths=0.0000000001,paragraph=False)

我試圖在 tesserocr/pytesserocr 中設置 psm/oem 但我仍然無法獲得單個字符。 請幫忙。

查看 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM