import numpy as np
import pyautogui
import scipy.ndimage
import pygame
class Viewer:
def __init__(self, display_size):
pygame.init()
self.display = pygame.display.set_mode(display_size)
self.pic = np.zeros((*display_size, 3), dtype=np.uint8)
def set_title(self, title):
pygame.display.set_caption(title)
def set_image(self, image):
self.pic = image
def start(self):
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
surf = pygame.surfarray.make_surface(self.pic)
self.display.blit(surf, (0, 0))
pygame.display.update()
pygame.quit()
viewer = Viewer((700, 700))
screen_size = pyautogui.size()
img = pyautogui.screenshot()
img = np.array(img)
img = np.rot90(img)
img = np.flipud(img)
background = np.zeros((700, 700, 3), dtype=np.uint8)
img = scipy.ndimage.zoom(img, (min(700 / img.shape[0], 700 / img.shape[1]),
min(700 / img.shape[0], 700 / img.shape[1]), 1))
# blend the image with the background
background[int(350 - img.shape[0] / 2):int(350 + img.shape[0] / 2),
int(350 - img.shape[1] / 2):int(350 + img.shape[1] / 2), :] = img
viewer.set_image(background)
viewer.start()
import mss
import numpy as np
with mss.mss() as sct:
monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
img_array = np.array(sct.grab(monitor))
# Do whatever you want...
import pyautogui
im2 = pyautogui.screenshot('my_screenshot.png', region=(x,y, width, height))