add:主线支持所有关卡导航

This commit is contained in:
EightyDollars 2024-09-30 02:05:57 +08:00
parent 28ed5b053c
commit 2f290a5a2e
4 changed files with 412 additions and 106 deletions

Binary file not shown.

View file

@ -1,8 +1,10 @@
import re
from turtle import left
import cv2
from arknights_mower.models import navigation
from arknights_mower.solvers.navigation.utils import generate_name
from arknights_mower.utils import config
from arknights_mower.utils.graph import SceneGraphSolver
from arknights_mower.utils.image import thres2
@ -15,121 +17,403 @@ from .last_stage import LastStageNavigation
location = {
1: {
"1-1": (0, 0),
"1-2": (428, -1),
"1-3": (700, 157),
"1-4": (1138, 158),
"1-5": (1600, 158),
"1-6": (2360, -1),
"1-7": (3073, -180),
"1-8": (3535, -181),
"1-9": (4288, -1),
"1-10": (4635, 167),
"1-11": (4965, -9),
"1-12": (5436, -10),
"1-1": [(0, 0), "light"],
"1-2": [(428, -1), "light"],
"1-3": [(700, 157), "light"],
"1-4": [(1138, 158), "light"],
"1-5": [(1600, 158), "dark"],
"1-6": [(2360, -1), "light"],
"1-7": [(3073, -180), "light"],
"1-8": [(3535, -181), "dark"],
"1-9": [(4288, -1), "light"],
"1-10": [(4635, 167), "light"],
"1-11": [(4965, -9), "light"],
"1-12": [(5436, -10), "dark"],
},
2: {
"2-1": [(0, 0), "light"],
"2-2": [(758, -135), "light"],
"2-3": [(2384, 0), "dark"],
"2-4": [(3008, -143), "light"],
"2-5": [(4799, 0), "dark"],
"2-6": [(5263, 0), "light"],
"2-7": [(5830, 0), "light"],
"2-8": [(7053, -175), "dark"],
"2-9": [(7507, -175), "light"],
"2-10": [(8974, 2), "dark"],
"S2-1": [(428, 0), "light"],
"S2-2": [(1190, -135), "light"],
"S2-3": [(1637, -135), "light"],
"S2-4": [(1921, 0), "light"],
"S2-5": [(3440, -144), "light"],
"S2-6": [(3740, 2), "light"],
"S2-7": [(4183, 2), "light"],
"S2-8": [(6277, 2), "light"],
"S2-9": [(6727, 0), "light"],
"S2-10": [(7856, -345), "light"],
"S2-11": [(8200, -175), "light"],
"S2-12": [(8521, 2), "light"],
},
3: {
"3-1": [(0, 0), "light"],
"3-2": [(450, -12), "light"],
"3-3": [(873, -18), "light"],
"S3-1": [(1747, 290), "light"],
"S3-2": [(2218, 290), "light"],
"3-4": [(2647, 114), "dark"],
"3-5": [(3097, 114), "light"],
"3-6": [(3547, 114), "light"],
"3-7": [(3871, -49), "light"],
"3-8": [(4456, -181), "dark"],
"S3-3": [(4306, 113), "light"],
"S3-4": [(4732, 113), "light"],
"S3-5": [(5163, 113), "light"],
"S3-6": [(5589, 113), "light"],
"S3-7": [(6016, 108), "light"],
},
4: {
"4-1": [(0, 0), "light"],
"4-2": [(309, 163), "light"],
"4-3": [(591, -1), "light"],
"S4-1": [(890, 163), "light"],
"S4-2": [(1199, 287), "light"],
"S4-3": [(1506, 163), "light"],
"4-4": [(1834, 1), "dark"],
"4-5": [(2167, -135), "light"],
"4-6": [(2502, -1), "light"],
"4-7": [(3931, 0), "dark"],
"S4-4": [(2774, 134), "light"],
"S4-5": [(3194, 134), "light"],
"S4-6": [(3617, 134), "light"],
"4-8": [(4258, -137), "light"],
"4-9": [(4566, -2), "light"],
"S4-7": [(4864, -281), "light"],
"S4-8": [(5194, -146), "light"],
"S4-9": [(5596, -146), "light"],
"4-10": [(6378, -2), "dark"],
"S4-10": [(5987, -146), "light"],
},
5: {
"5-1": [(0, 0), "light"],
"5-2": [(472, -128), "light"],
"5-3": [(1558, -128), "dark"],
"S5-1": [(720, 59), "light"],
"S5-2": [(1198, 59), "light"],
"5-4": [(2014, -22), "light"],
"5-5": [(2473, -127), "light"],
"5-6": [(2921, -230), "light"],
"S5-3": [(3262, -61), "light"],
"5-7": [(4046, -229), "dark"],
"5-8": [(4406, -71), "light"],
"5-9": [(4874, -71), "light"],
"S5-4": [(3703, -61), "light"],
"S5-5": [(5255, 91), "light"],
"S5-6": [(5681, 91), "light"],
"S5-7": [(6108, 91), "light"],
"S5-8": [(6528, 91), "light"],
"5-10": [(6833, -91), "dark"],
"S5-9": [(6952, 91), "light"],
"H5-1": [(7517, 60), "dark"],
"H5-2": [(7786, -271), "dark"],
"H5-3": [(8087, 49), "dark"],
},
6: {
"6-1": [(0, 0), "light"],
"6-2": [(413, 0), "light"],
"6-3": [(765, 123), "light"],
"6-4": [(1052, 243), "light"],
"6-5": [(1365, 120), "dark"],
"6-6": [(1768, 120), "light"],
"6-7": [(2110, 240), "dark"],
"6-8": [(2453, -69), "light"],
"6-9": [(3290, 241), "light"],
"6-10": [(3713, 241), "light"],
"6-11": [(4705, 223), "dark"],
"6-12": [(5032, 90), "light"],
"S6-1": [(3963, 103), "light"],
"S6-2": [(4387, 103), "light"],
"6-13": [(5336, -53), "light"],
"6-14": [(5687, 70), "light"],
"6-15": [(6130, 70), "light"],
"S6-3": [(6454, 226), "light"],
"6-16": [(7250, 70), "dark"],
"6-17": [(7976, 72), "dark"],
"S6-4": [(6880, 226), "light"],
"6-18": [(8423, 72), "light"],
"H6-1": [(8909, -81), "dark"],
"H6-2": [(9041, 199), "dark"],
"H6-3": [(9473, -81), "dark"],
"H6-4": [(9596, 199), "dark"],
},
7: {
"7-1": [(0, 0), "light"],
"7-2": [(415, -1), "light"],
"7-3": [(718, -172), "light"],
"7-4": [(913, 165), "light"],
"7-5": [(1353, 165), "light"],
"7-6": [(1854, 39), "light"],
"7-7": [(2200, 204), "light"],
"7-8": [(2550, 39), "light"],
"7-9": [(2865, -136), "dark"],
"7-10": [(3309, -136), "light"],
"7-11": [(3649, 28), "light"],
"7-12": [(3976, 185), "dark"],
"7-13": [(4263, 14), "light"],
"7-14": [(4556, 192), "light"],
"7-15": [(4875, 21), "light"],
"7-16": [(5211, -150), "dark"],
"S7-1": [(5486, 185), "light"],
"S7-2": [(5926, 185), "light"],
"7-17": [(6138, -9), "light"],
"7-18": [(6998, -6), "dark"],
"7-19": [(7805, -10), "light"],
"H7-1": [(8098, -245), "dark"],
"H7-2": [(8327, 219), "dark"],
"H7-3": [(8605, -246), "dark"],
"H7-4": [(8822, 220), "dark"],
"7-20": [(9722, -6), "light"],
},
8: {
"R8-1": (0, 0),
"R8-2": (471, 0),
"R8-3": (864, 0),
"R8-4": (1259, 0),
"R8-5": (1651, -4),
"R8-6": (2045, -4),
"R8-7": (2228, -124),
"R8-8": (2437, -4),
"R8-9": (2951, -4),
"R8-10": (3284, -4),
"R8-11": (3617, -4),
"M8-1": (6, 339),
"M8-2": (865, 339),
"M8-3": (1259, 339),
"M8-4": (1651, 339),
"M8-5": (2045, 339),
"M8-6": (2439, 340),
"M8-7": (2952, 340),
"M8-8": (3617, 339),
"JT8-1": (4092, 171),
"JT8-2": (4545, 171),
"JT8-3": (5022, 171),
"H8-1": (5556, -24),
"H8-2": (5759, 354),
"H8-3": (5999, -24),
"H8-4": (6192, 354),
"R8-1": [(0, 0), "light"],
"R8-2": [(471, 0), "light"],
"R8-3": [(864, 0), "light"],
"R8-4": [(1259, 0), "light"],
"R8-5": [(1651, -4), "light"],
"R8-6": [(2045, -4), "light"],
"R8-7": [(2228, -124), "light"],
"R8-8": [(2437, -4), "dark"],
"R8-9": [(2951, -4), "light"],
"R8-10": [(3284, -4), "light"],
"R8-11": [(3617, -4), "dark"],
"M8-1": [(6, 339), "light"],
"M8-2": [(865, 339), "light"],
"M8-3": [(1259, 339), "light"],
"M8-4": [(1651, 339), "light"],
"M8-5": [(2045, 339), "light"],
"M8-6": [(2439, 340), "light"],
"M8-7": [(2952, 340), "light"],
"M8-8": [(3617, 339), "dark"],
"JT8-1": [(4092, 171), "light"],
"JT8-2": [(4545, 171), "dark"],
"JT8-3": [(5022, 171), "dark"],
"H8-1": [(5556, -24), "dark"],
"H8-2": [(5759, 354), "dark"],
"H8-3": [(5999, -24), "dark"],
"H8-4": [(6192, 354), "dark"],
},
9: {
"9-1": [(0, 0), "light"],
"9-2": [(358, 162), "light"],
"9-3": [(687, 21), "light"],
"9-4": [(1048, -120), "light"],
"9-5": [(1528, -120), "light"],
"9-6": [(1859, 105), "dark"],
"9-7": [(2954, 57), "light"],
"9-8": [(3394, -18), "light"],
"9-9": [(3799, -168), "light"],
"9-10": [(4155, 21), "dark"],
"9-11": [(4530, 141), "light"],
"9-12": [(4890, -78), "light"],
"9-13": [(5303, 42), "light"],
"9-14": [(6140, 177), "dark"],
"S9-1": [(5747, 42), "light"],
"S9-2": [(6065, -138), "light"],
"9-15": [(6487, -31), "light"],
"9-16": [(6914, 102), "light"],
"9-17": [(7336, -18), "light"],
"9-18": [(7764, -138), "dark"],
"9-19": [(8282, 42), "dark"],
"9-20": [(8904, 42), "light"],
"H9-1": [(8460, -243), "dark"],
"H9-2": [(9000, -243), "dark"],
"H9-3": [(9536, -243), "dark"],
"H9-4": [(8777, 327), "dark"],
"H9-5": [(9294, 327), "dark"],
"H9-6": [(9813, 327), "dark"],
"9-21": [(11144, 42), "light"],
},
10: {
"10-1": [(0, 0), "light"],
"10-2": [(164, 171), "light"],
"10-3": [(364, 0), "light"],
"10-4": [(861, 0), "light"],
"10-5": [(1255, 0), "light"],
"10-6": [(1647, 0), "light"],
"10-7": [(1809, -161), "dark"],
"10-8": [(2007, 0), "light"],
"10-9": [(2178, 171), "light"],
"10-10": [(2399, -4), "light"],
"10-11": [(2539, -138), "dark"],
"10-12": [(2851, 171), "light"],
"10-13": [(3031, -73), "light"],
"10-14": [(3393, -73), "light"],
"10-15": [(3393, 89), "dark"],
"10-16": [(3531, 266), "light"],
"10-17": [(3931, 264), "dark"],
"10-18": [(3931, 89), "light"],
"10-19": [(5013, 96), "light"],
"H10-1": [(3520, -273), "dark"],
"H10-2": [(4152, -273), "dark"],
"H10-3": [(4392, -73), "dark"],
},
11: {
"11-1": [(0, 0), "light"],
"11-2": [(277, 206), "light"],
"11-3": [(584, -1), "dark"],
"11-4": [(942, 0), "light"],
"11-5": [(1086, 207), "light"],
"11-6": [(1544, -1), "light"],
"11-7": [(2110, 136), "light"],
"11-8": [(2378, -1), "dark"],
"11-9": [(2625, 212), "light"],
"11-10": [(2805, -156), "light"],
"11-11": [(3029, 0), "light"],
"11-12": [(3422, -1), "dark"],
"11-13": [(3611, 212), "light"],
"11-14": [(3860, -155), "light"],
"11-15": [(4034, 0), "dark"],
"11-16": [(4385, 166), "light"],
"11-17": [(4385, -155), "dark"],
"11-18": [(4837, -156), "light"],
"11-19": [(4837, -1), "dark"],
"11-20": [(4837, 166), "dark"],
"H11-1": [(5422, -163), "dark"],
"H11-2": [(5915, -164), "dark"],
"H11-3": [(5566, 163), "dark"],
"H11-4": [(6066, 164), "dark"],
"11-21": [(6407, -1), "light"],
},
12: {
"12-1": (0, 0),
"12-2": (342, 292),
"12-3": (701, 292),
"12-4": (894, 121),
"12-5": (1122, 292),
"12-6": (1364, 121),
"12-7": (1515, 292),
"12-8": (2109, 290),
"12-9": (2468, 290),
"12-10": (2670, 125),
"12-11": (2980, 422),
"12-12": (3218, 125),
"12-13": (3456, 294),
"12-14": (3694, 123),
"12-15": (4020, 123),
"12-16": (4348, -14),
"12-17": (4673, -14),
"12-18": (4673, 210),
"12-19": (5175, 210),
"12-20": (5700, 210),
"12-21": (6377, 210),
"12-1": [(0, 0), "light"],
"12-2": [(342, 292), "light"],
"12-3": [(701, 292), "light"],
"12-4": [(894, 121), "light"],
"12-5": [(1122, 292), "light"],
"12-6": [(1364, 121), "light"],
"12-7": [(1515, 292), "dark"],
"12-8": [(2109, 290), "light"],
"12-9": [(2468, 290), "light"],
"12-10": [(2670, 125), "light"],
"12-11": [(2980, 422), "light"],
"12-12": [(3218, 125), "light"],
"12-13": [(3456, 294), "dark"],
"12-14": [(3694, 123), "light"],
"12-15": [(4020, 123), "light"],
"12-16": [(4348, -14), "light"],
"12-17": [(4673, -14), "light"],
"12-18": [(4673, 210), "light"],
"12-19": [(5175, 210), "dark"],
"12-20": [(5700, 210), "dark"],
"12-21": [(6377, 210), "light"],
},
13: {
"13-1": [(0, 0), "light"],
"13-2": [(411, -107), "light"],
"13-3": [(615, 77), "light"],
"13-4": [(939, -177), "light"],
"13-5": [(1223, -30), "dark"],
"13-6": [(1606, -137), "light"],
"13-7": [(2647, -268), "light"],
"13-8": [(2796, 37), "light"],
"13-9": [(3182, -91), "light"],
"13-10": [(3564, -31), "light"],
"13-11": [(3843, -151), "dark"],
"13-12": [(3981, 54), "light"],
"13-13": [(4282, -220), "light"],
"13-14": [(4680, -139), "light"],
"13-15": [(5062, -275), "dark"],
"13-16": [(5216, -40), "light"],
"13-17": [(5474, -210), "light"],
"13-18": [(5694, 46), "dark"],
"13-19": [(6150, 46), "light"],
"13-20": [(6579, 46), "light"],
"13-21": [(6797, -149), "dark"],
"13-22": [(7763, -149), "light"],
"H13-1": [(7235, -391), "dark"],
"H13-2": [(7878, -391), "dark"],
"H13-3": [(7262, 67), "dark"],
"H13-4": [(7870, 67), "dark"],
},
14: {
"14-1": [(0, 0), "light"],
"14-2": [(408, -1), "light"],
"14-3": [(942, -25), "light"],
"14-4": [(1186, 114), "light"],
"14-5": [(1481, 36), "light"],
"14-6": [(1951, 22), "light"],
"14-7": [(2267, -116), "light"],
"14-8": [(2409, 194), "light"],
"14-9": [(2813, 194), "dark"],
"14-10": [(3090, 285), "dark"],
"14-11": [(3365, 19), "light"],
"14-12": [(3567, 188), "light"],
"14-13": [(3848, 384), "light"],
"14-14": [(4113, 228), "light"],
"14-15": [(4497, 291), "light"],
"14-16": [(4791, 120), "light"],
"14-17": [(4976, -12), "dark"],
"14-18": [(5231, 266), "dark"],
"14-19": [(5870, 270), "light"],
"14-20": [(6035, 113), "dark"],
"14-21": [(6035, -124), "dark"],
"14-22": [(6447, 3), "dark"],
"H14-1": [(7267, -210), "dark"],
"H14-2": [(7891, -211), "dark"],
"H14-3": [(7272, 261), "dark"],
"H14-4": [(7890, 262), "dark"],
"14-23": [(8368, -1), "light"],
},
"OF": {
"OF-1": (0, 0),
"OF-2": (738, 144),
"OF-3": (1122, 299),
"OF-4": (1475, 135),
"OF-5": (2288, -45),
"OF-6": (2737, -45),
"OF-7": (3550, 135),
"OF-8": (3899, 299),
"OF-1": [(0, 0), "light"],
"OF-2": [(738, 144), "light"],
"OF-3": [(1122, 299), "light"],
"OF-4": [(1475, 135), "light"],
"OF-5": [(2288, -45), "light"],
"OF-6": [(2737, -45), "light"],
"OF-7": [(3550, 135), "light"],
"OF-8": [(3899, 299), "light"],
},
"AP": {
"AP-1": (0, 0),
"AP-2": (416, -74),
"AP-3": (716, -247),
"AP-4": (964, -417),
"AP-5": (1116, -589),
"AP-1": [(0, 0), "light"],
"AP-2": [(416, -74), "light"],
"AP-3": [(716, -247), "light"],
"AP-4": [(964, -417), "light"],
"AP-5": [(1116, -589), "light"],
},
"LS": {
"LS-1": (0, 0),
"LS-2": (385, -34),
"LS-3": (710, -130),
"LS-4": (970, -257),
"LS-5": (1138, -421),
"LS-6": (1213, -600),
"LS-1": [(0, 0), "light"],
"LS-2": [(385, -34), "light"],
"LS-3": [(710, -130), "light"],
"LS-4": [(970, -257), "light"],
"LS-5": [(1138, -421), "light"],
"LS-6": [(1213, -600), "light"],
},
"CA": {
"CA-1": (0, 0),
"CA-2": (416, -73),
"CA-3": (716, -246),
"CA-4": (964, -417),
"CA-5": (1116, -589),
"CA-1": [(0, 0), "light"],
"CA-2": [(416, -73), "light"],
"CA-3": [(716, -246), "light"],
"CA-4": [(964, -417), "light"],
"CA-5": [(1116, -589), "light"],
},
"CE": {
"CE-1": (0, 0),
"CE-2": (382, -33),
"CE-3": (709, -128),
"CE-4": (970, -259),
"CE-5": (1136, -420),
"CE-6": (1210, -597),
"CE-1": [(0, 0), "light"],
"CE-2": [(382, -33), "light"],
"CE-3": [(709, -128), "light"],
"CE-4": [(970, -259), "light"],
"CE-5": [(1136, -420), "light"],
"CE-6": [(1210, -597), "light"],
},
"SK": {
"SK-1": (0, 0),
"SK-2": (416, -73),
"SK-3": (716, -246),
"SK-4": (965, -417),
"SK-5": (1116, -589),
"SK-1": [(0, 0), "light"],
"SK-2": [(416, -73), "light"],
"SK-3": [(716, -246), "light"],
"SK-4": [(965, -417), "light"],
"SK-5": [(1116, -589), "light"],
},
"PR-A": {"PR-A-1": (0, 0), "PR-A-2": (604, -283)},
"PR-B": {"PR-B-1": (0, 0), "PR-B-2": (684, -296)},
"PR-C": {"PR-C-1": (0, 0), "PR-C-2": (667, -231)},
"PR-D": {"PR-D-1": (0, 0), "PR-D-2": (639, -260)},
"PR-A": {"PR-A-1": [(0, 0), "light"], "PR-A-2": [(604, -283), "light"]},
"PR-B": {"PR-B-1": [(0, 0), "light"], "PR-B-2": [(684, -296), "light"]},
"PR-C": {"PR-C-1": [(0, 0), "light"], "PR-C-2": [(667, -231), "light"]},
"PR-D": {"PR-D-1": [(0, 0), "light"], "PR-D-2": [(639, -260), "light"]},
}
collection_prefixs = [
@ -166,7 +450,7 @@ class NavigationSolver(SceneGraphSolver):
self.pr_prefix = pr_prefix
self.now_difficulty = None
self.change_to = None
self.patten = r"^(R|JT|H|M)(\d{1,2})$"
self.patten = r"^(R|JT|H|M|S)(\d{1,2})$"
if name == "Annihilation":
logger.info("剿灭导航")
elif prefix.isdigit() or re.match(self.patten, prefix):
@ -302,16 +586,34 @@ class NavigationSolver(SceneGraphSolver):
)
return
for i in location[prefix]:
left_blank = 0
right_blank = 0
if len(i.split("-")[0]) < 2:
left_blank = 20
if len(i.split("-")[-1]) < 2:
right_blank = 20
result = cv2.matchTemplate(
config.recog.gray, navigation[i], cv2.TM_SQDIFF_NORMED
config.recog.gray,
generate_name(
i,
left_blank=left_blank,
right_blank=right_blank,
style=location[prefix][i][1],
),
cv2.TM_SQDIFF_NORMED,
)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
logger.info(f"{i} {min_val} ")
if min_val < val:
val = min_val
loc = min_loc
name = i
target = va(vs(loc, location[prefix][name]), location[prefix][self.name])
logger.info(f"{name} {val} ")
target = va(
vs(loc, location[prefix][name][0]), location[prefix][self.name][0]
)
if target[0] + 200 > 1920:
self.swipe_noinertia((1400, 540), (-800, 0))
elif target[0] < 0:

View file

@ -12,6 +12,8 @@ from arknights_mower.utils.image import cropimg
def generate_name(
name: str,
font_size: int = 40,
left_blank: int = 0,
right_blank: int = 0,
style: Literal["light", "dark"] = "light",
draw: bool = False,
) -> tp.GrayImage:
@ -26,7 +28,7 @@ def generate_name(
font = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", font_size
)
img = Image.new(mode="L", size=(250, 100))
img = Image.new(mode="L", size=(200, 70))
ImageDraw.Draw(img).text((20, 0), name, fill=(255,), font=font)
img = np.array(img, dtype=np.uint8)
contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
@ -35,7 +37,8 @@ def generate_name(
right = max(x + w for x, y, w, h in rect)
top = min(y for x, y, w, h in rect)
bottom = max(y + h for x, y, w, h in rect)
img = cropimg(img, ((left, top), (right, bottom)))
img = cropimg(img, ((left - left_blank, top), (right + right_blank, bottom)))
if style == "light":
img = cv2.bitwise_not(img)

View file

@ -135,7 +135,7 @@ template_matching = {
"navigation/collection/PR-B_entry": ((0, 170), (1920, 870)),
"navigation/collection/PR-C_entry": ((0, 170), (1920, 870)),
"navigation/collection/PR-D_entry": ((0, 170), (1920, 870)),
"navigation/episode": (1560, 944),
"navigation/episode": (1567, 949),
"navigation/ope_difficulty": [(0, 920), (120, 1080)],
"navigation/ope_normal": (172, 950),
"navigation/ope_normal_small": (494, 930),
@ -209,6 +209,7 @@ template_matching = {
template_matching_score = {
"connecting": 0.7,
"navigation/episode": 0.7,
"navigation/ope_hard": 0.7,
"navigation/ope_hard_small": 0.7,
"navigation/ope_normal": 0.7,