Capture screen from background windows and adb (Windows only)
pip install windows-adb-screen-capture
pip install windows-adb-screen-capture --no-deps
pip install pywin32
pip install mss
pip install pandas
pip install opencv-python
Update 2022/11/10
Faster ADB screenshots
Update 2022/11/04
-
Screenshots can now be resized for imshow
-
Screenshots can be taken from the whole screen, and even multiple screens
-
Bugfix: Closing and reopening imshow is working now
from windows_adb_screen_capture import ScreenShots
sc2 = ScreenShots()
sc2.set_resize_ratio(50).choose_monitor_for_screenshot(0).imshow_screenshot_monitor()
Example with BlueStacks (using adb)
Open bluestacks
$adb connect localhost:5735
from windows_adb_screen_capture import ScreenShots
sc=ScreenShots(hwnd=None, adb_path=r"C:\ProgramData\adb\adb.exe", adb_serial='localhost:5735')
sc.imshow_adb(sleep_time=0.05, quit_key="e")
Edit screenshots before showing
import cv2
sc.enable_show_edited_images()
for x in range(120):
tmpscreenshot = sc.imget_adb()
tmpscreenshort_inverted = cv2.bitwise_not(tmpscreenshot)
sc.show_edited_image(tmpscreenshort_inverted)
sc.disable_show_edited_images()
Example with BlueStacks (using hwnd)
sc2 = ScreenShots()
sc2.find_window_with_regex('[bB]lue[sS]tacks.*')
sc2.imshow_hwnd(sleep_time=0.05, quit_key="q")
sc2.enable_show_edited_images()
for x in range(1000):
tmpscreenshot = sc2.imget_hwnd()
tmpscreenshort_inverted = cv2.bitwise_not(tmpscreenshot)
sc2.show_edited_image(tmpscreenshort_inverted)
sc2.disable_show_edited_images()
Get screenshots without showing windows
from windowcapture import ScreenShots
sc=ScreenShots(hwnd=None, adb_path=r"C:\ProgramData\adb\adb.exe", adb_serial='localhost:5735')
sc.imget_adb()
sc2 = ScreenShots()
sc2.find_window_with_regex('[bB]lue[sS]tacks.*')
sc2.imget_hwnd()