Skip to content

Commit

Permalink
删除paddleocr识别资源的功能
Browse files Browse the repository at this point in the history
paddleocr与easyocr内存冲突
  • Loading branch information
veadex committed Mar 2, 2024
1 parent 32f42ce commit 2f2e607
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 105 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

## 近期更新

- 添加日常出击任务中500船停止出击的功能 *2024/02/19*
- 删除日常出击任务中500船停止出击的功能 *2024/03/02*
- 支持当前活动 "特混突袭-利斧行动", 详细信息见[文档](/documentation/特混突袭.md) *2024/02/06*
- 支持当前活动 "声威行动", 详细信息见文档 *2023/12/15*
- 设置文件新增一个选型`auto_exercise`,设置为`True`将会在执行`auto_daily.py`时自动打完每天的三次战役 *2023/10/17*
- 支持当前活动 "特混突袭", 详细信息见文档 *2023/9/27*
- 现已支持开启远程导弹支援,如要开启,建议在具体的plan里面针对某个点位设置`long_missile_support`为True. - *2023/9/22*
- 设置文件格式有小幅度调整, 增加新配置`auto_set_support`,默认为False,开启后每日会尝试开启战役支援. - *2023/9/11*
- 设置文件格式有小幅度调整, `dock_full_destroy` 参数位置发生了改变, 请对比自己的文件和默认文件. - *2023/6/9*
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2.16"
__version__ = "0.2.2.17"
2 changes: 1 addition & 1 deletion autowsgr/data/default_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ daily_automation:
auto_gain_bonus: True # 当有任务完成时自动点击
auto_bath_repair: True # 空闲时自动澡堂修理
auto_set_support: False # 自动开启战役支援
stop_maxship: True # 捞满500船时自动停止
# stop_maxship: False # 捞满500船时自动停止
auto_battle: True # 自动打完每日战役次数
battle_type: "困难潜艇" # 打哪个。可选名称参考"plans/battle/"
auto_exercise: True #自动打完每日的三次演习
Expand Down
1 change: 1 addition & 0 deletions autowsgr/data/plans/exercise/plan_1.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 功能: 演习默认模块
exercise_times: 4
robot: True
fleet_id: 2
node_defaults: # 如果部分参数没有指定,将继承默认模块中的值
night: True
node_args:
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ map: 4 # 地图
selected_nodes: [A, D, C, K, I, F, L] # 选择要打的节点,白名单模式,一旦到达不要的节点就SL
repair_mode: 1
fleet_id: 2
fleet: ["", "U-1405", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "U-1405", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
formation: 2 # 正常情况阵型选择,1-5
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ map: 5 # 地图
selected_nodes: [C, F, I] # 选择要打的节点,白名单模式,一旦到达不要的节点就SL
repair_mode: 1
fleet_id: 2
fleet: ["", "U-1405", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "U-1405", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
formation: 2 # 正常情况阵型选择,1-5
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ map: 3 # 地图
selected_nodes: [B, E, H, J] # 选择要打的节点,白名单模式,一旦到达不要的节点就SL
repair_mode: 1
fleet_id: 2
fleet: ["", "U-1405", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "U-1405", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
formation: 2 # 正常情况阵型选择,1-5
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ map: 4 # 地图
selected_nodes: [B, E, D, G, L, K, M, H] # 选择要打的节点,白名单模式,一旦到达不要的节点就SL
repair_mode: 1
fleet_id: 2
fleet: ["", "U-1405", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "U-1405", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
formation: 2 # 正常情况阵型选择,1-5
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ selected_nodes: [C, E, H, L] # 选择要打的节点,白名单模式,一旦
repair_mode: 1
fleet_id: 2
fight_condition: 3
fleet: ["", "U-1405", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "U-1405", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
formation: 2 # 正常情况阵型选择,1-5
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/data/plans/week/9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ selected_nodes: [A, D, G, H, M, O] # 选择要打的节点,白名单模式,
repair_mode: 1
fleet_id: 2
fight_condition: 3
fleet: ["", "飞龙", "U-1206", "狼群47", "射水鱼", "U-96", "肥鱼"]
fleet: ["", "飞龙", "U-1206", "U-47", "射水鱼", "U-96", "肥鱼"]

node_defaults:
detour: True # 是否迂回
Expand Down
17 changes: 0 additions & 17 deletions autowsgr/game/game_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from autowsgr.ocr.ship_name import recognize_single_number
from autowsgr.utils.api_image import crop_image


from .get_game_info import check_support_stats, detect_ship_stats

from autowsgr.ocr.paddle__ocr import paddle_ocr

class Expedition:
def __init__(self, timer: Timer) -> None:
Expand Down Expand Up @@ -52,25 +50,10 @@ def run(self, force=False):
def get_ship(timer: Timer, max_times=1):
"""获取掉落舰船"""
timer.got_ship_num += 1
#got_ship_ocr(timer) 识别掉落数据,后续补充相关内容
timer.wait_image(IMG.symbol_image[8])
while timer.wait_image(IMG.symbol_image[8], timeout=0.5):
timer.Android.click(915, 515, delay=0.25, times=1)

def got_ship_ocr(timer: Timer ):
"""
识别获得舰船的名字,返回识别结果,
"""
image = timer.screen
image_crop = crop_image(image,pos1=[0.015625, -0.1027], pos2 = [0.49, -0.49] ,resolution=timer.config.resolution)
result = paddle_ocr(image_crop, language = "ch")
timer.got_ship_name = result[0][1][0]
timer.ship_type = result[1][1][0]
# timer.ship_star = len(result[2][1][0]) 星级识别暂时有点问题
#输出日志
timer.logger.info(f"已获得舰船数量:{timer.got_ship_num}, 舰船名称:{timer.got_ship_name}, 舰种:{timer.ship_type}")
return result


def match_night(timer: Timer, is_night):
"""匹配夜战按钮并点击"""
Expand Down
5 changes: 2 additions & 3 deletions autowsgr/ocr/digit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np

from autowsgr.controller.run_timer import Timer
from autowsgr.ocr.paddle__ocr import paddle_ocr
from autowsgr.ocr.ship_name import recognize_number

# import pytesseract
Expand Down Expand Up @@ -50,7 +49,7 @@ def get_resources(timer: Timer):
ret = {}
for key in POS["main_page"]["resources"]:
image_crop = crop_image(image, *POS["main_page"]["resources"][key], resolution=timer.config.resolution)
raw_str = paddle_ocr(image_crop)
# raw_str = paddle_ocr(image_crop)
try:
raw_str = raw_str[0][1][0]
if raw_str[-1] == "K":
Expand Down Expand Up @@ -80,7 +79,7 @@ def get_loot_and_ship(timer: Timer):
ret = {}
for key in POS["map_page"]:
image_crop = crop_image(image, *POS["map_page"][key], resolution=timer.config.resolution)
raw_str = paddle_ocr(image_crop)
# raw_str = paddle_ocr(image_crop)
try:
raw_str = raw_str[0][1][0]
ret[key] = eval(raw_str.split("/")[0]) # 当前值
Expand Down
44 changes: 0 additions & 44 deletions autowsgr/ocr/paddle__ocr.py

This file was deleted.

25 changes: 13 additions & 12 deletions autowsgr/scripts/daily_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from autowsgr.constants import literals
from autowsgr.fight.battle import BattlePlan
from autowsgr.fight.exercise import NormalExercisePlan
from autowsgr.fight.normal_fight import NormalFightPlan
from autowsgr.game.game_operation import (
Expedition,
Expand All @@ -12,7 +13,6 @@
)
from autowsgr.ocr.digit import get_loot_and_ship, get_resources
from autowsgr.scripts.main import start_script
from autowsgr.fight.exercise import NormalExercisePlan


class DailyOperation:
Expand All @@ -21,15 +21,13 @@ def __init__(self, setting_path) -> None:

self.config = SN(**self.timer.config.daily_automation)
self.config.DEBUG = False
self.complete_time = None
self.complete_time = None

if self.config.auto_expedition:
self.expedition_plan = Expedition(self.timer)

if self.config.auto_battle:
self.battle_plan = BattlePlan(
self.timer, plan_path=f"battle/{self.config.battle_type}.yaml"
)
self.battle_plan = BattlePlan(self.timer, plan_path=f"battle/{self.config.battle_type}.yaml")
if self.config.auto_exercise:
self.exercise_plan = NormalExercisePlan(self.timer, "exercise/plan_1.yaml")

Expand All @@ -44,7 +42,7 @@ def __init__(self, setting_path) -> None:
fleet_id=plan[1],
)
)
self.fight_complete_times.append([0, plan[2]]) # 二元组, [已完成次数, 目标次数]
self.fight_complete_times.append([0, plan[2], plan[0]]) # 二元组, [已完成次数, 目标次数, 任务名称]

self.start_time = self.last_time = time.time()

Expand All @@ -59,16 +57,16 @@ def run(self):
if self.config.auto_set_support:
SetSupport(self.timer, True)

get_loot_and_ship(self.timer) # 获取胖次掉落和船只掉落数据
get_resources(self.timer)
# get_loot_and_ship(self.timer) # 获取胖次掉落和船只掉落数据
# get_resources(self.timer)

# 自动演习
if self.config.auto_exercise:
self.check_exercise()

# 自动出征
if self.config.auto_normal_fight:
while self._has_unfinished() and self._ship_max():
while self._has_unfinished():
task_id = self._get_unfinished()

plan = self.fight_plans[task_id]
Expand Down Expand Up @@ -101,6 +99,9 @@ def _has_unfinished(self):
def _get_unfinished(self):
for i, times in enumerate(self.fight_complete_times):
if times[0] < times[1]:
self.timer.logger.info(
f"正在执行的PLAN:{self.fight_complete_times[i][2]},已出击次数:{self.fight_complete_times[i][0]},目标次数:{self.fight_complete_times[i][1]}"
)
return i

def _expedition(self):
Expand All @@ -118,15 +119,15 @@ def _bath_repair(self):
def _ship_max(self):
if self.config.stop_maxship:
if self.timer.got_ship_num < 500:
self.timer.logger.info(f'已掉落船数量:{self.timer.got_ship_num}')
self.timer.logger.info(f"已掉落船数量:{self.timer.got_ship_num}")
return True
else:
return False
else:
return True

def check_exercise(self):
#判断在哪个时间段
# 判断在哪个时间段
now_time = time.localtime(time.time())
hour = now_time.tm_hour
if 0 <= hour < 12:
Expand Down
2 changes: 1 addition & 1 deletion examples/user_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ daily_automation:
auto_gain_bonus: True # 当有任务完成时自动点击
auto_bath_repair: True # 空闲时自动澡堂修理
auto_set_support: False # 自动开启战役支援
stop_maxship: True # 捞满500船时自动停止出击
# stop_maxship: False # 捞满500船时自动停止出击
auto_battle: True # 自动打完每日战役次数
battle_type: "困难潜艇" # 打哪个。可选名称参考"plans/battle/"

Expand Down
2 changes: 1 addition & 1 deletion examples/user_settings_debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ daily_automation:
auto_gain_bonus: True # 当有任务完成时自动点击
auto_bath_repair: True # 空闲时自动澡堂修理
auto_set_support: False # 自动开启战役支援
stop_maxship: True # 捞满500船时自动停止
# stop_maxship: False # 捞满500船时自动停止
auto_battle: True # 自动打完每日战役次数
battle_type: "困难潜艇" # 打哪个。可选名称参考"plans/battle/"

Expand Down
8 changes: 4 additions & 4 deletions other_data/ship_name_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ No.406: # 哈曼
- "哈曼"
No.407: # 吕特晏斯
- "吕特晏斯"
No.408: # 鲃鱼
No.408: # 肥鱼
- "肥鱼"
No.409: # 新泽西
- "新泽西"
Expand Down Expand Up @@ -1498,8 +1498,8 @@ No.1372: # 早春
- "早春"
No.1380: # 圣乔治
- "圣乔治"
No.1408: # 鲃鱼
- "鲃鱼"
No.1408: # 肥鱼
- "肥鱼"
No.1413: # 加里波第
- "加里波第"
No.1414: # 凯利
Expand Down Expand Up @@ -1546,4 +1546,4 @@ Other: # 战例
- 守护之盾
- 抱头蹲防
- 关键一击
- 久远的加护
- 久远的加护
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ opencv-python-headless = "4.5.4.60"
airtest = "^1.3.1"
easyocr = "^1.7.1"
keyboard = "^0.13.5"
paddleocr = "^2.0.1"
paddlepaddle = "^2.6.0"


[tool.poetry-version-plugin]
source = "init"
Expand Down
20 changes: 10 additions & 10 deletions tools/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import requests

#os.environ["https_proxy"] = "127.0.0.1:7890"
#os.environ["http_proxy"] = "127.0.0.1:7890"
# os.environ["https_proxy"] = "127.0.0.1:7890"
# os.environ["http_proxy"] = "127.0.0.1:7890"

UPDATE = True
URL = "https://www.zjsnrwiki.com/wiki/%E8%88%B0%E5%A8%98%E5%9B%BE%E9%89%B4#searchInput"
Expand All @@ -20,6 +20,7 @@
1058: "奥希金斯",
1185: "机灵",
1408: "肥鱼",
408: "肥鱼",
}


Expand All @@ -41,21 +42,21 @@ def extract(str):
res = ""
rks = re.findall(re_rk_wsrwiki, str)
names = re.findall(re_name_wsrwiki, str)
#print(rks)
#print(names)
# print(rks)
# print(names)
print(len(rks), len(names))

for rk, name in zip(rks, names):
rk = rk[30 : rk.find("</b>")].strip() # 添加.strip()以去除可能的空格和换行符
_title_idx = name.find("title") + 7
name = name[_title_idx:]
#获取改后名字
start_index = name.find('>') + 1
end_index = name.find('<', start_index)
# 获取改后名字
start_index = name.find(">") + 1
end_index = name.find("<", start_index)
substring = name[start_index:end_index]
#获取改前名字
# 获取改前名字
name = name[: name.index('"')]
if substring!=name:
if substring != name:
print(f"{name} : {substring}")
if int(rk) in REPLACE:
name = REPLACE[int(rk)]
Expand All @@ -66,7 +67,6 @@ def extract(str):
res += f"No.{rk}: # {name}\n"
res += f' - "{_name}"\n'


res += """Other: # 战例
- 肌肉记忆
- 长跑训练
Expand Down

0 comments on commit 2f2e607

Please sign in to comment.