diff --git a/assets/FishTest3.png b/assets/FishTest3.png deleted file mode 100644 index e63c9c8..0000000 Binary files a/assets/FishTest3.png and /dev/null differ diff --git a/assets/screenshot.jpg b/assets/screenshot.jpg new file mode 100644 index 0000000..755ca0a Binary files /dev/null and b/assets/screenshot.jpg differ diff --git a/bots/fishing/FishingAgent.py b/bots/fishing/FishingAgent.py index d4786fb..50b6b00 100644 --- a/bots/fishing/FishingAgent.py +++ b/bots/fishing/FishingAgent.py @@ -53,7 +53,8 @@ class FishingAgent: while True: time.sleep(1) self.logger.log("###") - self.monitor.findMatch(self.fishingBobberImg) + point = self.monitor.findMatch(self.fishingBobberImg) + pyautogui.moveTo(point[0], point[1]) def run(self): if self.monitor.screenshot is None: diff --git a/core/MainAgent.py b/core/MainAgent.py index 57c7a37..0bec72e 100644 --- a/core/MainAgent.py +++ b/core/MainAgent.py @@ -8,6 +8,6 @@ class MainAgent: def startFishBot(self): self.monitor.startScreenCaptureThread() - self.fishingBot.test() + self.fishingBot.run() diff --git a/core/Monitor.py b/core/Monitor.py index 814d51f..43a8560 100644 --- a/core/Monitor.py +++ b/core/Monitor.py @@ -1,11 +1,9 @@ import time -import os from threading import Thread from screeninfo import get_monitors import pyautogui import numpy as np import cv2 as cv -from matplotlib import pyplot as plt from core.Logger import Logger FPS_REPORT_DELAY = 3 @@ -32,11 +30,9 @@ class Monitor: 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) + newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.IMREAD_GRAYSCALE) self.screenshot = newScreenshot - + cv.imwrite("assets/screenshot.jpg", self.screenshot) currTime = time.time() if currTime - fpsPrintTime >= FPS_REPORT_DELAY: self.fps = 1 / (currTime - loopTime) @@ -48,13 +44,11 @@ class Monitor: self.screenThread.start() self.logger.log("Main Agent: Thread started") - def findMatch(self, img, method = "TM_CCOEFF_NORMED"): + def findMatch(self, template, method = "TM_CCOEFF_NORMED"): methodInt = getattr(cv, method) - - herePath = os.path.dirname(os.path.realpath(__file__)) - template = cv.imread(os.path.join(herePath, "assets", "FishTest3.png"), cv.IMREAD_GRAYSCALE) - - res = cv.matchTemplate(img, template, methodInt) + screen = cv.imread("assets/screenshot.jpg", cv.IMREAD_GRAYSCALE) + assert template is not None, "file could not be read, check with os.path.exists()" + res = cv.matchTemplate(screen, template, methodInt) w, h = template.shape[::-1] min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res) @@ -64,21 +58,8 @@ class Monitor: else: top_left = max_loc bottom_right = (top_left[0] + w, top_left[1] + h) - - cv.rectangle(img,top_left, bottom_right, 255, 2) - - plt.subplot(121) - plt.imshow(res,cmap = 'gray') - plt.title('Matching Result') - plt.xticks([]) - plt.yticks([]) - plt.subplot(122) - plt.imshow(img,cmap = 'gray') - plt.title('Detected Point') - plt.xticks([]) - plt.yticks([]) - plt.suptitle(method) - plt.show() + + return (top_left[0] + bottom_right[0]) / 2, (top_left[1] + bottom_right[1]) / 2 def stopScreenCaptureThread(self): if (self.screenThread): diff --git a/core/assets/FishTest3.png b/core/assets/FishTest3.png deleted file mode 100644 index e63c9c8..0000000 Binary files a/core/assets/FishTest3.png and /dev/null differ diff --git a/in_memory_to_disk.png b/in_memory_to_disk.png deleted file mode 100644 index 5cb85a3..0000000 Binary files a/in_memory_to_disk.png and /dev/null differ diff --git a/tests/assets/Bobber.png b/tests/assets/Bobber.png deleted file mode 100644 index 07f0568..0000000 Binary files a/tests/assets/Bobber.png and /dev/null differ diff --git a/tests/assets/Bobber2.png b/tests/assets/Bobber2.png deleted file mode 100644 index 9bbe4b4..0000000 Binary files a/tests/assets/Bobber2.png and /dev/null differ diff --git a/tests/assets/FishIcon.png b/tests/assets/FishIcon.png deleted file mode 100644 index 832155b..0000000 Binary files a/tests/assets/FishIcon.png and /dev/null differ diff --git a/tests/assets/FishTest3.png b/tests/assets/FishTest3.png deleted file mode 100644 index e63c9c8..0000000 Binary files a/tests/assets/FishTest3.png and /dev/null differ diff --git a/tests/assets/pecheTest2.png b/tests/assets/pecheTest2.png deleted file mode 100644 index 30b5dee..0000000 Binary files a/tests/assets/pecheTest2.png and /dev/null differ diff --git a/tests/bobber.jpg b/tests/bobber.jpg new file mode 100644 index 0000000..e8fa591 Binary files /dev/null and b/tests/bobber.jpg differ diff --git a/tests/screen.jpg b/tests/screen.jpg new file mode 100644 index 0000000..3b9132e Binary files /dev/null and b/tests/screen.jpg differ diff --git a/tests/templateMatching.py b/tests/templateMatching.py index cc11ab1..58a4580 100644 --- a/tests/templateMatching.py +++ b/tests/templateMatching.py @@ -1,14 +1,11 @@ -import os import cv2 as cv +import numpy as np from matplotlib import pyplot as plt -# interpolate here_path to get the path to the fishing target image -herePath = os.path.dirname(os.path.realpath(__file__)) - -img = cv.imread(os.path.join(herePath, "assets", "Bobber2.png"), cv.IMREAD_GRAYSCALE) +img = cv.imread('screen.jpg', cv.IMREAD_GRAYSCALE) assert img is not None, "file could not be read, check with os.path.exists()" img2 = img.copy() -template = cv.imread(os.path.join(herePath, "assets", "FishTest3.png"), cv.IMREAD_GRAYSCALE) +template = cv.imread('bobber.jpg', cv.IMREAD_GRAYSCALE) assert template is not None, "file could not be read, check with os.path.exists()" w, h = template.shape[::-1] @@ -33,16 +30,10 @@ for meth in methods: cv.rectangle(img,top_left, bottom_right, 255, 2) - plt.subplot(121) - plt.imshow(res,cmap = 'gray') - plt.title('Matching Result') - plt.xticks([]) - plt.yticks([]) - plt.subplot(122) - plt.imshow(img,cmap = 'gray') - plt.title('Detected Point') - plt.xticks([]) - plt.yticks([]) + plt.subplot(121),plt.imshow(res,cmap = 'gray') + plt.title('Matching Result'), plt.xticks([]), plt.yticks([]) + plt.subplot(122),plt.imshow(img,cmap = 'gray') + plt.title('Detected Point'), plt.xticks([]), plt.yticks([]) plt.suptitle(meth) plt.show() \ No newline at end of file