改写战斗中替换group的逻辑
This commit is contained in:
commit
7f89eb0db8
3890 changed files with 82290 additions and 0 deletions
41
mower/utils/detector.py
Normal file
41
mower/utils/detector.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue