-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eee0467
commit 3529872
Showing
19 changed files
with
76 additions
and
44 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from .nurturing import nurturing | ||
from .team_race import team_race | ||
from .daily_race import daily_race | ||
from .create_pos_mask import create_pos_mask |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding=UTF-8 -*- | ||
# pyright: strict | ||
|
||
if True: | ||
import sys | ||
import os | ||
sys.path.insert(0, os.path.join(__file__, "../.."), ) | ||
|
||
|
||
from typing import Text | ||
import cv2 | ||
from auto_derby import window, template, templates | ||
import pathlib | ||
import PIL.Image | ||
import numpy as np | ||
import argparse | ||
|
||
_TEMPLATES_PATH = pathlib.Path(templates.__file__).parent | ||
|
||
|
||
def _all_templates(): | ||
for i in _TEMPLATES_PATH.glob("*.png"): | ||
if i.is_dir(): | ||
continue | ||
if str(i).endswith(".pos.png"): | ||
continue | ||
yield i | ||
|
||
|
||
def _latest_file(): | ||
return str((sorted(_all_templates(), key=lambda x: x.stat().st_mtime, reverse=True))[0].name) | ||
|
||
|
||
def create_pos_mask(name: Text): | ||
|
||
game_img = template.screenshot(window.get_game()) | ||
match_img = template.load(name) | ||
match = template.match(game_img, name) | ||
last_match = template.DEBUG_DATA["last_match"] | ||
if last_match is None: | ||
raise ValueError("missing debug data") | ||
|
||
out_img = np.zeros((game_img.height, game_img.width), dtype=float) | ||
|
||
if match: | ||
_, pos = match | ||
x, y = pos | ||
cv2.rectangle(out_img, pos, (x+match_img.width, | ||
y+match_img.height), (255,), -1) | ||
|
||
img = PIL.Image.fromarray(out_img).convert("1") | ||
dest = str(_TEMPLATES_PATH / template.add_middle_ext(name, "pos")) | ||
img.save(dest) | ||
cv2.imshow("out", out_img) | ||
cv2.waitKey() | ||
|
||
|
||
def main(): | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument("--name", "-n", dest="name") | ||
args = parser.parse_args() | ||
name = args.name | ||
if not name: | ||
name = _latest_file() | ||
create_pos_mask(name) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |