Saving captured image to hard drive using python

Asked by arminius on 2018-05-07

This is my current working test.

    import shutil
    import os
    screenshotsDir = "C:\Users\ADDRESS_PATH\1stloop"
    wait(1)
    mySimilarity = 0.90
    Reg = Region(413,242,519,366)
    search = True
    while search:
      if Reg.exists(Pattern(Pattern("1525655012965.png").targetOffset(-1,-19)).similar(mySimilarity)):
        m = (Reg.getLastMatch())
        Xis = m.getX()
        Yis = m.getY()
        Wis = m.getW()
        His = m.getH()
        print m.getX(), m.getY(), m.getW(), m.getH()
        print(Xis)
        print(Yis)
        print(Wis)
        print(His)
        img = capture(Xis, Yis, Wis, His)
        shutil.move(img, os.path.join(screenshotsDir, "\First_image_used.png"))
        hover(Reg.getLastMatch())
        search = False
    wait(5)
    print('Finished')

The program executes without any bugs, goes right to the end, but the First_image_used.png is not being changed at all.
I noticed there was a java version that could do what I'm asking, but I'm still just learning in Python.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
arminius
Solved:
2018-05-09
Last query:
2018-05-09
Last reply:
2018-05-07
masuo (masuo-ohara) said : #1

You say "the First_image_used.png is not being changed at all."
I can't understand the situation well.
Is First_image_used.png created once?

After shutil.move(), "search" is False.
So shutil.move() is called only once.
That is First_image_used.png is created once but not changed.

If First_image_used.png is never created once, you have to confirm usage of python is correct or not by running easy code.

[for example:]
img = capture(0, 0, 100, 100)
print img

a = r"C:\tmp"
b = "img.png"
print os.path.join(a,b)

shutil.move(img, os.path.join(a,b))

arminius (arminius75) said : #2

Sorry, I put the image names down wrong.
In what I'm trying to do, if you have an image that has been seen a 100 times, and an image that has been seen none.
I want it to capture the dimensions of the image that's been found and get a newer snapshot of it, then transfer it over to replace the image that's never been seen.

I got it to work based on what you sent me.
thanks.