Add main agent, cli and opencv image template comparison test
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
from threading import Thread
|
||||
from core.Monitor import Monitor
|
||||
|
||||
class MainAgent:
|
||||
def __init__(self) -> None:
|
||||
self.monitor = Monitor()
|
||||
self.screenThread = None
|
||||
|
||||
def startScreenCaptureThread(self):
|
||||
self.screenThread = Thread(target=self.monitor.updateScreen, args=(self,), name="Update screen thread", daemon=True)
|
||||
self.screenThread.start()
|
||||
print("Main Agent: Thread started")
|
||||
|
||||
def stopScreenCaptureThread(self):
|
||||
if (self.screenThread):
|
||||
self.screenThread.terminate()
|
||||
print("Main Agent: Thread terminated")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import cv2 as cv
|
||||
|
||||
class CLIAgent:
|
||||
def __init__(self, mainAgent) -> None:
|
||||
self.isRunning = False
|
||||
if (not mainAgent):
|
||||
raise Exception("CLI: Main agent not found...")
|
||||
self.mainAgent = mainAgent
|
||||
|
||||
def printMenu(self):
|
||||
print("Enter a command:")
|
||||
print("\tH\tHelp.")
|
||||
print("\tF\tStart the fishing agent.")
|
||||
print("\tQ\tQuit.")
|
||||
print("$>> ", end='')
|
||||
|
||||
def run(self):
|
||||
self.isRunning = True
|
||||
|
||||
self.printMenu()
|
||||
while self.isRunning:
|
||||
userInput = input()
|
||||
userInput = str.lower(userInput).strip()
|
||||
|
||||
if (userInput == "f"):
|
||||
print("Starting Fishing bot...")
|
||||
self.mainAgent.startScreenCaptureThread()
|
||||
break
|
||||
# fishingAgent = FishingAgent(mainAgent)
|
||||
# fishingAgent.run()
|
||||
elif (userInput == "h"):
|
||||
self.printMenu()
|
||||
break
|
||||
elif (userInput == "q"):
|
||||
cv.destroyAllWindows()
|
||||
print("Exiting application...")
|
||||
self.isRunning = False
|
||||
break
|
||||
else:
|
||||
print("Unknown Command.")
|
||||
self.printMenu()
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user