publish eve_rock_watcher.py

This commit is contained in:
brockdarnold 2026-06-15 02:03:54 +00:00
parent 68b84c1877
commit 00fa861dc8

View file

@ -97,14 +97,20 @@ def detect_selected_region(cp):
tcmd = cp.get("ocr", "tesseract_cmd", fallback="").strip() tcmd = cp.get("ocr", "tesseract_cmd", fallback="").strip()
if tcmd: if tcmd:
pytesseract.pytesseract.tesseract_cmd = 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: try:
with mss.mss() as sct: with mss.mss() as sct:
mon = sct.monitors[0] mon = sct.monitors[0]
raw = sct.grab(mon) raw = sct.grab(mon)
img = Image.frombytes("RGB", raw.size, raw.bgra, "raw", "BGRX") img = Image.frombytes("RGB", raw.size, raw.bgra, "raw", "BGRX")
img = img.resize((img.width * S, img.height * S)) W, Hh = img.size
data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT) 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: except Exception as e:
print(f"[rock] detect error: {e}") print(f"[rock] detect error: {e}")
return None return None
@ -118,13 +124,13 @@ def detect_selected_region(cp):
joined = " ".join(data["text"][i] for i in idxs) joined = " ".join(data["text"][i] for i in idxs)
# the 'Quantity N Units' line: contains 'unit' + a digit (tolerant to OCR) # the 'Quantity N Units' line: contains 'unit' + a digit (tolerant to OCR)
if "unit" in joined.lower() and re.search(r"\d", joined): 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] ys = [data["top"][i] // S for i in idxs]
rs = [(data["left"][i] + data["width"][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] bs = [(data["top"][i] + data["height"][i]) // S for i in idxs]
padx = 170 # extend LEFT to capture the number padx = 180 # extend LEFT to capture the number
region = [mon["left"] + min(xs) - padx, mon["top"] + min(ys) - 8, region = [mon["left"] + cx0 + min(xs) - padx, mon["top"] + cy0 + min(ys) - 8,
(max(rs) - min(xs)) + padx + 20, (max(bs) - min(ys)) + 16] (max(rs) - min(xs)) + padx + 30, (max(bs) - min(ys)) + 16]
save_rock_region(cp, *region, mode="selected") save_rock_region(cp, *region, mode="selected")
print(f"[rock] auto-detected Selected-Item quantity -> {region}") print(f"[rock] auto-detected Selected-Item quantity -> {region}")
return region return region