mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
added debug option to save capture
This commit is contained in:
parent
2ca4107595
commit
df4deda1f2
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import uuid
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@ -7,6 +8,7 @@ import imutils
|
|||||||
from fishy.engine.common import window_server
|
from fishy.engine.common import window_server
|
||||||
from fishy.engine.common.window_server import Status, WindowServer
|
from fishy.engine.common.window_server import Status, WindowServer
|
||||||
from fishy.helper import helper
|
from fishy.helper import helper
|
||||||
|
from fishy.helper.config import config
|
||||||
|
|
||||||
|
|
||||||
class WindowClient:
|
class WindowClient:
|
||||||
@ -22,11 +24,37 @@ class WindowClient:
|
|||||||
self.color = color
|
self.color = color
|
||||||
self.crop = crop
|
self.crop = crop
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.show_name = show_name
|
self.show_name = f"window client {len(WindowClient.clients)}"
|
||||||
|
|
||||||
if len(WindowClient.clients) == 0:
|
|
||||||
window_server.start()
|
|
||||||
WindowClient.clients.append(self)
|
WindowClient.clients.append(self)
|
||||||
|
if len(WindowClient.clients) > 0 and WindowServer.status != Status.RUNNING:
|
||||||
|
window_server.start()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def running():
|
||||||
|
return WindowServer.status == Status.RUNNING
|
||||||
|
|
||||||
|
def processed_image(self, func=None):
|
||||||
|
"""
|
||||||
|
processes the image using the function provided
|
||||||
|
:param func: function to process image
|
||||||
|
:return: processed image
|
||||||
|
"""
|
||||||
|
if WindowServer.status == Status.CRASHED:
|
||||||
|
return None
|
||||||
|
|
||||||
|
img = self._get_capture()
|
||||||
|
|
||||||
|
if img is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if func:
|
||||||
|
img = func(img)
|
||||||
|
|
||||||
|
if config.get("show_grab", 0):
|
||||||
|
self._show(img)
|
||||||
|
|
||||||
|
return img
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
if self in WindowClient.clients:
|
if self in WindowClient.clients:
|
||||||
@ -34,11 +62,7 @@ class WindowClient:
|
|||||||
if len(WindowClient.clients) == 0:
|
if len(WindowClient.clients) == 0:
|
||||||
window_server.stop()
|
window_server.stop()
|
||||||
|
|
||||||
@staticmethod
|
def _get_capture(self):
|
||||||
def running():
|
|
||||||
return WindowServer.status == Status.RUNNING
|
|
||||||
|
|
||||||
def get_capture(self):
|
|
||||||
"""
|
"""
|
||||||
copies the recorded screen and then pre processes its
|
copies the recorded screen and then pre processes its
|
||||||
:return: game window image
|
:return: game window image
|
||||||
@ -71,49 +95,12 @@ class WindowClient:
|
|||||||
|
|
||||||
return temp_img
|
return temp_img
|
||||||
|
|
||||||
def processed_image(self, func=None):
|
# noinspection PyUnresolvedReferences
|
||||||
"""
|
def _show(self, img):
|
||||||
processes the image using the function provided
|
|
||||||
:param func: function to process image
|
|
||||||
:return: processed image
|
|
||||||
"""
|
|
||||||
if WindowServer.status == Status.CRASHED:
|
|
||||||
return None
|
|
||||||
|
|
||||||
img = self.get_capture()
|
|
||||||
|
|
||||||
if img is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if func is None:
|
|
||||||
return img
|
|
||||||
|
|
||||||
return func(img)
|
|
||||||
|
|
||||||
def show(self, to_show, resize=None, func=None):
|
|
||||||
"""
|
"""
|
||||||
Displays the processed image for debugging purposes
|
Displays the processed image for debugging purposes
|
||||||
:param to_show: false to destroy the window
|
|
||||||
:param resize: scale the image to make small images more visible
|
|
||||||
:param func: function to process the image
|
|
||||||
"""
|
"""
|
||||||
if WindowServer.status == Status.CRASHED:
|
if WindowServer.status == Status.CRASHED:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.show_name:
|
helper.save_img(self.show_name, img)
|
||||||
logging.warning("You need to assign a name first")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not to_show:
|
|
||||||
cv2.destroyWindow(self.show_name)
|
|
||||||
return
|
|
||||||
|
|
||||||
img = self.processed_image(func)
|
|
||||||
|
|
||||||
if img is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
if resize is not None:
|
|
||||||
img = imutils.resize(img, width=resize)
|
|
||||||
cv2.imshow(self.show_name, img)
|
|
||||||
cv2.waitKey(25)
|
|
||||||
|
@ -2,10 +2,13 @@ import logging
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from mss.base import MSSBase
|
from mss.base import MSSBase
|
||||||
|
|
||||||
from fishy.engine.common import screenshot
|
from fishy.engine.common import screenshot
|
||||||
|
from fishy.helper import helper
|
||||||
|
from fishy.helper.config import config
|
||||||
from fishy.helper.helper import print_exc
|
from fishy.helper.helper import print_exc
|
||||||
from fishy.osservices.os_services import os_services
|
from fishy.osservices.os_services import os_services
|
||||||
|
|
||||||
@ -37,17 +40,26 @@ def init():
|
|||||||
WindowServer.crop = os_services.get_game_window_rect()
|
WindowServer.crop = os_services.get_game_window_rect()
|
||||||
|
|
||||||
if WindowServer.crop is None or not WindowServer.sslib.setup():
|
if WindowServer.crop is None or not WindowServer.sslib.setup():
|
||||||
logging.error("Game window not found")
|
logging.error("Game window not found by window_server")
|
||||||
WindowServer.status = Status.CRASHED
|
WindowServer.status = Status.CRASHED
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_cropped_screenshot():
|
def get_cropped_screenshot():
|
||||||
ss = WindowServer.sslib.grab()
|
ss = WindowServer.sslib.grab()
|
||||||
|
|
||||||
|
if config.get("show_grab", 0):
|
||||||
|
helper.save_img("full screen", ss)
|
||||||
|
|
||||||
crop = WindowServer.crop
|
crop = WindowServer.crop
|
||||||
cropped_ss = ss[crop[1]:crop[3], crop[0]:crop[2]]
|
cropped_ss = ss[crop[1]:crop[3], crop[0]:crop[2]]
|
||||||
|
|
||||||
if cropped_ss.size == 0:
|
if cropped_ss.size == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if config.get("show_grab", 0):
|
||||||
|
helper.save_img("Game window", cropped_ss)
|
||||||
|
|
||||||
return cropped_ss
|
return cropped_ss
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,14 @@ def _create(gui: 'GUI'):
|
|||||||
debug_menu.add_command(label="Check QR Value",
|
debug_menu.add_command(label="Check QR Value",
|
||||||
command=lambda: gui.engine.check_qr_val())
|
command=lambda: gui.engine.check_qr_val())
|
||||||
|
|
||||||
|
def toggle_show_grab():
|
||||||
|
new_val = 1 - config.get("show_grab", 0)
|
||||||
|
show_grab_var.set(new_val)
|
||||||
|
config.set("show_grab", new_val)
|
||||||
|
show_grab_var = tk.IntVar()
|
||||||
|
show_grab_var.set(config.get("show_grab", 0))
|
||||||
|
debug_menu.add_checkbutton(label="Show Grab Window", variable=show_grab_var, command=lambda: toggle_show_grab(), onvalue=1)
|
||||||
|
|
||||||
def select_sslib(selected_i):
|
def select_sslib(selected_i):
|
||||||
config.set("sslib", selected_i)
|
config.set("sslib", selected_i)
|
||||||
sslib_var.set(selected_i)
|
sslib_var.set(selected_i)
|
||||||
|
@ -7,12 +7,14 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
from datetime import datetime
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from uuid import uuid1
|
from uuid import uuid1
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
import cv2
|
||||||
import requests
|
import requests
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
|
|
||||||
@ -205,3 +207,14 @@ def kill_thread(thread):
|
|||||||
def print_exc():
|
def print_exc():
|
||||||
logging.error(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
|
def save_img(show_name, img):
|
||||||
|
img_path = os.path.join(os_services.get_documents_path(), "fishy_debug", "imgs", show_name)
|
||||||
|
if not os.path.exists(img_path):
|
||||||
|
os.makedirs(img_path)
|
||||||
|
|
||||||
|
t = time.strftime("%Y.%m.%d.%H.%M.%S")
|
||||||
|
cv2.imwrite(
|
||||||
|
os.path.join(img_path, f"{t}.png"),
|
||||||
|
img)
|
||||||
|
Loading…
Reference in New Issue
Block a user