gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:25 32 4
gpt4 key购买 nike

我正在尝试通过 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"))

尝试使用谷歌搜索,但无济于事。有人可以指向正确的代码吗输出:

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! }

最佳答案

图像太亮,对比度不理想。

您需要改进 contrast and brightness .

然后应用一些 morphological operations去除噪音。

然后关注this tips关于如何为 OCR 改进点阵打印机字体:

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

关于python - 使用 Python(点阵 OCR)从图像中提取文本时获取不正确的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56315193/

32 4 0
文章推荐: python - 从图像 OpenCv 中删除合并线
文章推荐: 没有文本的元素的 CSS 伪类
文章推荐: c# - ExecuteStoreCommand 上出现奇怪的 EF6 性能问题
文章推荐: javascript - 为
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com