image not found during 2nd run

Asked by daniel

Hello,

I hope someone can help me with the following problem

Kind regards,
Daniel

1. I run the script as shown below.
2. the first run, object1 is created and "mypicture.png" is found.
3. object 2 is created with a rectangle with size 123,123,123,123
...no problem so far...

4. the second time I let the IDE run the script (ctrl+r): the image "mypicture.png" is NOT FOUND. Note the area where it's looking for has the size of the rectangle from class 2. 3rd, 4th run: same problem
6. restarting the Sikulix IDE 'solves' the problem

IDE: 2.0.5 build: 2021-3-3 9:10
VIDEO: https://drive.google.com/file/d/1iFq9ZgzDraCM7b-kL4IZiLHb0WCzgt1d/view?usp=sharing

============================================
from sikuli import *

class Myclass1:

    def mydef1(self):
        match1 = find("mypicture.png")
        match1.highlight(2)

class Myclass2:

    def mydef2(self):
        myRect = setRect(123,123,123,123)
        myRect.highlight(2)

myobj1 = Myclass1()
myobj1.mydef1()

myobj2 = Myclass2()
myobj2.mydef2()
====
Error after running this script for the 2nd (!!!!!!) time:

-----
[error] script [ module1 ] stopped with error in line 18
[error] FindFailed ( mypicture.png: (48x25) seen at (527, 325) with 0.90 in R[123,123 123x123]@S(0) )
[error] --- Traceback --- error source first
line: module ( function ) statement
6: main ( mydef1 ) match1 = find("mypicture.png")
18: main ( <module> ) myobj1.mydef1()
[error] --- Traceback --- end --------------

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
daniel (daniwin82) said (last edit ):
#1

=== UPDATE ===

When I remove the line: from sikuli import *

the script can be run multiple times without an error.
...but this no solution, since then the sikuli stuff isn't imported

=== UPDATE #2 ===
btw: I'm using the construction:
import x
from x import *
...as stated here: https://stackoverflow.com/questions/59958525/sikulix-python-getting-weird-nameerror-after-editing-of-imported-module

...but this doesn't make a difference.
So far, restarting the IDE is the only solution to the problem....but this is a bit cumbersome

Revision history for this message
daniel (daniwin82) said :
#2
Revision history for this message
RaiMan (raimund-hocke) said :
#3

In the first run find() searches on the whole screen.
After that you use setRect(), which also changes the constant SCREEN (main screen), to only the given area.

Since the Python interpreter context is static, changes to global variables are remembered in the next run.

As the error tells you:
FindFailed ( mypicture.png: (48x25) seen at (527, 325) with 0.90 in R[123,123 123x123]@S(0)

it was found at (527, 325) which surely is outside of R[123,123 123x123].

So you should use Region() to define area objects:
myRect = Region(123,123,123,123)

Not sure if you know that:
from sikuli import *
is not needed in the main script, when using SikuliX to run the script.

Can you help with this problem?

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

To post a message you must log in.