see screen recording app in action [here] (https://youtu.be/WNsNw1bQbrM)
credit to marcello tania who co-created this!
import numpy as np
import cv2
import pyautogui
from PIL import Image
# take screenshot using pyautogui
image = pyautogui.screenshot()
# this will return the image as PIL and
# store in `image`
# if you need to save the image as a
# file, pass the path of the file as
# an argument like this
image1 = pyautogui.screenshot(region=(0,0, 300, 400))
image1.save(r"C:\Users\..")
# Find the location of the title on the screen
titleLocation = pyautogui.locateOnScreen('title2.PNG')
image1 = pyautogui.screenshot(region=(int(titleLocation[0])-100,int(titleLocation[1])+60, 395, 390))
path =r"C:\Users\emma_odom\Dropbox (MIT)\Emma\Behavior_Code_Emma\snapshot_env\image.png"
image1.save(path)
live=True
# Find the location of the title on the screen
titleLocation = pyautogui.locateOnScreen('title2.PNG')
while live:
image1 = pyautogui.screenshot(region=(int(titleLocation[0])-100,int(titleLocation[1])+60, 395, 390))
np_img = np.array(image1)
np_img.shape
# Display the captured frame
cv2.imshow('Ema', np_img)
# Press 'q' to exit the loop
if cv2.waitKey(1) == ord('q'):
live = False
break
# waits for user to press any key
# (this is necessary to avoid Python kernel form crashing)
cv2.waitKey(0)
# closing all open windows
cv2.destroyAllWindows()