Skip to content

Instantly share code, notes, and snippets.

@doubledare704
Created January 5, 2018 14:11
Show Gist options
  • Save doubledare704/b96c12ddc59be82565ccd72d8eb7595e to your computer and use it in GitHub Desktop.
Save doubledare704/b96c12ddc59be82565ccd72d8eb7595e to your computer and use it in GitHub Desktop.
python screenshots with opencv
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)
@doubledare704
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment