Issue
When I use Pytesseract to recognise the text in this image, Pytesseract returns 7A51k but the text in this image is 7,451k.
How can I fix this problem with code instead of providing a clearer source image?
my code
import pytesseract as pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'D:\\App\\Tesseract-OCR\\tesseract'
img = Image.open("captured\\amount.png")
string = pytesseract.image_to_string(image=img, config="--psm 10")
print(string)
Solution
I have a two-step solution
-
- Resize the image
-
- Apply thresholding.
-
- Resizing the image
- The input image is too small for recognizing the digits, punctuation, and character. Increasing the dimension will enable an accurate solution.
-
- Apply threshold
When you read the threshold image:
7,451k
Code:
import cv2
from pytesseract import image_to_string
img = cv2.imread("4ARXO.png")
(h, w) = img.shape[:2]
img = cv2.resize(img, (w*3, h*3))
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.threshold(gry, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
txt = image_to_string(thr)
print(txt)
Answered By - Ahx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.