Skip to content

Commit

Permalink
Merge branch 'main' of github.com:MaaAssistantArknights/MAABH3
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Sep 26, 2023
2 parents b96a266 + 3291f00 commit c4f137d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
2. 等待扫描设备(设备越多等待时间越长)
3. 选择客户端
4. 输入需要执行的任务序号

- 以空格分隔,例如 `1 2 3 4 5``2 3 1 4 5`,序号的顺序代表着执行顺序
- 序号可重复,例如 `5 1 2 3 4 5`

Expand Down Expand Up @@ -73,6 +72,9 @@
- 目前启动游戏仅支持官服、Bilibili服和Vivo服
- 其他渠道服虽不支持启动,但可手动启动游戏后正常使用
- 若需要适配启动其他渠道服,欢迎提 `issues` 或 `pr`
- 家园远征可能会清空当前体力和家园体力罐内体力,总量受远征派遣体力限制
- 如果任务列表中同时包含 MaterialEvent 和 Homelad,先完成 MaterialEvent是一个更好的选择。这样做有助于确保有足够的体力来完成所有任务
- 使用材料减负需要先三星通关一次对应关卡,有多个关卡的模块(如曜日材料)则会自动进行已完成挑战的最高一级关卡
## How to build
Expand Down
60 changes: 35 additions & 25 deletions tools/CropRoi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import os
from typing import List, Tuple

print("Usage:\n"
"Put the 16:9 images under ./src, and run this script, it will be auto converted to 720p.\n"
"Drag mouse to select ROI, press 'S' to save, press 'Q' to quit.\n"
"The cropped images will be saved in ./dst\n")
print(
"Usage:\n"
"Put the 16:9 images under ./src, and run this script, it will be auto converted to 720p.\n"
"Drag mouse to select ROI, press 'S' to save, press 'Q' to quit.\n"
"The cropped images will be saved in ./dst\n"
)

# 初始化参考点列表和布尔值标志:是否正在执行裁剪
refPt: List[Tuple[int, int]] = []
Expand All @@ -26,6 +28,13 @@ def click_and_crop(event: int, x: int, y: int, *args) -> None:
if event == cv2.EVENT_LBUTTONDOWN:
refPt = [(x, y)]
cropping = True
# 检测鼠标是否移动
elif event == cv2.EVENT_MOUSEMOVE:
if cropping:
# 创建图像副本以绘制动态矩形
draw = image.copy()
cv2.rectangle(draw, refPt[0], (x, y), (0, 255, 0), 2)
cv2.imshow("image", draw)
# 检测鼠标左键是否释放
elif event == cv2.EVENT_LBUTTONUP:
# 记录结束(x,y)坐标,并显示裁剪结束
Expand Down Expand Up @@ -73,36 +82,37 @@ def click_and_crop(event: int, x: int, y: int, *args) -> None:

# 如果参考点列表里有俩个点,则裁剪区域并展示
if len(refPt) == 2:
if refPt[0][0] > refPt[1][0] or refPt[0][1] > refPt[1][1]:
refPt[0], refPt[1] = refPt[1], refPt[0]
left = refPt[0][0]
right = refPt[1][0]
top = refPt[0][1]
bottom = refPt[1][1]
pt1, pt2 = sorted(refPt)

left, top = pt1
right, bottom = pt2

roi = image[top:bottom, left:right]

horizontal_expansion = 100
vertical_expansion = 100

filename_x: int = int(left - horizontal_expansion / 2)
filename_x = max(filename_x, 0)
filename_y: int = int(top - vertical_expansion / 2)
filename_y = max(filename_y, 0)
filename_w: int = (right - left) + horizontal_expansion
if filename_x + filename_w > dsize_width:
filename_w = dsize_width - filename_x
filename_h: int = (bottom - top) + vertical_expansion
if filename_y + filename_h > dsize_height:
filename_h = dsize_height - filename_y
# 计算扩展后的左上角坐标,并确保不超出图像边界
filename_x = max(0, left - horizontal_expansion // 2)
filename_y = max(0, top - vertical_expansion // 2)

# 计算扩展后的宽度和高度,并进行边界检查
filename_w = min(
dsize_width - filename_x, (right - left) + horizontal_expansion
)
filename_h = min(dsize_height - filename_y, (bottom - top) + vertical_expansion)

dst_filename: str = f'{filename}_{filename_x},{filename_y},{filename_w},{filename_h}.png'
print('dst:', dst_filename)
dst_filename: str = (
f"{filename}_{filename_x},{filename_y},{filename_w},{filename_h}.png"
)
print("dst:", dst_filename)

print(f"original roi: {left}, {top}, {right - left}, {bottom - top}, \n"
f"amplified roi: {filename_x}, {filename_y}, {filename_w}, {filename_h}\n\n")
print(
f"original roi: {left}, {top}, {right - left}, {bottom - top}, \n"
f"amplified roi: {filename_x}, {filename_y}, {filename_w}, {filename_h}\n\n"
)

cv2.imwrite(f'./dst/{dst_filename}', roi)
cv2.imwrite(f"./dst/{dst_filename}", roi)

refPt: List[Tuple[int, int]] = []
cropping = False
Expand Down

0 comments on commit c4f137d

Please sign in to comment.