Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
44 lines
2.1 KiB
Python
44 lines
2.1 KiB
Python
import numpy as np,cv2
|
|
from fit_scene import world
|
|
from layer_common import sample
|
|
|
|
def collect(rgb,vehicle,geometry,labels,low,high,name):
|
|
proposals=[]
|
|
size = rgb.shape[0]; cell = 60 / size
|
|
yy, xx = np.mgrid[:1200, :1200]
|
|
xy = world(np.c_[xx.ravel(), yy.ravel()], geometry)
|
|
paved = np.isin(sample(labels, xy, low, high), [1, 2]).reshape(1200, 1200)
|
|
known = paved & (geometry['alpha'] >= .8) & (vehicle < .2)
|
|
known = cv2.resize(known.astype('uint8'), (size, size), interpolation=cv2.INTER_NEAREST) > 0
|
|
gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
|
|
hsv = cv2.cvtColor(rgb, cv2.COLOR_RGB2HSV)
|
|
k = max(3, round(.72 / cell) // 2 * 2 + 1)
|
|
ridge = cv2.morphologyEx(gray, cv2.MORPH_TOPHAT,
|
|
cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (k, k)))
|
|
paint = (known & (ridge > 12) & (gray > 100) & (hsv[:, :, 1] < 100)).astype('uint8')
|
|
count = 0
|
|
for closing_m in [0., .04, .08]:
|
|
radius = max(1, round(closing_m / cell))
|
|
binary = cv2.morphologyEx(paint, cv2.MORPH_CLOSE,
|
|
cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2*radius+1, 2*radius+1))) if closing_m else paint
|
|
contours, hierarchy = cv2.findContours(binary, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
|
|
if hierarchy is None:
|
|
continue
|
|
for i, contour in enumerate(contours):
|
|
if hierarchy[0, i, 3] >= 0 or len(contour) < 4:
|
|
continue
|
|
rect = cv2.minAreaRect(contour)
|
|
length, width = sorted(np.asarray(rect[1])*cell, reverse=True)
|
|
if not (.35 < length < 2.5 and .25 < width < 1.7):
|
|
continue
|
|
holes = 0; j = hierarchy[0, i, 2]
|
|
while j >= 0:
|
|
holes += cv2.contourArea(contours[j]) >= 9
|
|
j = hierarchy[0, j, 0]
|
|
if holes < 2:
|
|
continue
|
|
center = world((np.asarray(rect[0])[None, :]+.5)*1200/size-.5, geometry)[0]
|
|
proposals.append(dict(center=center.tolist(), source='paint-topology', seed_tile=name))
|
|
count += 1
|
|
return proposals
|