改写战斗中替换group的逻辑

This commit is contained in:
Elaina 2024-10-13 01:24:58 +08:00
commit 7f89eb0db8
3890 changed files with 82290 additions and 0 deletions

41
mower/utils/detector.py Normal file
View file

@ -0,0 +1,41 @@
import numpy as np
from . import typealias as tp
from .log import logger
def infra_notification(img: tp.Image) -> tp.Coordinate:
"""
检测基建内是否存在蓝色通知
前置条件已经处于基建内
"""
height, width, _ = img.shape
# set a new scan line: right
right = width
while np.max(img[:, right - 1]) < 100:
right -= 1
right -= 1
# set a new scan line: up
up = 0
for i in range(height):
if img[i, right, 0] < 100 < img[i, right, 1] < img[i, right, 2]:
up = i
break
if up == 0:
return None
# set a new scan line: down
down = 0
for i in range(up, height):
if not (img[i, right, 0] < 100 < img[i, right, 1] < img[i, right, 2]):
down = i
break
if down == 0:
return None
# detect successful
point = (right - 10, (up + down) // 2)
logger.debug(f"detector.infra_notification: {point}")
return point