"""Paired straight access boundaries from LSD anchors in a reviewed region.""" import cv2,numpy as np from shapely.geometry import LineString,Point from shapely.ops import substring from plan_junctions import unit,line_intersection import qualify_junctions as q def fit_access(line,center,e,bounds): station=line.project(Point(center));origin=np.asarray(line.interpolate(station).coords[0]);segment=np.array(substring(line,max(0,station-3),min(line.length,station+3)).coords) u=unit(segment[-1,:2]-segment[0,:2]);v=np.array([-u[1],u[0]]) if np.mean(e.occupancy(origin[None,:2]+v)-e.occupancy(origin[None,:2]-v))>0:v=-v raw=cv2.createLineSegmentDetector(cv2.LSD_REFINE_STD).detect(cv2.cvtColor(e.image,cv2.COLOR_RGB2GRAY))[0] anchors=[];transverse=[] for r in ([]if raw is None else raw[:,0,:]): ends=q.world(r.reshape(2,2),e.g);mid=ends.mean(0);length=np.linalg.norm(ends[1]-ends[0]);direction=unit(ends[1]-ends[0]);depth=float((mid-origin[:2])@v) if length<.8 or not(bounds[0].97 and .5.97 and depth>3:transverse.append(dict(ends=ends,length=length,mid=mid,depth=depth)) choices=[] for i,a in enumerate(anchors): for b in anchors[i+1:]: if a['direction']@b['direction']<.99:continue direction=unit(a['direction']*a['length']+b['direction']*b['length']);normal=np.array([-direction[1],direction[0]]) if normal@u<0:normal=-normal origins=sorted([a['mid'],b['mid']],key=lambda p:p@normal);width=float((origins[1]-origins[0])@normal) if not 2anchor_depth+.4 and x['length']>.45*width and abs((x['mid']-midpoint)@normal)