Wowxel/core/Monitor.py

39 lines
1.0 KiB
Python

import time
import pyautogui
import numpy as np
import cv2 as cv
from screeninfo import get_monitors
FPS_REPORT_DELAY = 3
class Monitor:
def __init__(self):
self.monitor = None
self.screenshot = None
self.getMonitor()
def getMonitor(self):
for monitor in get_monitors():
if (monitor.is_primary):
self.monitor = monitor
def updateScreen(self):
print("Starting computer vision screen update...")
print("Detected display resolution: " + str(self.monitor.width) + " x " + str(self.monitor.height))
loopTime = time.time()
fpsPrintTime = time.time()
while True:
newScreenshot = pyautogui.screenshot()
newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.COLOR_RGB2BGR)
cv.imwrite("in_memory_to_disk.png", newScreenshot)
self.screenshot = newScreenshot
currTime = time.time()
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
print('FPS: {}'.format(1 / (currTime - loopTime)))
fpsPrintTime = currTime
loopTime = currTime