Exemplo n.º 1
0
 def __init__(self, per, cal, params):
     self.left = lane.Lane(params)
     self.right = lane.Lane(params)
     self.per = per
     self.cal = cal
     self.params = params
     self.binary = None
Exemplo n.º 2
0
 def __init__(self, vMax1, vMax2):
     vm = [vMax1, vMax2]
     ln = [settings.L1, settings.L2]
     self.lanes = [lane.Lane(ln[i], vm[i], 0.1, i+5) for i in range(2)]
     self.cell_size = settings.CELL_SIZE
     self.e_prob1 = 0.5
     self.e_prob2 = 0.5
    def __init__(self, C, coeff, image_size):
        """
        Constructor
        :param C: Calibration matrix
        :param coeff: Distortion coefficients
        """

        # Store calibration information
        self.C = C
        self.coeff = coeff

        # Save image information
        self.image_width = image_size[0]
        self.image_height = image_size[1]
        self.image_x_center = int(self.image_width / 2)

        # Perspective transform
        self.trapezium = np.float32([[560, 475], [205, self.image_height],
                                     [1105, self.image_height], [724, 475]])
        self.rectangle = np.float32([[(self.image_width / 4), 0],
                                     [(self.image_width / 4),
                                      self.image_height],
                                     [(self.image_width * 3 / 4),
                                      self.image_height],
                                     [(self.image_width * 3 / 4), 0]])

        # Image thresholding information after running from `adjust_parameters()`
        self.lower_HLS_threshold = np.array([0, 55, 74])
        self.upper_HLS_threshold = np.array([85, 255, 255])

        # Left lane information
        self.left_lane = lane.Lane(self.image_x_center)

        # Right lane information
        self.right_lane = lane.Lane(self.image_x_center)

        # Polynomial fit option
        # Number of sliding windows
        self.nwindows = 9
        self.window_height = np.int(self.image_height / self.nwindows)
        # Set the width of the windows +/- margin
        self.margin = 100
        # Set minimum number of pixels found to recenter window
        self.minpix = 50

        # Debug counter
        self.false_counter = 0
Exemplo n.º 4
0
 def __init__(self, num_L, vMax):
     self.lanes = []
     self.probRight = 0.8  # the probability to turn the right lane
     self.probLeft = 0.8  # the probability to turn the left lane
     self.num_L = num_L
     self.q = Queue.Queue()
     self.cell_size = settings.CELL_SIZE
     L = settings.L
     densities = [0.08, 0.08, 0.09, 0.09, 0.09]
     for i in range(num_L):
         if i == num_L - 1:
             vMax -= 1
         self.lanes.append(lane.Lane(L, vMax, densities[i], i))
Exemplo n.º 5
0
    [bus_stop.BusStop(i) for i in range(40, ROAD_LENGTH, 200)], 70)

line_2 = bus_line.BusLine(
    [bus_stop.BusStop(i) for i in range(140, ROAD_LENGTH, 200)], 120)

line_3 = bus_line.BusLine(
    [bus_stop.BusStop(i) for i in range(80, ROAD_LENGTH, 200)], 110)

line_4 = bus_line.BusLine(
    [bus_stop.BusStop(i) for i in range(180, ROAD_LENGTH, 200)], 230)

config_lines = [line_1, line_2, line_3, line_4]

while not condition:
    config_lanes = [
        lane.Lane(),
        lane.Lane(),
        lane.Lane(),
        lane.Lane(True),
    ]

    line_1.last_time_appeared = 0
    line_2.last_time_appeared = 0
    line_3.last_time_appeared = 0
    line_4.last_time_appeared = 0

    sim = sim_module.Simulator(config_lanes, config_lines)

    if not histograms:
        histograms = {}
        for line in config_lines:
def sliding_window(image,
                   n_windows=9,
                   x_margin=100,
                   minpix=50,
                   previous_lane=None,
                   show=False):
    '''
    Parameters
    ----------
    image : np.array
        binary and warped image containing the lane lines
    n_windows : int
        Number of sliding windows in which image is separated along y-axis
    x_margin : int
        width of the window to be addes at either side of the central point
    minpix : int
        minimum bumber of pixels found to recenter window
    '''
    # Derived parameters
    Ny, Nx = image.shape
    if show:  # Create an output image to draw on and  visualize the result
        out_img = np.dstack((image, image, image)) * 255

    # Identify the x and y positions of all nonzero pixels in the image
    nonzero = image.nonzero()
    nonzeroy = np.array(nonzero[0])
    nonzerox = np.array(nonzero[1])

    # Refind lanes
    if previous_lane is None:
        reset = True
    else:
        reset = False
        if not previous_lane.detected:
            reset = True
        if not previous_lane.sanity:
            reset = True

    if reset:
        left_lane_inds, right_lane_inds, out_img = _sliding_window(image,
                                                                   n_windows,
                                                                   x_margin,
                                                                   minpix,
                                                                   show=show)
    else:
        try:
            left_x_pred = previous_lane.left.current_poly(nonzeroy)
            right_x_pred = previous_lane.right.current_poly(nonzeroy)

            # Note to myself: & (bitwise and) and and (logical and) are not the same!
            # Only search +- margin around predicted lane center from previous line fit
            left_lane_inds = np.bitwise_and(
                nonzerox > (left_x_pred - x_margin), nonzerox <
                (left_x_pred + x_margin))
            right_lane_inds = np.bitwise_and(
                nonzerox > (right_x_pred - x_margin), nonzerox <
                (right_x_pred + x_margin))
        except:
            #raise ValueError
            print('Polynomes of previous lane are not defined.')

    left = l.Line(image, left_lane_inds)
    right = l.Line(image, right_lane_inds)
    lane = l.Lane(left, right)

    return lane
Exemplo n.º 7
0
def pipeline(img, left_lane=None, right_lane=None ,mtx=None, dist=None, fname=None, testMode=False):
	""" Pipeline for finding lane lines on a given image. If camera calibration was not done
		in a previous step and the result are not given as mtx and dist to the function, it
		will calibrate the camera on itself.

		The pipeline consists of serveral steps:
		1) Camera Calibration (done if necessary)
		2) Distortion correction
		3) Color & Gradient Threshold
		4) Perspective Transform
		5) Find lanes, calculate curvature and distance to center  with peaks in 
		   histogram. Draw found lanes in transformed image
		6) Retransform image and stack undistorted and rewarped image
		7) Write text with calculations of step 5 on image
		
		Furthermore, it will save the images to output_images folder if it is run in test mode.
	"""
	### Prepare lanes if function was called without
	if left_lane is None:
		left_lane = lane.Lane()
	if right_lane is None:
		right_lane = lane.Lane()

	### Step 1
	if mtx is None or dist is None:
		mtx, dist = camera_calibration.get_camera_calibration_values()

	### Step 2
	dst = cv2.undistort(img, mtx, dist, None, None)

	### Step 3
	combined = color_gradient_threshold.apply_thresholds(dst)

	### Step 4
	mask = perspective_transform.apply_standard_mask_to_image(combined)
	warped = perspective_transform.warp(mask)

	### Step 5
	left_lane, right_lane, center_distance, identified_lanes_image = find_lanes.find_lanes_with_histogram(warped, left_lane, right_lane)
	filled_image = find_lanes.fillPolySpace(identified_lanes_image, left_lane, right_lane)

	### Step 6
	rewarped = perspective_transform.warp(identified_lanes_image, toBirdView=False)
	result = perspective_transform.weighted_img(dst, rewarped, α=0.8, β=1, λ=0)

	### Step 7
	result = __put_texts_on_image(result, left_lane, right_lane, center_distance)

	### Plot result of each step to the output_images folder if run in test mode
	if testMode:
		f, ((ax11, ax12, ax13, ax14),(ax21, ax22, ax23, ax24)) = plt.subplots(2, 4, figsize=(24, 9))
		f.tight_layout()
		ax11.imshow(img)
		ax11.set_title('Original Image', fontsize=50)
		ax12.imshow(dst)
		ax12.set_title('Undistorted Image', fontsize=50)
		ax13.imshow(combined, cmap='gray')
		ax13.set_title('Combination', fontsize=50)
		ax14.imshow(mask, cmap='gray')
		ax14.set_title('Masked Image', fontsize=50)
		ax21.imshow(warped, cmap='gray')
		ax21.set_title('Warped Image', fontsize=50)
		ax22.imshow(identified_lanes_image)
		ax22.plot(left_lane.current_xfitted, left_lane.ploty, color='yellow')
		ax22.plot(right_lane.current_xfitted, right_lane.ploty, color='yellow')
		ax22.set_title('Identified Lanes', fontsize=50)
		ax23.imshow(rewarped)
		ax23.set_title('Rewarped Image', fontsize=50)
		ax24.imshow(result)
		ax24.set_title('Final Image', fontsize=50)
		plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)
		plt.savefig('./output_images/'+fname.split('/')[-1], dpi=100)

	return result
Exemplo n.º 8
0
	""" Pipeline for finding lane lines. It needs a array of the images to proceed.
		The function calls pipeline() to proceed each image.
	"""
	### Get calibration once
	global mtx, dist
	for fname in images:
		img = mpimg.imread(fname)
		### Just for safety I work on a copy of the image
		copy_img = np.copy(img)
		pipeline(img, mtx=mtx, dist=dist, fname=fname, testMode=True)

def video_pipeline(image):
	global mtx, dist, left_lane, right_lane
	return pipeline(image, left_lane, right_lane, mtx, dist, testMode=False)


mtx, dist = camera_calibration.get_camera_calibration_values()
camera_calibration.save_example_camera_calibration_images(mtx, dist)

test_images = glob.glob('./test_images/test*.jpg')
test_pipeline(test_images)
straight_lines_images = glob.glob('./test_images/straight_lines*.jpg')
test_pipeline(straight_lines_images)

left_lane = lane.Lane()
right_lane = lane.Lane()
output = 'processed_project_video.mp4'
clip = VideoFileClip('project_video.mp4')
output_clip = clip.fl_image(video_pipeline)
output_clip.write_videofile(output, audio=False)
Exemplo n.º 9
0
import const
import sprite
import lane

page = 1  # 1=menu, 2=game, 3=

background = pg.display.set_mode((const.WIDTH, const.HEIGHT))

elementsgame = pg.sprite.Group()
elementsmenu = pg.sprite.Group()

Lhama1 = sprite.Player(
    pg.image.load('../../media/sprite/Skin0Test.png').convert_alpha())

Fundo1Game = sprite.Fundo(
    pg.image.load('../../media/img/FundoTest.png').convert_alpha())
Fundo1Menu = sprite.Fundo(
    pg.image.load('../../media/img/MenuTest.png').convert_alpha())

Enemy1 = sprite.Enemy(2)
Enemy2 = sprite.Enemy(1)
Enemy3 = sprite.Enemy(3)

Guacamole1 = sprite.Point(3)

Lane1 = lane.Lane(1, const.WIDTH / 2 - 150)
Lane2 = lane.Lane(2, const.WIDTH / 2)
Lane3 = lane.Lane(3, const.WIDTH / 2 + 150)

lanes = [Lane1, Lane2, Lane3]
Exemplo n.º 10
0
LANE_LEN = 100


def print_lanes(lanes):
    print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
    for lane in lanes.values():
        lane.printl()
    print("-" * LANE_LEN + "--")


if __name__ == "__main__":
    arr = [1, 2, 3, 4, 5]
    print(arr[2:])

    LANES = {
        1: l.Lane(LANE_LEN, speed_limit=3),
        2: l.Lane(LANE_LEN, speed_limit=4),
        3: l.Lane(LANE_LEN, speed_limit=5),
        4: l.Lane(LANE_LEN, speed_limit=6),
        5: l.Lane(LANE_LEN, speed_limit=7)
    }

    LANES[1].add_vehicle(travelled=0)

    while True:
        print_lanes(LANES)

        for lane in LANES.values():
            lane.update()
        time.sleep(0.15)
Exemplo n.º 11
0
 def __init__(self, vMax):
     ln = settings.L3
     self.lanes = lane.Lane(ln, vMax, 0.1, 7)
     self.cell_size = settings.CELL_SIZE
Exemplo n.º 12
0
import path as p

pygame.init()
win = pygame.display.set_mode(config.screen_size)
pygame.display.set_caption("Artificial City")
clock = pygame.time.Clock()

visualisation = Visualisation(win, config.lane_width, config.cell_size,
                              config.c_lanes_coordinates,
                              config.z_lanes_coordinates,
                              config.t_lanes_coordinates)

TRAM_LANES = {1: l.TramLane(number=1), 2: l.TramLane(number=2)}

CAR_LANES = {
    1: l.Lane(number=1, length=25, spawn_probability=0),
    2: l.Lane(number=2, length=35),
    3: l.Lane(number=3, length=30),
    4: l.Lane(number=4, length=30),
    5: l.Lane(number=5, spawn_probability=0),
    6: l.Lane(number=6),
    7: l.Lane(number=7),
    8: l.Lane(number=8),
    9: l.Lane(number=9),
    10: l.Lane(number=10),
    11: l.Lane(number=11)
}

PEDESTRIAN_LANES = {
    1: p.Path(number=1, length=20),
    2: p.Path(number=2, length=20),
Exemplo n.º 13
0
 def addLane(self, edge, speed, length):
     return lane.Lane(edge, speed, length)