使用Python(点阵OCR)从图像中提取文本时获取不正确的文本

使用Python(点阵OCR)从图像中提取文本时获取不正确的文本,python,opencv,python-tesseract,Python,Opencv,Python Tesseract,我正试图通过python使用OpenCV从图像中提取文本,但得到的结果不正确,而且大部分都是特殊字符,请纠正这里的错误 import cv2 import numpy as np import pytesseract from PIL import Image import os def get_string(img_path): # Read image with opencv img = cv2.imread(img_path) # Convert to gray

我正试图通过python使用OpenCV从图像中提取文本,但得到的结果不正确,而且大部分都是特殊字符,请纠正这里的错误

import cv2
import numpy as np
import pytesseract
from PIL import Image
import os

def get_string(img_path):
    # Read image with opencv
    img = cv2.imread(img_path)

    # Convert to gray
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Apply dilation and erosion to remove some noise
    kernel = np.ones((1, 1), np.uint8)
    img = cv2.dilate(img, kernel, iterations=1)
    img = cv2.erode(img, kernel, iterations=1)

    # Write image after removed noise
    cv2.imwrite(src_path + "removed_noise.png", img)

    # Write the image after apply opencv to do some ...
    cv2.imwrite(src_path + "thres.png", img)

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

    return result

print('--- Start recognize text from image ---')
print(get_string("image_full_path.png"))
尝试过谷歌搜索,但没有任何帮助。有人能指出正确的代码吗 输出:


图像太亮,对比度不理想

你需要改进这个方法

然后涂上一些以消除噪音

然后介绍如何改进OCR的点阵打印机字体:

  • 找到边缘
  • 灰度图像阈值
  • 模糊黑白图像

图像太亮,对比度不理想

你需要改进这个方法

然后涂上一些以消除噪音

然后介绍如何改进OCR的点阵打印机字体:

  • 找到边缘
  • 灰度图像阈值
  • 模糊黑白图像

请展示图片。这是图片。请展示图片。这是图片非常感谢您的提示,让我尝试并回复您。非常感谢您的提示,让我尝试并回复您。
i } i er Oe a Pee pe be a

i j rye Se) PEE eet et ae ec?

j } a « o cy ” a @

: i : } Cand RET RE Petr eet PI ret

nif wad

fs | : : } wert
| ; a] |
wee | a
— th | cE i
ae | i
“ oe i j EYE }
en ct
. a f ae " i
- — ; - i! }