Возврат с easyocr к tessaract

This commit is contained in:
2023-03-12 03:31:46 +03:00
parent 1073dee6ca
commit 7fc3f93da4
2 changed files with 32 additions and 51 deletions

61
main.py
View File

@@ -7,13 +7,15 @@ import cv2
import pygetwindow as gw
import pyautogui as pg
from pyclick import HumanClicker
import easyocr
from pytesseract import pytesseract as pt
import pandas as pd
debug = True
win_name = "EVE - Nostrom Stone"
pt.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(message)s",
@@ -23,9 +25,6 @@ logging.basicConfig(
logging.info("Бот: запущен")
reader = easyocr.Reader(["en"], gpu=True)
logging.info("Бот: модели загружены")
hc = HumanClicker()
@@ -107,29 +106,35 @@ def highlite_boxes(boxes, module_name, file_name):
def get_boxes(screenshot):
results = reader.readtext(
results = pt.image_to_data(
cv2.bitwise_not(cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)),
low_text=0.4,
width_ths=1.5,
lang="eng",
output_type=pt.Output.DATAFRAME,
config="--psm 3",
)
logging.debug("Боксы: получены")
results = results.loc[
(results["conf"] > 30)
& (results["text"].notnull())
& (len(results["text"].str.strip()) > 0)
]
results_frame = pd.DataFrame(
[
[
int(result[0][0][0]), # tl_x
int(result[0][0][1]), # tl_y
int(result[0][1][0]), # tr_x
int(result[0][1][1]), # tr_y
int(result[0][2][0]), # br_x
int(result[0][2][1]), # br_y
int(result[0][3][0]), # bl_x
int(result[0][3][1]), # bl_y
int((result[0][0][0] + result[0][1][0]) / 2), # cent_x
int((result[0][0][1] + result[0][3][1]) / 2), # cent_y
result[1].lower(), # text
result.left, # tl_x
result.top, # tl_y
result.left + result.width, # tr_x
result.top, # tr_y
result.left + result.width, # br_x
result.top + result.height, # br_y
result.left, # bl_x
result.top + result.height, # bl_y
int(result.left + result.width / 2), # cent_x
int(result.top + result.height / 2), # cent_y
result.text.lower(), # text
]
for result in results
for result in results.itertuples(index=False)
],
columns=[
"tl_x",
@@ -147,7 +152,7 @@ def get_boxes(screenshot):
)
results_frame = results_frame.loc[results_frame["text"].str.len() > 2]
logging.debug("Боксы: переведены во фрейм")
logging.debug("Боксы: переведены в удобный фрейм")
logging.info("Боксы: готовы")
if debug:
@@ -164,7 +169,7 @@ def get_targets(boxes_frame, text=False):
boxes_frame["text"] == "name", ["cent_x", "cent_y"]
].values[0]
anchor_bot_y = boxes_frame.loc[
boxes_frame["text"] == "drones in", "cent_y"
boxes_frame["text"] == "hobgoblin", "cent_y"
].values[0]
targets = boxes_frame.loc[
@@ -203,7 +208,7 @@ def go_to_minefield():
global screenshot
screenshot = get_screenshot()
boxes_frame = get_boxes(screenshot)
targets = get_targets(boxes_frame, "asteroid belt")
targets = get_targets(boxes_frame, "belt")
click_mouse(targets.iloc[0].cent_x, targets.iloc[0].cent_y, True)
@@ -228,11 +233,12 @@ def start_mine():
screenshot = get_screenshot()
boxes_frame = get_boxes(screenshot)
target_lock_cor = get_cors_by_unique_name(boxes_frame, "lock target")
target_lock_cor = get_cors_by_unique_name(boxes_frame, "lock")
if target_lock_cor:
click_mouse(target_lock_cor[0], target_lock_cor[1])
time.sleep(random.uniform(4.4, 5.8))
pg.press("f1")
time.sleep(random.uniform(0.1, 1))
pg.press("f2")
return
else:
@@ -244,12 +250,7 @@ def start_mine():
while True:
screenshot = get_screenshot()
boxes_frame = get_boxes(screenshot)
targets = get_targets(boxes_frame, "\\(veldspar\\)")
# move_mouse(targets.iloc[0].cent_x, targets.iloc[0].cent_y)
# pg.click()
# pg.click(button="right")
# move_mouse(30, 30)
targets = get_targets(boxes_frame, "(veldspar)")
input("Следущий скриншот - enter")
"""
@@ -265,4 +266,4 @@ def main(current_state="EMPTY"):
current_state = "MINING"
main("UNDOCKED")
main("ON_MINEFILD")

View File

@@ -1,13 +1,5 @@
certifi==2022.12.7
charset-normalizer==3.1.0
easyocr==1.6.2
et-xmlfile==1.1.0
idna==3.4
imageio==2.26.0
lazy_loader==0.1
MouseInfo==0.1.3
networkx==3.0
ninja==1.11.1
numpy==1.24.2
opencv-python==4.7.0.72
openpyxl==3.1.1
@@ -16,27 +8,15 @@ pandas==1.5.3
Pillow==9.4.0
PyAutoGUI==0.9.53
pyclick==0.0.2
pyclipper==1.3.0.post4
PyGetWindow==0.0.9
PyMsgBox==1.0.9
pyperclip==1.8.2
PyRect==0.2.0
PyScreeze==0.1.28
python-bidi==0.4.2
pytesseract==0.3.10
python-dateutil==2.8.2
python3-xlib==0.15
pytweening==1.0.4
pytz==2022.7.1
PyWavelets==1.4.1
PyYAML==6.0
requests==2.28.2
scikit-image==0.20.0
scipy==1.10.1
shapely==2.0.1
six==1.16.0
tifffile==2023.2.28
torch==1.13.1+cu116
torchvision==0.14.1+cu116
typing_extensions==4.5.0
urllib3==1.26.14
xlib==0.21