从图像中读取文本的OCR库(最好是python)

2024-05-20 02:31:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从一些图像中读取文本,图像清晰且噪音很低。 所以我最初的想法是应该很容易获取文本。(我知之甚少)

我测试了一些python库,但没有成功(pytesser),它们可能会得到10%的正确率。 我转向了Googles tesseract-occ但它仍然远远不够好。

下面是一个例子: enter image description here

结果如下:

nemnamons

Ill
w_on

lhggerllo
' 59
' as

\M_P2ma\

vuu uu

Cafllode omer
Mom | Dyna
Mom | Dyna

lnggerllo



2vMnne= Tr2rspnn| Factory (Hexmy;

lalgeflll Uxzlconflg
w_o«
w_o«

cammem

我做错什么了?还是OCR识别真的这么差?


Tags: 图像文本on例子momtesseract噪音dyna
1条回答
网友
1楼 · 发布于 2024-05-20 02:31:54

为了得到更好的效果,你需要对图像进行预处理,比如去除噪声。稍后,您可以使用诸如pytesseract之类的库从图像中获取文本:

def get_string(img_path):
    img = cv2.imread(img_path)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Remove some noise
    kernel = np.ones((1, 1), np.uint8)
    img = cv2.dilate(img, kernel, iterations=1)
    img = cv2.erode(img, kernel, iterations=1)
    cv2.imwrite("removed_noise.png", img)    

    # Recognize text with tesseract for python
    result = pytesseract.image_to_string(Image.open("removed_noise.png"))

    return result

相关问题 更多 >