Welcome to the Self-Driving Car Simulation project! This repository showcases a small-scale self-driving car simulation using TensorFlow models designed for various tasks such as road line detection, traffic sign detection, and arrow direction detection. These models can be run using Python, TensorFlow Lite, and OpenCV, and they are designed to work on both live webcam feeds and video files.
This project is a simulation of a self-driving car on a small scale, like the size of a toy car. The project is divided into three main directories, each focusing on a different aspect of autonomous driving:
- Road Line Detection: Detects lines on the road using TensorFlow Lite.
- Sign Detection: Identifies various traffic signs using TensorFlow Lite.
- Arrow Direction Detection: Determines the direction of arrows detected by the sign detection model.
The repository is organized into three main directories:
- Purpose: Detects the lines on the road using TensorFlow Lite models.
- Files:
detect.tflite: TensorFlow Lite model for line detection.labelmap.txt: Label map for the model.webcam.py: Runs the model on a live webcam feed.detectionOnVideo.py: Runs the model on a pre-recorded video file (video.mp4) and saves the processed video with detected road lines asoutput.mp4.video.mp4: Sample video to test the model.output.mp4: The output video generated after runningdetectionOnVideo.pyonvideo.mp4.
- Purpose: Detects traffic signs in images or video streams.
- Files:
model.tflite: TensorFlow Lite model for traffic sign detection.main.py: Runs the model on a live webcam feed and displays the detected traffic sign.
- Purpose: Determines the direction of an arrow detected by the sign detection model.
- Files:
detect.tflite: TensorFlow Lite model for arrow direction detection.labelmap.txt: Label map for the model.main.py: Runs the model on a live webcam feed and displays the direction of the detected arrow.
To run the models, you'll need to set up a Python environment with the required dependencies.
python3 -m venv self_driving_env
source self_driving_env/bin/activate # On Windows: self_driving_env\Scripts\activatepip install tensorflow opencv-pythonTo verify that TensorFlow and OpenCV are installed correctly, you can run the following commands in the Python interpreter:
import tensorflow as tf
import cv2
print(tf.__version__)
print(cv2.__version__)To detect road lines using a live webcam feed, navigate to the road_line/ directory and run:
python webcam.pyThis script captures video from your webcam and uses the TensorFlow Lite model to detect road lines in real-time.
To detect road lines on a pre-recorded video file and save the output, run:
python detectionOnVideo.pyThis script uses the TensorFlow Lite model to detect road lines in the provided video.mp4 file. The processed video with the detected road lines will be saved as output.mp4 in the same directory.
Navigate to the sign_detection/ directory and run:
python main.pyThis script uses your webcam to detect traffic signs and displays the type of sign detected. The script is capable of detecting the following traffic signs:
- Do Not Enter
- Directional Arrow
- Stop
- Dead End
- No Sign
Based on the detected sign, the script will display the corresponding name on the screen.
Navigate to the ArrowDirection/ directory and run:
python main.pyThis script uses your webcam to detect the direction of arrows. It works by identifying two key points on the arrow: the end (tail) and the tip (head). By comparing the positions of these points, the script determines the direction in which the arrow is pointing (left, right, up, or down). The output will display the direction based on this analysis.
To accelerate the inference of TensorFlow models using a GPU, ensure you have the necessary GPU drivers and CUDA toolkit installed. You can install the GPU-enabled version of TensorFlow with:
pip install tensorflow-gpuFor detailed instructions and system requirements, please visit the TensorFlow GPU support guide.
Make sure your system meets the requirements for running TensorFlow with GPU support. For most small-scale projects like this, the CPU version should suffice, but for more intensive tasks, GPU acceleration can significantly speed up processing.
This project is licensed under the MIT License. See the LICENSE file for details.
Thanks to the following contributors for their support and contributions to this project:
