Skip to content

Instantly share code, notes, and snippets.

@badjano
Last active Nov 22, 2021
Embed
What would you like to do?
import numpy as np
import cv2
from PIL import ImageGrab
from screeninfo import get_monitors
monitors = []
for m in get_monitors():
monitors.append((m.x, m.y, m.x + m.width, m.y + m.height))
bbox = monitors[0]
while True:
img = ImageGrab.grab(bbox=bbox)
img_np = np.array(img)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
cv2.imshow("Screen", frame)
key = cv2.waitKey(1)
for i, m in enumerate(monitors):
if key == i + 49:
bbox = m
if key == 27:
break
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment