我有这个python代码,用于将写在图片中的文本转换为字符串,我现在正在尝试仅包含数字的代码。 这是我的原始图片:
这是我的代码:
from google.colab.patches import cv2_imshow
img = cv2.imread(image_file_ocr)
edges = cv2.Canny(img,50,50)
edges = cv2.GaussianBlur(edges,(11,11),0)
#edges = cv2.medianBlur(edges,3)
thresh = cv2.threshold(edges, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
cv2_imshow(thresh)
而且,这是处理图像的源代码:
# PROCESS THE IMAGE
print("Process method 1:")
text = pytesseract.image_to_string(thresh, config='--psm 13 --oem 1 -c tessedit_char_whitelist=0123456789')
print(text)
print("Process method 2:")
text = pytesseract.image_to_string(thresh, config = 'outputbase nobatch digits')
print('output is: ', text)