Created
January 5, 2018 14:11
-
-
Save doubledare704/b96c12ddc59be82565ccd72d8eb7595e to your computer and use it in GitHub Desktop.
python screenshots with opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pyautogui | |
import cv2 | |
import datetime | |
import time | |
import os | |
p = os.path.dirname(os.path.abspath(__file__)) | |
p = p + '/screens/' | |
ts = time.time() | |
screens = 3 | |
image = pyautogui.screenshot() | |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) | |
height, width, channels = image.shape | |
slice_size = width // screens | |
now = datetime.datetime.now() | |
date_name = now.strftime("%B-%d-%Y") | |
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S') | |
for i in range(screens): | |
temp_image = image[0:height, i * slice_size: (i + 1) * slice_size] | |
folder_image = str(p) + "Screenshot_{1}{0}.png".format(i, st) | |
cv2.imwrite(folder_image, temp_image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need to take a screnshot from multi windows and cut for separate frames - this script will help you.
requirements:
imutils==0.4.5
numpy==1.13.3
opencv-python==3.4.0.12
Pillow==5.0.0
PyAutoGUI==0.9.36
PyMsgBox==1.0.6
PyScreeze==0.1.13
python-xlib==0.21
python3-xlib==0.15
PyTweening==1.0.3
six==1.11.0