This project demonstrates a lane detection system using the Carla autonomous driving simulator. The goal is to detect lane lines and steer the vehicle within the detected lane.
Project Overview
The project consists of these main components:
Carla Simulator Setup: The code connects to the Carla server, loads a map, spawns a vehicle, and attaches a camera sensor to capture images.
Lane Detection: Camera images from the vehicle’s perspective are processed to detect lane markings.
Perspective Transformation: Images are transformed into a bird-eye view to make lane detection easier.
Sliding Window Technique: A sliding window algorithm is applied to locate lane pixels in the processed images.
Polynomial Fitting: Detected lane pixels are fitted to a second-degree polynomial representing lane lines.
Curvature Calculation: The curvature of the lane lines and the vehicle’s position within the lane are calculated.
Vehicle Control: Steering and speed of the vehicle are controlled based on the detected lane to keep the vehicle centered.
How It Works?
Simulation Setup:
The Carla client connects to the server at localhost:2000.
Weather and environmental conditions (cloudiness, precipitation, etc.) are set.
A vehicle is spawned at a predefined point in the simulation.
Camera Setup:
An RGB camera sensor is attached to the vehicle to capture front-facing images.
Lane Detection:
Images are transformed into a top-down view.
The sliding window method is used to identify lane pixels.
A second-degree polynomial curve is fitted to the lane pixels.
The curvature of the lane is calculated, showing how sharply the lane is curving.
Vehicle Control:
Based on the detected lane, the vehicle’s position is adjusted.
The vehicle receives steering, throttle, and brake commands to stay centered in the lane.
The vehicle will turn left, right, or go straight based on the lane curvature.
How To Run
Requirements:
Carla Simulator (Make sure the server is running on localhost:2000).
Python dependencies: cv2, carla, numpy, and other necessary libraries.
Steps:
Start the Carla simulator.
Run the main Python script:
python main.py
The vehicle will start driving in the Carla environment, and the lane detection system will guide it based on the detected lane lines.
Stopping the Program:
Press q on the OpenCV window to stop the program.
Key Functions
get_perspective_matrices(): Applies perspective transformation to make lane detection easier.
hist(): Computes a pixel intensity histogram to identify lane lines.
find_lane_pixels(): Detects lane pixel points using a sliding window technique.
fit_poly(): Fits a second-degree polynomial curve to the detected lane pixel points.
measure_curvature(): Calculates the curvature of lane lines.
plot(): Draws lane lines on the output image and applies vehicle control based on lane detection.
Feel free to customize and expand this lane detection system in your own Carla simulation projects!