Recognize numbers from an image python
10,640
okay, so I tried changing it into grayscale, reverse contrast or use different treshold, but it all seems to be fairly inaccurate. The issue seems to be the tilted and smaller numbers. You do not happen to have any hiher res image? Most accurate I could get was the following code.
import cv2
import pytesseract
import imutils
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread('D:/img/New folder (2)/1.png') #test.png is your original image
img = imutils.resize(img, width=1400)
crop = img[340:530, 100:400]
data = pytesseract.image_to_string(crop,config=' --psm 1 --oem 3 -c tessedit_char_whitelist=0123456789/')
print(data)
cv2.imshow('crop', crop)
cv2.waitKey()
Otherwise I recommend one of these methods as described in the similar question or in this one.
Related videos on Youtube
Author by
Cesar
Updated on June 04, 2022Comments
-
Cesar about 2 years
I am trying to extract numbers from in game screenshots.
I'm trying to extract:
98
3430
5/10from PIL import Image import pytesseract image="D:/img/New folder (2)/1.png" pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe' text = pytesseract.image_to_string(Image.open(image),lang='eng',config='--psm 5') print(text)
output is gibberish
‘t hl) keteeeees ek pSlaerenen JU) pgrenmnreserenny Rates B d dali eas. 5 cle aM (Sores |, S| pgranmrerererecons a cee 3 pea 3 oS : (geo eenee ey = es A
-
Arun over 4 yearsCan you upload the image?
-
Cesar over 4 yearsThe image is at i.imgur.com/QSOcVRF.png
-
stateMachine over 4 yearsYou are going to need a stronger pre-processing pipeline than that to be able to correctly detect the numbers. You must segment the characters as cleanly as possible, also, the text is warped, you will need to unwarp it.
-