Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 pyautogui screenshotting region relative to image found on screen
#1
i am trying to manipulate a known region found by using the locate on screen feature then changing these points to select a region beside the found image and take a screenshot of it. no clue how to go about doing this.
example:

foodi = pyautogui.locateOnScreen("foodi.png", confidence=0.7)

pyautogui.locateOnScreen(foodi)

this image location would be (1047, 45, 36, 35) except i want to select a region that is (1047+32,45+7,36+30,35-10)
i tried simply doing
pyautogui.locateOnScreen(foodi(+32,+7,+30,-10))
returns 'tuple' object is not callable.
How would i go about manipulating the region of foodi as it changes and selecting the region beside it?

Thanks
Bmart
buran wrote Oct-05-2019, 09:14 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
got it to modify the values of a found images region however it is still giving me an error this is what i have and the error.
print(foodi)

foodil = numpy.array(foodi)
print(foodil.astype(int)[[0]+32,[1]+7,[2]+30,[3]-10])
Error:
Traceback (most recent call last): (1047, 45, 36, 35) File "C:/Users/brady/PycharmProjects/Bot/scratch.py", line 21, in <module> (1079, 52, 66, 25) print(foodil.astype(int)[[0]+32,[1]+7,[2]+30,[3]-10]) TypeError: can only concatenate list (not "int") to list Process finished with exit code 1
buran wrote Oct-05-2019, 09:14 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#3
try
left, top, width, height = pyautogui.locateOnScreen("foodi.png", confidence=0.7)
im = pyautogui.screenshot('my_screenshot.png', region=(left + 32, top + 7, width + 30, height - 10)) # don't pass filename if you don't want it saved to file
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Quote
#4
i figured out a way to do it however it is now saying too many indices for array for
oil1[0]
food1 = numpy.array(foodi)

food1[0] += 32
food1[1] += 7
food1[2] += 30
food1[3] -= 10

food = pyautogui.screenshot(region=(food1[0], food1[1], food1[2], food1[3]))
food.save(r'C:\Users\brady\PycharmProjects\Bot\foodc.png')

def get_text(image):
    return pytesseract.image_to_string(image)
img = Image.open('foodc.png')
print(pytesseract.image_to_string(img))
time.sleep(1)
oil1 = numpy.array(oili)

oil1[0] += 32
oil1[1] += 7
oil1[2] += 30
oil1[3] -= 10

oil = pyautogui.screenshot(region=(oil1[0], oil1[1], oil1[2], oil1[3]))

oil.save(r'C:\Users\brady\PycharmProjects\Bot\oilc.png')

(Oct-05-2019, 06:20 PM)Bmart6969 Wrote: i figured out a way to do it however it is now saying too many indices for array for
oil1[0]
food1 = numpy.array(foodi)

food1[0] += 32
food1[1] += 7
food1[2] += 30
food1[3] -= 10

food = pyautogui.screenshot(region=(food1[0], food1[1], food1[2], food1[3]))
food.save(r'C:\Users\brady\PycharmProjects\Bot\foodc.png')

def get_text(image):
    return pytesseract.image_to_string(image)
img = Image.open('foodc.png')
print(pytesseract.image_to_string(img))
time.sleep(1)
oil1 = numpy.array(oili)

oil1[0] += 32
oil1[1] += 7
oil1[2] += 30
oil1[3] -= 10

oil = pyautogui.screenshot(region=(oil1[0], oil1[1], oil1[2], oil1[3]))

oil.save(r'C:\Users\brady\PycharmProjects\Bot\oilc.png')

This code worked on my scratch file when I copied it over to my Main project it started giving me this error.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Add new line after finding last string in a region Nigel11 1 163 Aug-08-2020, 10:00 PM
Last Post: Larz60+
  pyautogui with a display emulator? gumby4231 0 114 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  pytz: get integer utc offset from Olsen region/city h4tt3n 2 235 Jul-30-2020, 06:43 AM
Last Post: h4tt3n
  pyautogui.screenshot region is not working alexlu 6 423 Jun-04-2020, 10:46 AM
Last Post: alexlu
  loop in pyautogui (python automation GUI application) pyprogrammer 0 466 Feb-12-2020, 02:52 PM
Last Post: pyprogrammer
  Python function executes twice when region loop is present bluethundr 2 526 Jan-07-2020, 03:01 PM
Last Post: bluethundr
  Doesn't work function pyautogui.typewrite() aliyevmiras 1 783 Dec-22-2019, 11:35 AM
Last Post: aliyevmiras
  Pyautogui script runs fine if split into two parts together it does not Bmart6969 1 564 Oct-07-2019, 10:53 PM
Last Post: Bmart6969
  pyautogui while loop Bmart6969 0 1,356 Oct-03-2019, 03:32 PM
Last Post: Bmart6969
  Can't run pyautogui on Mohave veromi22 4 626 Sep-30-2019, 12:41 AM
Last Post: veromi22

Forum Jump:


Users browsing this thread: 1 Guest(s)