"""Bounded local strip proposals from opposite edges of connected paint. The binary foreground is supplied by the existing primary detector. No colour, visibility, road or final-admission threshold is changed. A connected parking shape can contain several thin bodies; its whole bounding box is not a body. """ import cv2 import numpy as np def branches(contour,binary,mpp): boundary=cv2.approxPolyDP(contour,.025/mpp,True)[:,0].astype(float) if len(boundary)<=4:return [] starts=boundary;ends=np.roll(boundary,-1,axis=0);vectors=ends-starts lengths=np.linalg.norm(vectors,axis=1);keep=lengths*mpp>.26 starts,ends,lengths,vectors=starts[keep],ends[keep],lengths[keep],vectors[keep] if len(starts)<2:return [] axes=vectors/lengths[:,None];candidates=[] # Each contour edge may support at most one opposite-side interpretation. # This bounds alternatives by observed boundary complexity, not a grid of # guessed angles/widths/positions or a list of previously missed objects. for i,(a,b,u)in enumerate(zip(starts,ends,axes)): n=np.array([-u[1],u[0]]);best=None alignment=axes@u for j in np.flatnonzero(alignment<-np.cos(np.deg2rad(8))): if j==i:continue q=np.array([starts[j],ends[j]])-a;t=q@u;offset=q@n width=abs(float(np.mean(offset))) if not .045.045:continue lo=max(0.,float(t.min()));hi=min(lengths[i],float(t.max())) length=(hi-lo)*mpp if not .260].mean()) if fill<=.48:continue score=(length,fill,-width,-int(j)) if best is None or score>best[0]:best=(score,box,tuple(sorted((i,int(j))))) if best is not None:candidates.append(best) unique={pair:(score,box)for score,box,pair in candidates} return [unique[pair][1]for pair in sorted(unique)]