我试图通过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}$