Use offset(Location(x,y)} but get wrong position some time

Asked by YO on 2017-07-30

Hi!

Here is the similar picture I use in Sikuli:
  http://imgur.com/a/v1Ft5

Here is my code:

target = find(target_pic) #the link above
scene_list = ["","","","","",""]
scene_list[1] = target.offset(Location((- scene_offset*2), 0))
scene_list[2] = target.offset(Location((- scene_offset*1), 0))
scene_list[3] = target.offset(Location(0, 0))
scene_list[4] = target.offset(Location((scene_offset*1), 0))
scene_list[5] = target.offset(Location((scene_offset*2), 0))

for pos in scene_list :
    mouseMove (pos)
    sleep(0.5)

  Sometimes when it runs, the position of scene[4] and scene[5] will move too East from the target.
For example, it would move from middle of scene[5], to the "wrong point" in the picture.

I am sure there is other similar picture when running the script(by using setROI )

And when it happens, restart the sikuli would be Okay then.

But I still want to know is there any other workaround that I can do.

Information:
  Using sikuli 1.1.1 build 2017-03-30 01:00
  Window 10
  CPU usage 55% max when running
  RAM usage 40 % max when running

            Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
dinev
Solved:
2017-08-03
Last query:
2017-08-03
Last reply:
2017-08-02
YO (testseng) said : #1

The problem is a little strange, but "the massive offset" happens on positive offset only.

The negative offset might also happen but not that "massive" to observe.

Did I accidentally trigger some bug?

dinev (ndinev) said : #2

Use "highlight" command to visualize your target and subsequent calculation
There is a chance that initial target is not recognized correctly if you dynamic application

YO (testseng) said : #3

I have use mouseMove(target) to ensure the central point of the image I found.

If the initial target is getting wrong, the whole offset in "scene_list" would be the same, since I use the variable "scene_offset" to control.

dinev (ndinev) said : #4

I do not see where scene_offset is calculated. Maybe this can be the problem.

YO (testseng) said : #5

sorry, I miss to copy that line.

I set scene_offset = 450 at start.

YO (testseng) said : #6

Sorry for the Code, I have made some correction by adding extra scene_list[0].
Using the picture http://imgur.com/a/v1Ft5
and the code below, may get the same result sometimes.

sleep(1)
scene_offset = 200
target = find(Pattern("1501664009243.png").similar(0.50)) #please use the link above for the .png
mouseMove(target)
sleep(1)
scene_list = ["","","","","",""]
scene_list[0] = target.offset(Location((- scene_offset*3), 0))
scene_list[1] = target.offset(Location((- scene_offset*2), 0))
scene_list[2] = target.offset(Location((- scene_offset*1), 0))
scene_list[3] = target.offset(Location(0, 0))
scene_list[4] = target.offset(Location((scene_offset*1), 0))
scene_list[5] = target.offset(Location((scene_offset*2), 0))

for pos in scene_list :
    mouseMove(pos)
    sleep(0.5)

Best dinev (ndinev) said : #7

Can you try replacing this part :

#####
mouseMove(target)
sleep(1)
scene_list = ["","","","","",""]
scene_list[0] = target.offset(Location((- scene_offset*3), 0))
scene_list[1] = target.offset(Location((- scene_offset*2), 0))
scene_list[2] = target.offset(Location((- scene_offset*1), 0))
scene_list[3] = target.offset(Location(0, 0))
scene_list[4] = target.offset(Location((scene_offset*1), 0))
scene_list[5] = target.offset(Location((scene_offset*2), 0))

for pos in scene_list :
    mouseMove(pos)
    sleep(0.5)
######

with this:

#####
mouseMove(target)
sleep(1)
mouseMove((- scene_offset*3), 0)
for i in range(1,6) :
    mouseMove(scene_offset,0)
    sleep(0.5)
######

YO (testseng) said : #8

I've try and there is no bug for "mouseMove" by saving the mouse Location.

sleep(1)
target = find(Pattern("1501664009243.png").similar(0.50)) #the link above
mouseMove(target)

sleep(0.3)
scene_offset = 125
mouseMove((- scene_offset*3), 0)
i = 0
scene_list = []
scene_list.append([])
scene_list[i] = Env.getMouseLocation ()
sleep(0.3)

for i in range(1,6) :
    mouseMove(scene_offset,0)
    sleep(0.3)
    scene_list.append([])
    scene_list[i] = Env.getMouseLocation ()

for j in scene_list:
    mouseMove(j)
    sleep(0.3)

but the code using offset(Location(x,y)) is so strange,
can I count it as a bug?

YO (testseng) said : #9

Thanks dinev, that solved my question.