def poly_line(self, coordinates, line_width, seg_noise = 0):
#Note that we subtract generation offsets from the curve coordinates before calculating the line segment locations
x,y = bezier_curve(coordinates[ 0, : ] - self.cropsize[0],
coordinates[1, :] - self.cropsize[1], self.n_segments)
true_line = np.array([x, y])
#Add some noise to the line so it's harder to over fit
noise_line = true_line + seg_noise * np.random.randn(2, true_line.shape[1])
#Create the virtual point path needed to give the line width when drawn by polygon:
polygon_path = np.zeros( (true_line.shape[0], 2 * true_line.shape[1] + 1) , dtype=float)
#Now we offset the noisy line perpendicularly by the line width to give it depth (rhs)
polygon_path[:, 1:(true_line.shape[1]-1) ] = (noise_line[:,1:true_line.shape[1]-1]
+ line_width * np.transpose(self.perpendicular(
np.transpose(noise_line[:,2:] - noise_line[:, :noise_line.shape[1]-2]) ) ) )
#Same code but subtracting width and reverse order to produce the lhs of the line
polygon_path[:, (2*true_line.shape[1]-2):(true_line.shape[1]) :-1 ] = (noise_line[:,1:true_line.shape[1]-1]
- line_width * np.transpose(self.perpendicular(
np.transpose(noise_line[:,2:] - noise_line[:, :noise_line.shape[1]-2]) ) ) )
#These points determine the bottom end of the line:
polygon_path[:, true_line.shape[1]-1] = noise_line[:, true_line.shape[1]-1] - [line_width, 0]
polygon_path[:, true_line.shape[1] ] = noise_line[:, true_line.shape[1]-1] + [line_width, 0]
#Now we set the start and endpoints (they must be the same!)
polygon_path[:, 0] = noise_line[:, 0] - [line_width, 0]
polygon_path[:, 2*true_line.shape[1] -1] = noise_line[:, 0] + [line_width, 0] #This is the last unique point
polygon_path[:, 2*true_line.shape[1] ] = noise_line[:, 0] - [line_width, 0]
#Actually draw the polygon
rr, cc = polygon((polygon_path.astype(int)[1]), polygon_path.astype(int)[0], ( self.view_res[1], self.view_res[0]) )
return rr, cc
# Draws dashed lines like the one in the center of the road
# FIXME add noise to the dashed line generator to cut down on over-fitting(may be superfluous)
评论列表
文章目录