Skip to content

Commit

Permalink
adapt junk detection
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 committed Nov 24, 2023
1 parent fe380b6 commit a9aa9e9
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 18 deletions.
Binary file added assets/templates_1080p/item_descr/junk_inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/templates_1080p/item_descr/junk_mask.png
Binary file not shown.
Binary file added assets/templates_1080p/item_descr/junk_stash.png
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_1440p/item_descr/junk_inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/templates_1440p/item_descr/junk_mask.png
Binary file not shown.
Binary file added assets/templates_1440p/item_descr/junk_stash.png
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_2160p/item_descr/junk_inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/templates_2160p/item_descr/junk_mask.png
Binary file not shown.
Binary file added assets/templates_2160p/item_descr/junk_stash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/ui/chest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Chest(InventoryBase):
def __init__(self):
super().__init__(5, 10)
super().__init__(5, 10, is_stash=True)
self.menu_name = "Chest"
self.is_open_search_args = SearchArgs(
ref=["stash_menu_icon", "stash_menu_icon_medium"],
Expand Down
25 changes: 8 additions & 17 deletions src/ui/inventory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from utils.roi_operations import get_center, to_grid
from utils.custom_mouse import mouse
from utils.misc import wait
from template_finder import get_template
from template_finder import search


@dataclass
Expand All @@ -26,13 +26,15 @@ class InventoryBase(Menu):
Provides methods for identifying occupied and empty slots, item operations, etc.
"""

def __init__(self, rows: int = 3, columns: int = 11):
def __init__(self, rows: int = 3, columns: int = 11, is_stash: bool = False):
super().__init__()
self.rows = rows
self.columns = columns
self.slots_roi = Config().ui_roi[f"slots_{self.rows}x{self.columns}"]
mask_gray = cv2.cvtColor(get_template("JUNK_MASK"), cv2.COLOR_BGR2GRAY)
_, self.junk_mask = cv2.threshold(mask_gray, 127, 255, cv2.THRESH_BINARY)
if is_stash:
self.junk_template = "junk_stash"
else:
self.junk_template = "junk_inv"

def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlot], list[ItemSlot], list[ItemSlot], list[ItemSlot]]:
"""
Expand All @@ -57,28 +59,17 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo
item_slot = ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi))
slot_img = crop(img, slot_roi)

junk_mask = self.junk_mask.copy()
if self.junk_mask.shape[:2] != slot_img.shape[:2]:
junk_mask = cv2.resize(junk_mask, (slot_img.shape[1], slot_img.shape[0]))
junk_mask_inv = cv2.bitwise_not(junk_mask)

hsv_img = cv2.cvtColor(slot_img, cv2.COLOR_BGR2HSV)
mean_value_overall = np.mean(hsv_img[:, :, 2])
fav_flag_crop = crop(hsv_img, Config().ui_roi["rel_fav_flag"])
mean_value_fav = cv2.mean(fav_flag_crop)[2]

# check junk
hsv_junk = cv2.bitwise_and(hsv_img, hsv_img, mask=junk_mask)
mean_hsv = cv2.mean(hsv_junk, mask=junk_mask)
_, mean_saturation, mean_value = mean_hsv[:3]
hsv_junk_inv = cv2.bitwise_and(hsv_img, hsv_img, mask=junk_mask_inv)
mean_hsv_inv = cv2.mean(hsv_junk_inv, mask=junk_mask_inv)
_, _, mean_value_inv = mean_hsv_inv[:3]
res_junk = search(self.junk_template, slot_img, threshold=0.7)

if mean_value_fav > 205:
item_slot.is_fav = True
occupied_slots.append(item_slot)
elif mean_value > 110 and mean_saturation < 50 and (mean_value - mean_value_inv) > 90:
elif res_junk.success:
item_slot.is_junk = True
occupied_slots.append(item_slot)
elif mean_value_overall > 37:
Expand Down

0 comments on commit a9aa9e9

Please sign in to comment.