Python package to take screenshots of windows that are in background
pip install bshot
import cv2
import win32gui
from bshot.screenshot import get_image
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
img = get_image(hwnd, method="srccopy") # windll and srccopy methods
cv2.namedWindow("bshot", cv2.WINDOW_NORMAL)
cv2.imshow("bshot", img)
cv2.waitKey(0)
The speed of the capture depends on the size of the window that is being captured. It can caputre 220x160 window with 2400+ fps.
import time
import win32gui
from bshot.screenshot import get_image
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
start = time.time()
count = 0
while time.time() - start < 1:
get_image(hwnd, method="srccopy")
count += 1
print("fps =", count)
- The screenshot module uses GetClientRect which can crop some portion of the window contents.