So I'm trying to read the text in an image, and I'm experiencing some issues with it.
My code:
import cv2
import pytesseract
def read_img():
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
return cv2.imread('Images/Image2.png')
def process_text(img):
names = []
data = pytesseract.image_to_data(img)
for x, d in enumerate(data.splitlines()):
if x != 0:
d = d.split()
if len(d) == 12:
names.append(d[11])
return names
img = read_img()
print(process_text(img))
Result:
['-', '©', '-', 'AceeZ.Rogue', 'a', '5540', 't', '3', '8', '&', '©', 'LeonGids.Rogue', 'a', 'seas', '8', '3', '8', 'e', 'fl', 'karzheka.Rogue', 'a', '5151', '8', '2', '7', '48', '7', 'Q', 'ripz.Rogue', 'a', '5105', '8', '[', '5s', '27', 'm', 'korey.Rogue', 'a', '5105', '7', '2', '6', '36', '-', '[ZH]', 'Shaiiko.BDS', 'C', '3520', 'a', 'B', 's', '22', 'Cps', 'a', '2012', '8', 'i', '8', '21', 'ypc', 'Chee', 'e', '8', '-_', '22', '3', '(2)', 'Flemzje.BDS', 'a', '2420', 'a', '3', '10', '26', '(SF)', 'Renshiro.BDS', 'C', '2410', '6', '1', '8', 'Fo']
As you can see this is not the result I was hoping for. Here's what I've tried;
- Splitting the image up
I've split the image up into two to have it more centered on the actual text:
The result of img1 is actually perfect:
['AceeZ.Rogue', 'LeonGids.Rogue', 'karzheka.Rogue', 'ripz.Rogue', 'korey.Rogue', 'Shaiiko.BDS', 'BriD.BDS', 'RaFaLe.BDS', 'Elemzje.BDS', 'Renshiro.BDS']
But with img2 issues arise again:
['5540', '5343', '5151', '5105', '5105', '3520', '29012', '2695', '2420', '2410', '11', '10']
It looks like tesseract is having issues reading numbers, because img1 with just text went fine? I've tried increasing the quality of the text (letsenhance.io) and also increasing contrast:
Neither of these methods worked.
- Using config options
I've tried using config options like '--psm 6' and 'outbase digits' which didn't fix the problem either.
I saw on this page that training with the specified font is a possibility (https://stackoverflow.com/a/53763425/10503012) but I sadly don't know the font and https://www.myfonts.com/WhatTheFont/ didn't give me the exact font so I'm assuming that's not an option either.
So my question is; is it even possible to extract the text/numbers from this image or is this a lost case? What more can I do to improve the result tesseract gives me? I have the idea that the image with high contrast should work but it clearly doesn't.
Thanks for any help.



