fullauto rect detection done, and...

- window.show now also shows ready images,
- removed debug condition to print "Running with admin"
This commit is contained in:
DESKTOP-JVKHS7I\Adam 2020-06-03 07:11:54 +05:30
parent 686252d39e
commit 49cc7f191d
4 changed files with 54 additions and 10 deletions

View File

@ -29,7 +29,7 @@ def initialize(c: Config, window_to_hide):
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
if is_admin and c.get("debug"):
if is_admin:
logging.info("Running with admin privileges")
try:

View File

@ -12,7 +12,7 @@ class IEngine(ABC):
def __init__(self, config, gui_ref: 'Callable[[], GUI]'):
self.get_gui = gui_ref
self.start = False
self.fishPixWindow = None
self.window = None
self.thread = None
self.config = config

View File

@ -1,13 +1,55 @@
import cv2
import logging
import time
import numpy as np
import pywintypes
from fishy.engine.IEngine import IEngine
from fishy.engine.window import Window
class FullAuto(IEngine):
def run(self):
self.gui.bot_started(True)
try:
Window.init(False)
except pywintypes.error:
logging.info("Game window not found")
self.start = False
return
self.window = Window(color=cv2.COLOR_RGB2GRAY)
if self.get_gui is not None:
self.gui.bot_started(True)
while self.start:
logging.debug("running full auto")
time.sleep(0.5)
Window.loop()
img = self.window.get_capture()
img = cv2.inRange(img, 0, 1)
cnt, h = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
"""
code from https://stackoverflow.com/a/45770227/4512396
"""
crop = self.window.get_capture()
for i in range(len(cnt)):
area = cv2.contourArea(cnt[i])
if 5000 < area < 100000:
mask = np.zeros_like(img)
cv2.drawContours(mask, cnt, i, 255, -1)
x, y, w, h = cv2.boundingRect(cnt[i])
crop = self.window.get_capture()[y:h + y, x:w + x]
# cnt, h = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# print(cnt)
self.window.show("test", ready_img=crop)
Window.loop_end()
self.gui.bot_started(False)
if __name__ == '__main__':
bot = FullAuto(None, None)
bot.toggle_start()

View File

@ -108,18 +108,20 @@ class Window:
else:
return func(self.get_capture())
def show(self, name, resize=None, func=None):
def show(self, name, resize=None, func=None, ready_img=None):
"""
Displays the processed image for debugging purposes
:param name: unique name for the image, used to create a new window
:param resize: scale the image to make small images more visible
:param func: function to process the image
"""
img = self.processed_image(func)
if resize is not None:
img = imutils.resize(img, width=resize)
if ready_img is None:
img = self.processed_image(func)
if resize is not None:
img = imutils.resize(img, width=resize)
else:
img = ready_img
cv2.imshow(name, img)
Window.showing = True