Skip to main content

wscreenshot

wscreenshot is a package which helps you to take screenshot of active windows running in windows OS. You just have to specify the name of the window which you want to take screen shot.

If you don't specify name of any window it takes the default screenshot of current view.

Implemented using win32 library and numpy so that it can be directly used by opencv.

To take Default Screenshot

from wscreenshot import Screenshot
import cv2 as cv
k = Screenshot()
x = k.screenshot()
cv.imshow('My Screenshot', x)
cv.waitKey(0) 
cv.destroyAllWindows()  

To list out the active windows you can use

import wscreenshot
wscreenshot.list_window_names()

This prints all the active windows.

To take screenshot of only specific window use

obj = Screenshot('Name of the window')

or

obj = Screenshot(window_name = 'Name of the window')

Example to take the screenshot of File Explorer which is currently running

To get the exact name of the window use wscreenshot.list_window_names()

from wscreenshot import Screenshot
import cv2 as cv
k = Screenshot('File Explorer')
x = k.screenshot()
cv.imshow('My Screenshot', x)
cv.waitKey(0) 
cv.destroyAllWindows()  

For taking the cropped screenshot you can specify width and height of the image

obj.screenshot(w = None, h = None)

Example:

from wscreenshot import Screenshot
import cv2 as cv
k = Screenshot()
x = k.screenshot(w = 200)
cv.imshow('My Screenshot with width 200', x)
cv.waitKey(0) 
cv.destroyAllWindows()  
x = k.screenshot(h = 200)
cv.imshow('My Screenshot with height 200', x)
cv.waitKey(0) 
cv.destroyAllWindows()  
x = k.screenshot(w = 200, h = 200)
cv.imshow('My Screenshot with width and height 200', x)
cv.waitKey(0) 
cv.destroyAllWindows()  

Advance stuff

This can be used to process games and lot many stuff

To capture each frame we can use

from wscreenshot import Screenshot
from time import time
import cv2 as cv
wincap = Screenshot('name of some active window')
loop_time = time()
while True :
    screenshot = wincap.screenshot()
    cv.imshow('Computer Vision', screenshot)
    print(f'FPS { 1 / (time() - loop_time) }')
    loop_time = time()
    if cv.waitKey(1) == ord('q'):
        cv.destroyAllWindows()
        break
print('Done.')

This can be used from processing a game or many image processing application where you can capture each frame and process the image.

Limitations

It will take blank screenshot for applications build using electron and some other framework. Will try to resolve in next update

Metadata

Release files for wscreenshot 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wscreenshot 0.0.3
File Size Uploaded
wscreenshot-0.0.3.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wscreenshot 0.0.3
File Interpreter ABI Platform
wscreenshot-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / wscreenshot-0.0.3.tar.gz

Download URL wscreenshot-0.0.3.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7cc876662753529acef076bda1f7e7151010f956d5baadcca687e8945128186e
BLAKE2b-256 checksum
How to use checksums
7b3e1cf42779932c02e776934f8f22101e2fe24663a209b96b07063b98a16bd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

Release files / wscreenshot-0.0.3-py3-none-any.whl

Download URL wscreenshot-0.0.3-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e150a6c0569125715bbd6d7d348d0982dc18d02afc442a3eb8a1ffc7b1c850e
BLAKE2b-256 checksum
How to use checksums
ce48e16e2adadd70faf515880f8f47c6d106e26127322ad288ba3fac4807a806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page