pythonautomationocrsikulisikuli-ide

Matching a Pattern in a Region in Sikuli is very slow


I am automating a computer game using Sikuli as a hobby project and to hopefully get good enough to make scripts to help me at my job. In a certain small region, (20x20 pixels) one of 15 characters will appear. Right now I have these 15 images defined as variables, and then using an if, elif loop I am doing Region.exists(). If one of my images is present in the region, I assign a variable the appropriate value.

I am doing this for two areas on the screen and then based on the combination of characters the script clicks appropriately.

The problem right now is that to run the 15 if statements is taking approximately 10 seconds. I was hoping to do this recognition in closer to 1 second.

These are just text characters but the OCR feature was not reading them reliably and I wanted close to 100% accuracy.

Is this an appropriate way to do OCR? Is there a better way you guys can recommend? I haven't done much coding in the last 3 years so I am wondering if OCR has improved and if Sikuli is still even a relevant program. Seeing as this is just a hobby project I am hoping to stick to free solutions.


Solution

  • Sikuli operates by scanning a Screen or a part of a screen and attempting to match a set pattern. Naturally, the smaller the pattern is, the more time it will consume to match it. There few ways to improve the detection time:

    1. Region and Pattern manipulation (bound region size)
    2. Functions settings (reduce minimum wait time)
    3. Configuration (amend scan rate)

    I have described the issue in some more detail here.

    OCR is still quite unreliable. There are ways to improve that but if you only have a limited set of characters, I reckon you will be better off using them as patterns. It will be quicker and more reliable.

    As of Sikuli itself, the tool is under active development and is still relevant if it helps you to solve your problem.