我试图通过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"))

试着用谷歌搜索,但都没用。有人能指出正确的代码吗

输出:

^{pr2}$

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐