Fix match template
This commit is contained in:
+1
-1
@@ -8,6 +8,6 @@ class MainAgent:
|
||||
|
||||
def startFishBot(self):
|
||||
self.monitor.startScreenCaptureThread()
|
||||
self.fishingBot.test()
|
||||
self.fishingBot.run()
|
||||
|
||||
|
||||
|
||||
+8
-27
@@ -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):
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 MiB |
Reference in New Issue
Block a user