我有一个水表的裁剪图像,我想使用pytesseract将其转换为整数字符串。我的原始图像'meter1.png'的输出应为'524621'。这是我的代码:
import cv2
import pytesseract
img = cv2.imread('/<directory>/downloads/meter1.png')
# apply grayscale and binary threshold
grayscaled = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
retval, threshold = cv2.threshold(grayscaled, 80, 255, cv2.THRESH_BINARY)
# cv2.imshow('img', img)
# cv2.imshow('threshold', threshold)
# save the image
cv2.imwrite('/<directory>/downloads/meter1_thresh.png', threshold)
# convert threshed image to text
print(pytesseract.image_to_string('/<directory>/downloads/meter1_thresh.png'))
cv2.waitKey(0)
cv2.destroyAllWindows()
我使用jupyter获得的输出是'ic PE Tr 2 11'。我缺少一些cv2转换,可以给我正确的结果(例如边缘检测,模糊/平滑等)吗?