From f434d3d94cb8d4d08a57cc1319a247b1ad4fb5ea Mon Sep 17 00:00:00 2001 From: brockdarnold Date: Mon, 15 Jun 2026 01:19:05 +0000 Subject: [PATCH] publish eve_rock_watcher.py --- eve_rock_watcher.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/eve_rock_watcher.py b/eve_rock_watcher.py index 51c391a..5e0b2a6 100644 --- a/eve_rock_watcher.py +++ b/eve_rock_watcher.py @@ -66,8 +66,9 @@ def parse_survey(text): return rows -# Selected-Item panel (no survey scanner needed): "Quantity 5,593 Units" -QTY_RE = re.compile(r"quantit\w*\s*([\d.,]{2,})\s*units?", re.I) +# Selected-Item panel (no survey scanner needed): "...Quantity 40,370 Units". +# Match the NUMBER before "Units" — don't require the word "Quantity" (OCR drops it). +QTY_RE = re.compile(r"([\d.,]{2,})\s*units?\b", re.I) def parse_selected(text): @@ -76,7 +77,7 @@ def parse_selected(text): if not m: return None digits = re.sub(r"\D", "", m.group(1)) # tolerate OCR , vs . in the number - return int(digits) if digits else None + return int(digits) if digits and len(digits) >= 2 else None def save_rock_region(cp, l, t, wd, ht, mode="survey"): @@ -96,11 +97,13 @@ 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 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) except Exception as e: print(f"[rock] detect error: {e}") @@ -113,14 +116,15 @@ def detect_selected_region(cp): lines.setdefault(k, []).append(i) for idxs in lines.values(): joined = " ".join(data["text"][i] for i in idxs) - if QTY_RE.search(joined): - xs = [data["left"][i] for i in idxs] - ys = [data["top"][i] for i in idxs] - rs = [data["left"][i] + data["width"][i] for i in idxs] - bs = [data["top"][i] + data["height"][i] for i in idxs] - pad = 10 - region = [mon["left"] + min(xs) - pad, mon["top"] + min(ys) - pad, - (max(rs) - min(xs)) + 2 * pad, (max(bs) - min(ys)) + 2 * pad] + # 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 + 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] save_rock_region(cp, *region, mode="selected") print(f"[rock] auto-detected Selected-Item quantity -> {region}") return region @@ -233,7 +237,12 @@ def get_region(cp): def read_rows(cp, region, mode): import pytesseract - text = pytesseract.image_to_string(w.grab_region(region)) + img = w.grab_region(region) + try: # upscale: small panel text reads better + img = img.resize((img.width * 2, img.height * 2)) + except Exception: + pass + text = pytesseract.image_to_string(img, config="--psm 6") if mode == "selected": q = parse_selected(text) return [("rock", q)] if q else []