[英]How to read digits from some images using Python
I have some pics from which I want to read digits.我有一些我想从中读取数字的图片。 I used pytesseract as well as cv2 threshold.
我使用了 pytesseract 和 cv2 阈值。
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
crop = ['crop.png','crop1.png','crop2.png','crop3.png']
for c in crop:
image = cv2.imread(c, 0)
#thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
thresh = cv2.threshold(image, 0, 255,cv2.THRESH_OTSU)[1]
#thresh = cv2.GaussianBlur(thresh, (1,3), 0 )
#thresh = cv2.adaptiveThreshold(thresh,125, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 12)
#thresh = cv2.bilateralFilter(thresh, 15, 80, 80, cv2.BORDER_DEFAULT)
data = pytesseract.image_to_string(thresh, lang='eng',config='--psm 6')
print(data)
print('\nnext')
cv2.imshow('thresh', thresh)
but not getting good output please tell me where I am doing wrong.但没有得到好的 output 请告诉我哪里做错了。
here are the pics这是照片
https://ibb.co/thgXTSn https://ibb.co/thgXTSn
https://ibb.co/cYGYL2W https://ibb.co/cYGYL2W
You can try to do image processing before recognition.您可以尝试在识别之前进行图像处理。 For example, like this:
例如,像这样:
image = cv2.imread(c, 0)
se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE , (5,5))
close=cv2.morphologyEx(image, cv2.MORPH_CLOSE, se)
close=cv2.absdiff(close, image)
image=cv2.bitwise_not(close)
Also try upsampling image.也尝试对图像进行上采样。 Hope this solve your problem.
希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.