removed ocr things, using blob detection to find qr code, using qr code to get data from eso

This commit is contained in:
Adam Saudagar 2021-04-13 20:22:55 +05:30
parent 7f316f6fa6
commit 10cbd899f8
7 changed files with 64 additions and 113 deletions

View File

@ -52,11 +52,6 @@ class Calibrate:
self._callibrate_state = -1
self.engine = engine
# region getters
@property
def crop(self):
return _get_factor("crop")
@property
def move_factor(self):
return _get_factor("move_factor")
@ -72,18 +67,11 @@ class Calibrate:
# endregion
def all_callibrated(self):
return self.crop is not None and self.move_factor is not None and self.rot_factor is not None
return self.move_factor is not None and self.rot_factor is not None
def toggle_show(self):
self.engine.show_crop = not self.engine.show_crop
def update_crop(self, enable_crop=True):
if enable_crop:
self.engine.show_crop = True
crop = get_crop_coods(self.engine.window)
_update_factor("crop", crop)
self.engine.window.crop = crop
def walk_calibrate(self):
walking_time = 3

View File

@ -17,7 +17,7 @@ def get_controls(engine: FullAuto):
Key.DOWN: (Recorder(engine).toggle_recording, "start/stop record"),
}),
("CALIBRATE", {
Key.RIGHT: (engine.calibrate.update_crop, "cropping"),
Key.RIGHT: (None, ""),
Key.UP: (engine.calibrate.walk_calibrate, "walking"),
Key.LEFT: (engine.calibrate.rotate_calibrate, "rotation"),
Key.DOWN: (engine.calibrate.time_to_reach_bottom_callibrate, "look up down")

View File

@ -14,8 +14,7 @@ import time
import numpy as np
import pytesseract
from fishy.engine.fullautofisher.tesseract import is_tesseract_installed, downlaoad_and_extract_tesseract, \
get_values_from_image
from fishy.engine.fullautofisher.qr_detection import get_values_from_image, get_qr_location
from fishy.engine.semifisher.fishing_mode import FishingMode
from fishy.engine import SemiFisherEngine
@ -27,7 +26,6 @@ from pynput import keyboard, mouse
from fishy.helper import hotkey, helper
from fishy.helper.config import config
from fishy.helper.downloader import download_file_from_google_drive
from fishy.helper.helper import sign
from fishy.helper.hotkey import Key
@ -36,12 +34,11 @@ kb = keyboard.Controller()
def image_pre_process(img):
scale_percent = 200 # percent of original size
scale_percent = 100 # percent of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
img = cv2.bitwise_not(img)
return img
@ -73,7 +70,6 @@ class FullAuto(IEngine):
self.show_crop = False
def run(self):
self.show_crop = False
FullAuto.state = State.NONE
self.gui.bot_started(True)
@ -83,21 +79,19 @@ class FullAuto(IEngine):
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
try:
if self.calibrate.crop is None:
self.calibrate.update_crop(enable_crop=False)
self.window.crop = self.calibrate.crop
if not is_tesseract_installed():
logging.info("tesseract not found")
downlaoad_and_extract_tesseract()
self.window.crop = get_qr_location(self.window.get_capture())
if self.window.crop is None:
print("FishyQR not found")
self.start = False
if not self.calibrate.all_callibrated():
logging.error("you need to callibrate first")
self.controls.initialize()
while self.start and WindowClient.running():
if self.show_crop:
self.window.show(self.show_crop, func=image_pre_process)
if not self.show_crop:
else:
time.sleep(0.1)
except:
traceback.print_exc()
@ -173,11 +167,11 @@ class FullAuto(IEngine):
def look_for_hole(self):
self._hole_found_flag = False
if FishingMode.CurrentMode == fishing_mode.State.LOOK:
if FishingMode.CurrentMode == fishing_mode.State.LOOKING:
return True
def found_hole(e):
if e == fishing_mode.State.LOOK:
if e == fishing_mode.State.LOOKING:
self._hole_found_flag = True
fishing_mode.subscribers.append(found_hole)

View File

@ -0,0 +1,51 @@
import logging
import os
from datetime import datetime
import cv2
from fishy.helper.helper import get_documents
import numpy as np
from pyzbar.pyzbar import decode
def get_qr_location(og_img):
"""
code from https://stackoverflow.com/a/45770227/4512396
"""
gray = cv2.bilateralFilter(og_img, 11, 17, 17)
kernel = np.ones((5, 5), np.uint8)
erosion = cv2.erode(gray, kernel, iterations=2)
kernel = np.ones((4, 4), np.uint8)
img = cv2.dilate(erosion, kernel, iterations=2)
cnt, h = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
valid_crops = []
for i in range(len(cnt)):
area = cv2.contourArea(cnt[i])
if 500 < area < 100000:
mask = np.zeros_like(img)
cv2.drawContours(mask, cnt, i, 255, -1)
x, y, w, h = cv2.boundingRect(cnt[i])
qr_result = decode(og_img[y:h + y, x:w + x])
if qr_result:
valid_crops.append(((x, y, x + w, y + h), area))
return min(valid_crops, key=lambda c: c[1])[0] if valid_crops else None
# noinspection PyBroadException
def get_values_from_image(img):
try:
for qr in decode(img):
vals = qr.data.decode('utf-8').split(",")
return float(vals[0]), float(vals[1]), float(vals[2])
logging.error("FishyQR not found, try restarting the engine")
return None
except Exception:
logging.error("Couldn't read coods, make sure 'crop' calibration is correct")
cv2.imwrite(os.path.join(get_documents(), "fishy_failed_reads", f"{datetime.now()}.jpg"), img)
return None

View File

@ -1,50 +0,0 @@
import logging
import os
import tempfile
import uuid
from datetime import datetime
from zipfile import ZipFile
import cv2
import pytesseract
from fishy.helper.downloader import download_file_from_google_drive
from fishy.helper.helper import get_documents
directory = os.path.join(os.environ["APPDATA"], "Tesseract-OCR")
def downlaoad_and_extract_tesseract():
logging.info("Tesseract-OCR downlaoding, Please wait...")
f = tempfile.NamedTemporaryFile(delete=False)
download_file_from_google_drive("16llzcBlaCsG9fm-rY2dD4Gvopnhm3XoE", f)
f.close()
logging.info("Tesseract-OCR downloaded, now installing")
with ZipFile(f.name, 'r') as z:
z.extractall(path=directory)
logging.info("Tesseract-OCR installed")
def is_tesseract_installed():
return os.path.exists(os.path.join(os.environ["APPDATA"], "Tesseract-OCR"))
# noinspection PyBroadException
def get_values_from_image(img):
try:
pytesseract.pytesseract.tesseract_cmd = directory + '/tesseract.exe'
tessdata_dir_config = f'--tessdata-dir "{directory}" -c tessedit_char_whitelist=0123456789.'
text = pytesseract.image_to_string(img, lang="eng", config=tessdata_dir_config)
text = text.replace(" ", "")
vals = text.split(":")
return float(vals[0]), float(vals[1]), float(vals[2])
except Exception:
logging.error("Couldn't read coods, make sure 'crop' calibration is correct")
cv2.imwrite(os.path.join(get_documents(), "fishy_failed_reads", f"{datetime.now()}.jpg"), img)
return None

View File

@ -1,31 +0,0 @@
import requests
def download_file_from_google_drive(id, file):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params={'id': id}, stream=True)
token = get_confirm_token(response)
if token:
params = {'id': id, 'confirm': token}
response = session.get(URL, params=params, stream=True)
save_response_content(response, file)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, f):
CHUNK_SIZE = 32768
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)

View File

@ -10,7 +10,6 @@ requests
beautifulsoup4
whatsmyip
pynput
pytesseract
keyboard
playsound
event-scheduler