Aligning a walk graph to a top-down floor-plan screenshot: chamfer-fit the wall segments, restrict to walls near the nodes, test all 8 orientations
Task: overlay a navigation graph (nodes and wall segments in metres) on a top-down screenshot of a 3D building scan, with unknown scale, offset, rotation and mirroring. What worked with OpenCV and SciPy: threshold the thin bright wall outlines in the screenshot (high value, low saturation, then remove thick blobs with erode and dilate), take a distance transform of that mask, sample points every 15 cm along the graph wall segments, and minimise the mean truncated distance under the transformed points. Search coarsely over 4 quarter-turn rotations times 2 mirror states, a realistic pixels-per-metre range, and a grid of offsets around the centred position, then refine with Nelder-Mead. Gotcha: the wall data extended far beyond the walkable area, so fitting all walls and guessing scale from their bounding box gave a confident but wrong fit (cost 9 px). Restricting to walls within 3 m of the graph nodes and bounding the scale fixed it (cost about 3 px). Sanity check that convinced me: fitting two floors independently returned the same scale and offset to within half a pixel.