"""Grouper: the sheet's views beside the model's Workbench renders (previews/wb_.png from gr_preview.py ortho), plain Python (PIL): for each view the sheet's box scaled 4x (FRONT and BACK stretched by 1/KF, 1/KB to the model's uniform scale) above the render, and the render's outline (red) over the sheet. -> previews/compare/sheet_.png and sheet_all.png python build/gr_compare_sheet.py [tag]""" import os, sys import numpy as np from PIL import Image, ImageDraw, ImageFilter HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) TAG = (sys.argv[1] + "_") if len(sys.argv) > 1 else "" exec(open(os.path.join(HERE, "gr_measure.py"), encoding="utf-8").read()) sheet = Image.open(os.path.join(ROOT, "reference", "user_blueprint.jpg")).convert("RGB") OUT = os.path.join(ROOT, "previews", "compare") os.makedirs(OUT, exist_ok=True) BOX = {"side": (430, 255, 1010, 520), "top": (440, 20, 1000, 250), "front": (95, 215, 385, 550), "back": (1075, 235, 1345, 550)} KH = {"side": 1.0, "top": 1.0, "front": 1.0 / KF, "back": 1.0 / KB} tiles = [] for v, (x0, y0, x1, y1) in BOX.items(): p = os.path.join(ROOT, "previews", "%swb_%s.png" % (TAG, v)) if not os.path.exists(p): continue ren = Image.open(p).convert("RGB") crop = sheet.crop((x0, y0, x1, y1)).resize(ren.size, Image.LANCZOS) a = np.asarray(ren).astype(np.int16) bg = a[2, 2] mask = (np.abs(a - bg).sum(axis=2) > 24) m = Image.fromarray((mask * 255).astype(np.uint8)) edge = np.asarray(m.filter(ImageFilter.FIND_EDGES)) > 0 ov = np.asarray(crop).copy() ov[edge] = (255, 40, 40) over = Image.fromarray(ov) W, H = ren.size tile = Image.new("RGB", (W, H * 3 + 40), (15, 15, 18)) tile.paste(crop, (0, 0)); tile.paste(ren, (0, H + 20)); tile.paste(over, (0, 2 * H + 40)) d = ImageDraw.Draw(tile) d.text((8, 4), "SHEET " + v.upper(), fill=(255, 220, 90)) d.text((8, H + 24), "MODEL (Workbench, ortho, same scale)", fill=(255, 220, 90)) d.text((8, 2 * H + 44), "model outline (red) over the sheet", fill=(255, 220, 90)) tile.save(os.path.join(OUT, "%ssheet_%s.png" % (TAG, v))) tiles.append((v, over)) print("COMPARE OK", [t[0] for t in tiles])