When using captrue() to deposit a local image, and then calling recognition, the score is less than 0.7 most of the time

Asked by Chaoyang Shi

The version I'm using is SikulixIDE-2.0.5
I want the image to screenshot itself, I use captrue(), put it with .py there is a path, but when I call it through the path, most of the time it scores less than 0.7, I can't recognize it, how can I improve it, here is my operation process.
I limited the recognition area and it didn't work well either.
I use the "screenshot" in the IDE to capture the locally stored picture, and its score is also very low, and the picture directly captured by the "screenshot" has a high score, why?
--------My code--------
import os
import shutil

user_file = os.path.realpath("sikulix")
user_file = os.path.dirname(os.path.dirname(user_file))
user_file = os.path.join(user_file, "sikulix","test1.sikuli")

#Test data
user_img = Region(126, 91, 317, 958)
game_Area = user_img.offset(-95, -91)
reg = game_Area.setW(500).setH(1080)

#Stored procedures
ETC_L = Region(42, 300, 500, 864)
img_name = "ETC"
ETC_img_L = os.path.join(user_file, img_name+".png")
ETC_img = capture(ETC_L)
shutil.move(ETC_img, ETC_img_L)
EL = reg.find(ETC_img_L)

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said (last edit ):

A score less than 0.99 means, that parts of the image pixels are not the same in the match area on screen compared to the given image.
The larger the image is (especially in game scenarios) the higher the risk, that the human thinks, that the image should be found, but at the pixel level there are differences, that lower the score.
So generally it is better to work with smaller images, that are key visuals for the possible situations and then with other small images subsequently decide what exact situation you have on the screen.
An example is how I define the gameArea by an image that is always visible in the top left corner of the area.

I changed your code a bit, to make it testable for me:

import shutil

# the folder of your running script
user_file = getBundlePath()
print "BundlePath:", user_file

#Test data
topleft = "topleft.png"
mTopleft = exists(topleft,0)
if (not mTopleft):
    print "game area not there"

gameArea = mTopleft.setW(500).setH(1080)

#Stored procedures
imgArea = gameArea.offset(100, 100).setW(300).setH(800)
img_name = "_ETC"
#see comment
print "saved image:", SCREEN.capture(imgArea).saveInBundle(img_name)

print "Match:", gameArea.find(img_name)

--- running the script prints:

BundlePath: C:\Users\rmhde\iCloudDrive\SikuliX\test.sikuli
[log] highlight M[48,79 500x1080]On(0) S 9998 for 2.0 secs
saved image: C:\Users\rmhde\iCloudDrive\SikuliX\test.sikuli\_ETC.png
Match: M[148,179 300x800]@S(0) S:1,00 C:298,579 [42 msec]

As you can see: the score is 100%.

--- comment
I am sorry, but at the Python scripting level, the API to store captured images is not up-to-date.
The construct SCREEN.feature() allows you to use functions available on the Java level underneath.
In this case the captured image is stored at the bundle path (hence in the script folder) with the given name as .png being the default ending.
This feature always adds a leading _ (if not already given) which prevents the image from being automatically deleted.
So you just have to define an image name to get the capture stored this way.

Revision history for this message
Chaoyang Shi (elementary-student) said :

Thanks RaiMan, that solved my question.