# Mako: colour runs along image columns (or rows) of one view of the reference, to read the hull's lines off. # python mk_runs.py side 40 950 10 [y0 y1] -> per column: runs "y0-y1 class" (o orange, g glass, k dark, s grey, r red) import os, sys import numpy as np from PIL import Image HERE = os.path.dirname(os.path.abspath(__file__)) a = np.asarray(Image.open(os.path.join(os.path.dirname(HERE), "reference", "user_reference.webp")).convert("RGB")).astype(int) R, G, B = a[..., 0], a[..., 1], a[..., 2] mx, mn = a.max(-1), a.min(-1) red = (R - G > 25) & (B - G > -15) & (R > 120) obj = ((mn < 222) | (mx - mn > 45)) & ~red C = np.full(R.shape, ".", dtype=" 35) & (B > 120)] = "g" C[obj & (R > 120) & (R - G > 25) & (G - B > 20)] = "o" C[red] = "r" view = sys.argv[1] a0, a1, step = map(int, sys.argv[2:5]) BOX = {"top": (40, 520), "side": (530, 1065), "front": (970, 1410), "rear": (960, 1410)} lo, hi = (int(sys.argv[5]), int(sys.argv[6])) if len(sys.argv) > 6 else BOX[view] rows_mode = view in ("front", "rear") and len(sys.argv) <= 6 or (len(sys.argv) > 7 and sys.argv[7] == "rows") for c in range(a0, a1 + 1, step): line = C[c, lo:hi] if rows_mode else C[lo:hi, c] runs, start = [], 0 for i in range(1, len(line) + 1): if i == len(line) or line[i] != line[start]: if line[start] != "." and i - start >= 3: runs.append("%d-%d%s" % (lo + start, lo + i - 1, line[start])) start = i print(c, " ".join(runs))