Python Forum
pyautogui.screenshot region is not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyautogui.screenshot region is not working
#3
Here is the full code
import cv2
import numpy as np
import pyautogui
# display screen resolution, get it from your OS settings
import tkinter as tk

root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
SCREEN_SIZE = (screen_width, screen_height)
fourcc = cv2.VideoWriter_fourcc(*"XVID")
# create the video write object
out = cv2.VideoWriter("output.avi", fourcc, 20.0, (SCREEN_SIZE))
while True:
    # make a screenshot

    img = pyautogui.screenshot(region=(350, 800, 500, 150))
    # convert these pixels to a proper numpy array to work with OpenCV
    frame = np.array(img)
    # convert colors from BGR to RGB
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    # write the frame
    out.write(frame)
    # show the frame
    cv2.imshow("screenshot", frame)
    # if the user clicks q, it exits
    if cv2.waitKey(1) == ord("q"):
        break

# make sure everything is closed when exited
cv2.destroyAllWindows()
out.release()
Reply


Messages In This Thread
RE: pyautogui.screenshot region is not working - by alexlu - Jun-04-2020, 08:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyautogui, İmagesearch, Moving target Beyazx 0 621 Jun-27-2023, 08:47 PM
Last Post: Beyazx
  PyAutogui write Dollar Sign Dutch keyboard not working alato 0 830 Nov-22-2022, 11:25 PM
Last Post: alato
  Using locationtagger to extract locations found in a specific country/region lord_of_cinder 1 1,336 Oct-04-2022, 12:46 AM
Last Post: Larz60+
  PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen Tiel 3 8,620 Jun-27-2022, 02:00 PM
Last Post: DeaD_EyE
  pyautogui.locateOnScreen producing error dude8074 6 3,995 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  how to take a screnshot by Pyautogui automatically and randomly rachidel07 0 3,607 Feb-03-2021, 01:16 PM
Last Post: rachidel07
Sad problem with Pyautogui rachidel07 1 2,515 Jan-27-2021, 05:43 PM
Last Post: nilamo
  Add new line after finding last string in a region Nigel11 1 1,941 Aug-08-2020, 10:00 PM
Last Post: Larz60+
  pyautogui with a display emulator? gumby4231 0 2,657 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  pytz: get integer utc offset from Olsen region/city h4tt3n 2 5,412 Jul-30-2020, 06:43 AM
Last Post: h4tt3n

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020