Skip to content

Commit

Permalink
support 1440p (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 authored Nov 2, 2023
1 parent c4f3cfb commit 482482e
Show file tree
Hide file tree
Showing 43 changed files with 71 additions and 8 deletions.
Binary file not shown.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/templates_2560x1440/hud_detection_left.png
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 added assets/templates_2560x1440/stash_menu_icon.png
3 changes: 2 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def clean_up():

os.system(f"cd {release_dir} && mkdir config && cd ..")

shutil.copy("config/game_1920_1080.ini", f"{release_dir}/config/")
shutil.copy("config/game_1920x1080.ini", f"{release_dir}/config/")
shutil.copy("config/game_2560x1440.ini", f"{release_dir}/config/")
shutil.copy("config/params.ini", f"{release_dir}/config/")
shutil.copy("config/filter_affixes.yaml", f"{release_dir}/config/")
shutil.copy("config/filter_aspects.yaml", f"{release_dir}/config/")
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions config/game_2560x1440.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[colors]
; min and max hsv range (opencv format: h: [0-180], s: [0-255], v: [0, 255])
; h_min, s_min, v_min, h_max, s_max, v_max
gray_seperator=14,10,62,40,42,100

[ui_pos]
; all positions in [x, y]
window_dimensions=2560,1440

[ui_offsets]
; all offsets in [x, y]
item_descr_width=516
item_descr_pad=20
item_descr_off_bottom_edge=69
find_seperator_short_offset_top=400
find_bullet_points_width=52
item_descr_line_height=33

[ui_roi]
character_active=1741,17,205,40
rel_descr_search_left=-688,0,213,1173
rel_descr_search_right=-53,0,213,1173
3x11_slots=1691,963,809,324
5x10_slots=61,359,816,648
stash_menu_icon=395,96,145,64
tab_slots_5=244,189,448,68
4 changes: 2 additions & 2 deletions src/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def update_window_pos(self, offset_x: int, offset_y: int, width: int, height: in
):
return
Logger.info(f"Found Window. offsets: left {offset_x}px, top {offset_y}px, width {width}px, height {height}px")
self.res_key = f"{width}_{height}"
if self.res_key not in ["1920_1080"]:
self.res_key = f"{width}x{height}"
if self.res_key not in ["1920x1080", "2560x1440"]:
Logger.error(f"The resoltuion: {self.res_key} is not supported.")
os._exit(0)

Expand Down
2 changes: 1 addition & 1 deletion src/item/find_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def find_descr(img: np.ndarray, anchor: tuple[int, int]) -> tuple[bool, tuple[in
rarity = map_template_rarity[match.name.lower()]
# find equipe template
offset_top = int(window_height * 0.1)
roi_y = match.region[1] - offset_top
roi_y = match.region[1] + offset_top
search_height = window_height - roi_y - offset_top
roi = [match.region[0], roi_y, item_descr_width, search_height]
res_bottom = search(ref=["item_bottom_edge"], inp_img=img, roi=roi, threshold=0.73, mode="best")
Expand Down
2 changes: 1 addition & 1 deletion src/item/read_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
start_tex_1 = time.time()
refs = ["item_seperator_short_rare", "item_seperator_short_legendary"]
roi = [0, 0, img_item_descr.shape[1], Config().ui_offsets["find_seperator_short_offset_top"]]
if not (sep_short := search(refs, img_item_descr, 0.68, roi, True, "gray_seperator", "all")).success:
if not (sep_short := search(refs, img_item_descr, 0.68, roi, True, "gray_seperator", "all", do_multi_process=False)).success:
Logger.warning("Could not detect item_seperator_short.")
screenshot("failed_seperator_short", img=img_item_descr)
return None
Expand Down
17 changes: 14 additions & 3 deletions src/template_finder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import threading
import time
from functools import cache
from functools import lru_cache

import cv2
import numpy as np
Expand Down Expand Up @@ -102,7 +102,7 @@ def wait_for_update(img: np.ndarray, roi: list[int] = None, timeout: float = 3,
return change


@cache
@lru_cache(maxsize=None)
def stored_templates() -> dict[Template]:
paths = []
templates = {}
Expand Down Expand Up @@ -231,6 +231,8 @@ def search(
def _process_cv_result(template: Template, img: np.ndarray) -> bool:
new_match = False
res, template_img, new_roi = _get_cv_result(template, img, roi, color_match, use_grayscale)

# i = 0
while True and not (matches and mode == "first"):
_, max_val, _, max_pos = cv2.minMaxLoc(res)

Expand Down Expand Up @@ -258,7 +260,16 @@ def _process_cv_result(template: Template, img: np.ndarray) -> bool:
if mode == "first":
break
# Remove the matched region from the result
cv2.rectangle(res, max_pos, (max_pos[0] + template_img.shape[1], max_pos[1] + template_img.shape[0]), (0, 0, 0), -1)
cv2.rectangle(
res,
(max_pos[0] - template_img.shape[1] // 2, max_pos[1] - template_img.shape[0] // 2),
(max_pos[0] + template_img.shape[1], max_pos[1] + template_img.shape[0]),
(0, 0, 0),
-1,
)
# result_norm = cv2.normalize(res, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
# cv2.imwrite(f"res{i}.png", result_norm)
# i += 1
else:
break
return new_match
Expand Down
5 changes: 5 additions & 0 deletions test/item/find_descr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from item.find_descr import find_descr
from item.data.rarity import ItemRarity
from cam import Cam
from config import Config
from template_finder import stored_templates


BASE_PATH = "test/assets/item"
Expand All @@ -14,10 +16,13 @@
[
((1920, 1080), f"{BASE_PATH}/find_descr_rare_1920x1080.png", (1630, 763), True, (1196, 377), ItemRarity.Rare),
((1920, 1080), f"{BASE_PATH}/find_descr_legendary_1920x1080.png", (1515, 761), True, (1088, 78), ItemRarity.Legendary),
((2560, 1440), f"{BASE_PATH}/find_descr_legendary_2560x1440.png", (676, 546), True, (743, 105), ItemRarity.Legendary),
],
)
def test_find_descr(img_res, input_img, anchor, expected_success, expected_top_left, expected_rarity):
Cam().update_window_pos(0, 0, img_res[0], img_res[1])
Config().load_data()
stored_templates.cache_clear()
img = cv2.imread(input_img)
start = time.time()
success, top_left_corner, item_rarity, cropped_img = find_descr(img, anchor)
Expand Down
20 changes: 20 additions & 0 deletions test/item/read_descr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from item.data.aspect import Aspect
from item.models import Item
from cam import Cam
from config import Config
from template_finder import stored_templates

# def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
BASE_PATH = "test/assets/item"
Expand Down Expand Up @@ -48,10 +50,28 @@
],
),
),
(
(2560, 1440),
f"{BASE_PATH}/read_descr_legendary_2560x1440_1.png",
Item(
ItemRarity.Legendary,
ItemType.Wand,
864,
Aspect("conceited_aspect", 18),
[
Affix("core_skill_damage", 18),
Affix("ultimate_skill_damage", 18.5),
Affix("damage_to_stunned_enemies", 18),
Affix("damage_to_burning_enemies", 12.5),
],
),
),
],
)
def test_read_descr(img_res: tuple[int, int], input_img: str, expected_item: Item):
Cam().update_window_pos(0, 0, img_res[0], img_res[1])
Config().load_data()
stored_templates.cache_clear()
img = cv2.imread(input_img)
start = time.time()
item = read_descr(expected_item.rarity, img)
Expand Down

0 comments on commit 482482e

Please sign in to comment.