0

I have some pics from which I want to read digits. I used pytesseract as well as cv2 threshold.

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.

here are the pics

https://ibb.co/thgXTSn

https://ibb.co/cYGYL2W

https://ibb.co/R2nbt0g

https://ibb.co/ZgPKy2N

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

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.

Alex Alex
  • 1,893
  • 1
  • 6
  • 12
  • Hi i used this code se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE , (5,5)) close=cv2.morphologyEx(image, cv2.MORPH_CLOSE, se) close=cv2.absdiff(close, image) thresh=cv2.bitwise_not(close) thresh = cv2.threshold(thresh, 0, 255,cv2.THRESH_OTSU)[1] thresh = cv2.GaussianBlur(thresh, (3,3), 0 ) data = pytesseract.image_to_string(thresh) but 1 image is still showing nothing – Guddu Kumar May 25 '20 at 10:34
  • M.b. cv2.resize()? – Alex Alex May 25 '20 at 13:43