Created
April 25, 2017 08:09
-
-
Save S1M0N38/26224b8b750200ce31d1b388da929928 to your computer and use it in GitHub Desktop.
MSS (written in pure python, working on windows, mac, linux) is capable to grab the screen at ~40 fps at 800x400 resolution.
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 cv2 | |
import time | |
from mss import mss | |
from PIL import Image | |
'''Macbook have a bug about box's dimensions, can be just multiple of 16 | |
but this bug will be fix soon in the next release''' | |
box = { "top": 10, "left": 10, "width": 400, "height": 320} | |
sct = mss() | |
while True: | |
t = time.time() | |
sct.get_pixels(box) | |
image = Image.frombytes('RGB', (sct.width, sct.height), sct.image) | |
# Could be useful in MAC OS | |
#b, g, r = image.split() | |
#image = Image.merge("RGB", (r, g, b)) | |
cv2.imshow('test', np.array(image)) | |
print('fps: {}'.format(1/(time.time()-t))) | |
if cv2.waitKey(25) & 0xFF == ord('q'): | |
cv2.destroyAllWindows() | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment