diff --git a/eve_rock_watcher.py b/eve_rock_watcher.py index 5e0b2a6..d001a20 100644 --- a/eve_rock_watcher.py +++ b/eve_rock_watcher.py @@ -97,14 +97,20 @@ def detect_selected_region(cp): tcmd = cp.get("ocr", "tesseract_cmd", fallback="").strip() if tcmd: pytesseract.pytesseract.tesseract_cmd = tcmd - S = 2 # upscale so small panel text is found + # CROP to the center band (where EVE sits on a big multi-monitor desktop) THEN + # upscale — full-screen OCR is too coarse to read the small panel text. This is the + # exact approach that successfully located 'Quantity 43,975 Units' on Brock's screen. + S = 2 try: with mss.mss() as sct: mon = sct.monitors[0] raw = sct.grab(mon) img = Image.frombytes("RGB", raw.size, raw.bgra, "raw", "BGRX") - img = img.resize((img.width * S, img.height * S)) - data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT) + W, Hh = img.size + cx0, cy0 = int(W * 0.22), 0 + crop = img.crop((cx0, cy0, int(W * 0.82), int(Hh * 0.97))) + up = crop.resize((crop.width * S, crop.height * S)) + data = pytesseract.image_to_data(up, output_type=pytesseract.Output.DICT) except Exception as e: print(f"[rock] detect error: {e}") return None @@ -118,13 +124,13 @@ def detect_selected_region(cp): joined = " ".join(data["text"][i] for i in idxs) # the 'Quantity N Units' line: contains 'unit' + a digit (tolerant to OCR) if "unit" in joined.lower() and re.search(r"\d", joined): - xs = [data["left"][i] // S for i in idxs] # map 2x coords back to screen + xs = [data["left"][i] // S for i in idxs] # 2x -> crop space ys = [data["top"][i] // S for i in idxs] rs = [(data["left"][i] + data["width"][i]) // S for i in idxs] bs = [(data["top"][i] + data["height"][i]) // S for i in idxs] - padx = 170 # extend LEFT to capture the number - region = [mon["left"] + min(xs) - padx, mon["top"] + min(ys) - 8, - (max(rs) - min(xs)) + padx + 20, (max(bs) - min(ys)) + 16] + padx = 180 # extend LEFT to capture the number + region = [mon["left"] + cx0 + min(xs) - padx, mon["top"] + cy0 + min(ys) - 8, + (max(rs) - min(xs)) + padx + 30, (max(bs) - min(ys)) + 16] save_rock_region(cp, *region, mode="selected") print(f"[rock] auto-detected Selected-Item quantity -> {region}") return region