"""Draw the model frame through the fitted camera over the picture: the centre plane's grid (0.5 m), the X = +-1 m planes' ground lines, and the Mako sheet's SIDE lines on the centre plane, to read where picture features sit in the model frame. python tg_grid.py -> previews/compare/grid.png """ import numpy as np from PIL import Image, ImageDraw from tg_cam import project, load, HERE ROOT = HERE.parent S, X0, Z0, DZ = 0.0075, 324.0, 805.333, 0.10 def main(): cam = load()["params"] im = Image.open(ROOT / "reference" / "user_picture.jpg").convert("RGB") im = Image.blend(im, Image.new("RGB", im.size, (255, 255, 255)), 0.35) d = ImageDraw.Draw(im) def line(P, col, w=1): uv, z = project(cam, np.array(P)) d.line([tuple(p) for p in uv], fill=col, width=w) for y in np.arange(-2.5, 4.51, 0.5): line([[0, y, -2.0], [0, y, 2.5]], (0, 160, 0) if y % 1 else (0, 90, 0), 1) uv, _ = project(cam, np.array([[0, y, -2.1]])) d.text(tuple(uv[0] + [2, 0]), f"Y{y:g}", fill=(0, 100, 0)) for z in np.arange(-2.0, 2.51, 0.5): line([[0, -2.5, z], [0, 4.5, z]], (0, 160, 0) if z % 1 else (0, 90, 0), 1) uv, _ = project(cam, np.array([[0, -2.6, z]])) d.text(tuple(uv[0] - [34, 6]), f"Z{z:g}", fill=(0, 100, 0)) for x in (1.0, -1.0): line([[x, -2.5, 0], [x, 4.5, 0]], (160, 0, 160), 1) # the sheet's SIDE lines on the centre plane (the Mako's v04 readings) import importlib.util spec = importlib.util.spec_from_file_location("mk", ROOT.parent / "tender-mako" / "build" / "mk_measure.py") mk = importlib.util.module_from_spec(spec) spec.loader.exec_module(mk) for tbl, col in ((mk.TOPY, (255, 0, 0)), (mk.BOTY, (255, 0, 0)), (mk.GTOP, (0, 0, 255)), (mk.SILL, (0, 0, 255)), (mk.DORSAL_LE + mk.DORSAL_TE, (255, 120, 0)), (mk.TAIL4_LE + mk.TAIL4_TE, (255, 120, 0)), (mk.VENT4, (255, 120, 0)), (mk.SHELL, (200, 0, 200)), (mk.JBOT, (150, 0, 0))): P = [[0, (x - X0) * S, (Z0 - y) * S + DZ] for x, y in tbl] line(P, col, 2) im.save(ROOT / "previews" / "compare" / "grid.png") if __name__ == "__main__": main()