From a44131ad0727359f1d63860a29e36d897f660171 Mon Sep 17 00:00:00 2001 From: brockdarnold Date: Mon, 15 Jun 2026 02:20:36 +0000 Subject: [PATCH] publish eve_orehold_watcher.py --- eve_orehold_watcher.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/eve_orehold_watcher.py b/eve_orehold_watcher.py index b3ebbd6..879aa20 100644 --- a/eve_orehold_watcher.py +++ b/eve_orehold_watcher.py @@ -301,11 +301,14 @@ def grab_region(region): return Image.frombytes("RGB", raw.size, raw.bgra, "raw", "BGRX") -def _detect_readout(cp, img, mon_left=0, mon_top=0, save=True): +def _detect_readout(cp, img, mon_left=0, mon_top=0, save=True, scale=1): """Find the ore-hold 'cur / cap m3' readout inside a screenshot. Returns the - absolute-screen region [l,t,w,h] (and saves it) or None. Split out from the - screen-grab so it can be unit-tested against a rendered image.""" + absolute-screen region [l,t,w,h] (and saves it) or None. `scale` = how much `img` + was upscaled vs screen (coords are divided back). Split out so it's unit-testable.""" import pytesseract + tcmd = cp.get("ocr", "tesseract_cmd", fallback="").strip() if cp else "" + if tcmd: + pytesseract.pytesseract.tesseract_cmd = tcmd data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT) lines = {} for i in range(len(data["text"])): @@ -322,10 +325,10 @@ def _detect_readout(cp, img, mon_left=0, mon_top=0, save=True): cur, cap = parsed if not (500 <= cap <= 2_000_000): # plausible ore/gas hold capacity continue - xs = [data["left"][i] for i in idxs] - ys = [data["top"][i] for i in idxs] - rights = [data["left"][i] + data["width"][i] for i in idxs] - bots = [data["top"][i] + data["height"][i] for i in idxs] + xs = [data["left"][i] // scale for i in idxs] + ys = [data["top"][i] // scale for i in idxs] + rights = [(data["left"][i] + data["width"][i]) // scale for i in idxs] + bots = [(data["top"][i] + data["height"][i]) // scale for i in idxs] pad = 8 region = [mon_left + min(xs) - pad, mon_top + min(ys) - pad, (max(rights) - min(xs)) + 2 * pad, (max(bots) - min(ys)) + 2 * pad] @@ -351,10 +354,15 @@ def auto_region(cp): mon = sct.monitors[0] # full virtual desktop (all screens) raw = sct.grab(mon) img = Image.frombytes("RGB", raw.size, raw.bgra, "raw", "BGRX") + # crop the center band (where EVE sits) then upscale, so small m³ text is readable + 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 * 2, crop.height * 2)) except Exception as e: print(f"[ocr] auto-detect error: {e}") return None - return _detect_readout(cp, img, mon["left"], mon["top"]) + return _detect_readout(cp, up, mon["left"] + cx0, mon["top"] + cy0, scale=2) def run_ocr(cp):