Answers for "screen capture particular part using python"

0

python screen capture a window

from win32gui import FindWindow, GetWindowRect
from PIL import ImageGrab
from PIL import Image
import numpy as np
import cv2

while True:
    window_handle = FindWindow(None, "MTGA")
    window_rect = GetWindowRect(window_handle)
    screen = np.array(ImageGrab.grab(bbox=(window_rect)))
    resized = cv2.resize(screen, (1280, 720), interpolation = cv2.INTER_AREA)
    im_rgb = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB)
    cv2.imshow('Python Window', im_rgb)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break
Posted by: Guest on April-28-2021
0

make screen shot of specific part of screen python

import mss
import mss.tools


with mss.mss() as sct:
    # The screen part to capture
    monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
    output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)

    # Grab the data
    sct_img = sct.grab(monitor)

    # Save to the picture file
    mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
    print(output)
Posted by: Guest on May-31-2020

Python Answers by Framework

Browse Popular Code Answers by Language