OCR or other solution

Asked by Egon04

Hello!

I'm quite new to Sikuli and been experiencing a while. I've managed to create some great scripts. Now I'm trying to play with the OCR/tess-reader. I'm trying to get the text out of the gold value in Clash of clans. But I dont sucseed.

Here's an image that shows the gold value. I added diffirent values and the numbers 0-9.
http://oi60.tinypic.com/2v9zn6x.jpg

If anyone could help me to grab this value with OCR or another way, I would be realy thankfull.

I'm currently using the 1.0 version of Sikuli.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Egon04 (sonic087) said :
#1

Here's the image with the values I want to grab:
http://oi60.tinypic.com/2v9zn6x.jpg

Revision history for this message
Eugene S (shragovich) said :
#2

Hi,

Sikuli embedded OCR does not play well with computer rendered text. However in your case, it's even more complicated, due to several issues:

1. Not black on white text - this is what Tesseract expects and works best with
2. Multicolored background - same reason as above
3. Can't cut the digit without the background - so the same digit will not be matched if the background changes.

The only thing I could think about is to take screenshots of each digit and maybe to enclose a region around a number and then try to detect the number by working with digit's locations. But since issue #3 I mentioned above that might not work either.

Cheers,
Eugene

Revision history for this message
Egon04 (sonic087) said :
#3

Any idea if its possible with some assist from other programs perhaps? Seems that some other people have managed to read it... Or offcorse, if someone has a better idea for how to solve it with Sikuli alone :)

Revision history for this message
RaiMan (raimund-hocke) said :
#4

The possibilities are completely described in Eugene's comment #2.
No other possibilities with Sikuli alone.

Feel free, to use any available graphics/image library to preprocess your number image, to finally get better results from Sikuli's Region.text().

You might as well have a look at Tesseract's learning feature. At least with SikuliX 1.1.0 you would have the possibility to use your own training data.

Revision history for this message
rrTenz (rtensmeyer) said :
#5

I was trying to implement this exact thing and created a work around that is working for me. You just need to create an image for numbers 0 through 9 and store them in the 'numImages' array. Make sure to click on each image, go to the Matching Preview, and adjust the Similarity value. Then you just need to call the function and pass in a region created by "Create Region". I just through the code together today, and I'm sure it could be improved, but here is what I did:

val=[999,999,999,999,999,999,999,999,999,999]
xLoc=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]

# 0 1 2 3 4 5 6 7 8 9
numImages=[(Image_0),(Image_1),(Image_2),(Image_3),(Image_4),(Image_5),(Image_6),(Image_7),(Image_8),(Image_9)]
def numberReader(myRegion):
    i = 0
    #find all digits in the specified region
    for x in range(0, 10):
        try:
            numFound = myRegion.findAll(numImages[x])
            for num in numFound:
                #a digit was found
                xLoc[i] = num.x
                val[i] = x
                i += 1
        except FindFailed:
            doNothing = 0
            #print 'Did not find ' + `x`

    valConcat = 0
    #concatenate digits, starting with least significant and moving towards the left
    for x in range(0, i):
        highestLoc = 0
        highestIdx = 0
        for y in range(0, i):
            if(xLoc[y] > highestLoc):
                highestLoc = xLoc[y]
                highestIdx = y
        pow = 1
        for p in range(0, x):
            pow *= 10
        newVal = val[highestIdx] * pow
        valConcat += (newVal)
        xLoc[highestIdx] = 0
    return valConcat

Revision history for this message
rrTenz (rtensmeyer) said :
#6

This needs to be added to speed up the function:
            myRegion.setAutoWaitTimeout(0)

Can you help with this problem?

Provide an answer of your own, or ask Egon04 for more information if necessary.

To post a message you must log in.