I am building a discord bot with discord.py for the video game Diablo 2. One of the functionalities requires the bot to extract the name and properties of items from Diablo 2 screenshots. I am currently using pytesseract for this but I am not getting sufficient results.
I cropped the part of the item (the code needs to do this automatically later) and got this after preprocessing (see code below):

That is the code for preprocessing and extracting the manually cropped image:
def grayscale(image):
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
def threshold(image):
return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
def dilate(image):
kernel = np.ones((5,5),np.uint8)
return cv2.dilate(image, kernel, iterations = 1)
image = cv2.imread('item.png')
scale = 10
w = int(image.shape[1] * scale)
h = int(image.shape[0] * scale)
dim = (w, h)
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
image = grayscale(image)
image = threshold(image)
image = dilate(image)
custom_config = r'--oem 3 --psm 6 -c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%+'
print(pytesseract.image_to_string(image, config=custom_config))
It gives me these results:
sSPIRITWARD
WARD
ITamLavar66 Se a
Daryusa4if Oe
CHANCE Te BLece7a%
DURABILITY Blep5
REQUIREDSTRENGTHI76
RaguinaDLavat66
6%CHANCETSCASTLEVEL8FADEWHENSTRUCE
926%PFASTERBLeckRATE
29%IMCREASEDCHANCEOFBLeckiING2
Los t142%PNHANCEDDEFENSE a ALLRESISTANCES93i
Ay eYCeGlLOABSERE
ETHEREALCANNTBEREPAIRED
And I am unsure on how to proceed to get better results. The font and resolution are certainly difficult for OCR (you can see in the results how the OCR has problems with 5 and 6 especially). Here are some further pointers on the problem:
- I do have the Diablo 2 font (Exocet) so I might be able to train my own model (?)
- I do have list of all possible items and properties to further whitelist the results (however, I need the exact numbers for my bot's functionality)
- I also tried another lib (keras-ocr) but did not get better results















