1. import WindowCaptureUtil
from WindowCaptureUtil import WindowCapture
2. list processes (optional)
import win32gui
def winEnumHandler ( hwnd , ctx ):
if win32gui .IsWindowVisible ( hwnd ):
print ( "0x%08x" % (hwnd ), win32gui .GetWindowText ( hwnd ))
win32gui .EnumWindows ( winEnumHandler , None )
3. get screenshot (for all windows)
cap = WindowCapture (window_name = "계산기" )
img = cap .get_screenshot () # window will be foreground
from PIL import Image
import cv2
im = Image .fromarray (cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB ))
im .save ("calc.jpg" )
% matplotlib inline
from matplotlib import pyplot as plt
plt .imshow (cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB ))
plt .axis ("off" )
plt .tight_layout ()
plt .show ()
5. get screeshot (for native window apps)
cap = WindowCapture (window_name = "팟플레이어" )
img = cap .get_screenshot_of_native_appication () # window doesn't need to be foreground
% matplotlib inline
from matplotlib import pyplot as plt
import cv2
plt .imshow (cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB ))
plt .axis ("off" )
plt .tight_layout ()
plt .show ()