python screen capture a window

Solutions on MaxInterview for python screen capture a window by the best coders in the world

showing results for - "python screen capture a window"
Lilli
10 Apr 2016
1from win32gui import FindWindow, GetWindowRect
2from PIL import ImageGrab
3from PIL import Image
4import numpy as np
5import cv2
6
7while True:
8    window_handle = FindWindow(None, "MTGA")
9    window_rect = GetWindowRect(window_handle)
10    screen = np.array(ImageGrab.grab(bbox=(window_rect)))
11    resized = cv2.resize(screen, (1280, 720), interpolation = cv2.INTER_AREA)
12    im_rgb = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB)
13    cv2.imshow('Python Window', im_rgb)
14    if cv2.waitKey(25) & 0xFF == ord('q'):
15        cv2.destroyAllWindows()
16        break
17