Created
August 28, 2017 18:09
-
-
Save mascot27/b87791bab146645327f2d6caeb07a0bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from PIL import ImageGrab | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 | |
import time | |
import pyautogui | |
print("launched") | |
time.sleep(2) | |
screenCapture_heigth = 200 | |
screeCapture_width = 200 | |
capturing = True | |
while(True): | |
cursor_position_x, cursor_position_y = pyautogui.position() | |
img = ImageGrab.grab(bbox=(cursor_position_x-screenCapture_heigth, cursor_position_y-screeCapture_width, | |
cursor_position_x+screenCapture_heigth, cursor_position_y+screeCapture_width)) | |
# bbox specifies specific region (bbox= x,y,width,height *starts top-left) | |
# convert to opencv's format | |
img_np = np.array(img) # this is the array obtained from conversion | |
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY) | |
# note: generally, we use grayscale images for processing because this use lot less ressources | |
cv2.imshow("screenCast", frame) | |
if(cv2.waitKey(1) & 0xFF == ord('q')): # -> press 'q' to quit | |
break | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment