Issue
I'm trying to use pytesseract to recognize two numbers from an image. from this 1
i processed the image to look like this 2 and give that to pytesseract and that work easly.
But when i want to read by tesseract from this 3 to this 4 it doesn't work and return empty string
code:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
img = cv2.imread('grabbed.png')
rows, cols, channels = img.shape
imggray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, img = cv2.threshold(imggray, 220, 255, cv2.THRESH_BINARY_INV)
img = cv2.resize(img,(0,0),fx=3,fy=3)
img = cv2.GaussianBlur(img,(11,11),0)
img = cv2.medianBlur(img,9)
k = pytesseract.image_to_string(img, lang='eng', config='outputbase digits --dpi 300 --psm 13')
print(k)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Solution
1 - check the orientation. pytessaract need perfectly portrait images. 2 - use dialation and errosion 3 https://nanonets.com/blog/ocr-with-tesseract/ [Look at this example][1]
Answered By - Gaurav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.