Make fishing agent capable of detecting bobber
This commit is contained in:
+18
-5
@@ -30,8 +30,9 @@ class Monitor:
|
||||
fpsPrintTime = time.time()
|
||||
while True:
|
||||
newScreenshot = pyautogui.screenshot()
|
||||
newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.IMREAD_GRAYSCALE)
|
||||
self.screenshot = newScreenshot
|
||||
newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.COLOR_RGB2BGR)
|
||||
grayScreenshot = cv.cvtColor(newScreenshot, cv.COLOR_BGR2GRAY)
|
||||
self.screenshot = grayScreenshot
|
||||
cv.imwrite("assets/screenshot.jpg", self.screenshot)
|
||||
currTime = time.time()
|
||||
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
|
||||
@@ -46,12 +47,16 @@ class Monitor:
|
||||
|
||||
def findMatch(self, template, method = "TM_CCOEFF_NORMED"):
|
||||
methodInt = getattr(cv, method)
|
||||
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)
|
||||
res = cv.matchTemplate(self.screenshot, template, methodInt)
|
||||
w, h = template.shape[::-1]
|
||||
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
|
||||
|
||||
matchRatio = max_val * 100
|
||||
self.logger.log(matchRatio)
|
||||
if (matchRatio < 40):
|
||||
self.logger.log("Cannot find matching result...")
|
||||
return -1
|
||||
|
||||
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
|
||||
if method in [cv.TM_SQDIFF, cv.TM_SQDIFF_NORMED]:
|
||||
top_left = min_loc
|
||||
@@ -61,6 +66,14 @@ class Monitor:
|
||||
|
||||
return (top_left[0] + bottom_right[0]) / 2, (top_left[1] + bottom_right[1]) / 2
|
||||
|
||||
def findMatchAndMoveToPosition(self, template, method = "TM_CCOEFF_NORMED"):
|
||||
point = self.findMatch(template, method)
|
||||
if (point == -1):
|
||||
return -1
|
||||
time.sleep(0.2)
|
||||
pyautogui.moveTo(point[0], point[1])
|
||||
time.sleep(0.15)
|
||||
|
||||
def stopScreenCaptureThread(self):
|
||||
if (self.screenThread):
|
||||
self.screenThread.terminate()
|
||||
|
||||
Reference in New Issue
Block a user