Autonomous Driving Object Detection on the Raspberry Pi 4!

by ethandell in Circuits > Raspberry Pi

1488 Views, 5 Favorites, 0 Comments

Autonomous Driving Object Detection on the Raspberry Pi 4!

car_gif_compressed.gif

Here is a demo of the project in action! :)

This project leverages a neural network to detect things on the road that an autonomous driving vehicle would see (eg. bus, traffic light, traffic sign, person, bike, truck, motor, car, train, rider). The trained network was tested on lightweight hardware (i.e. Raspberry PI 4) to see how it performs in terms of processing speed and detection accuracy.

For more information, here is the location for Code, YouTube tutorial (for set up information), and Medium Post (on the training and theory)

Open a Command Prompt on Your Raspberry Pi and Clone the Repository

Command: git clone https://github.com/ecd1012/rpi_road_object_detection.git

Change Directory to Source Code

Command: cd rpi_road_object_detection

Open Command Prompt and Make Sure Pi Is Up to Date

Command: sudo apt-get update && sudo apt-get upgrade

Install Virtual Environment

Command: sudo pip3 install virtualenv

Make Virtual Environment

Command:python3.7 -m venv TFLite-venv

Activate Environment

Command: source TFLite-venv/bin/activate

Install Dependencies

Command: bash get_py_requirements.sh

Make Sure the Camera Module Is Enabled

Command: sudo raspi-config

  • Go to Intercae Options and make sure the Pi Camera is enabled.

Setting Up Hardware

hardware.jpg

This project was configured and tested with the following hardware components.

Here is a video tutorial to set up the hardware: https://youtu.be/Zfmo3bMycUg?t=277

Core

  • Raspberry Pi 4 GBRaspberry
  • Pi 5MP Camera (rev 1.3)

Other

  • LED
  • 470 Ohm Resistor
  • Small breadboard
  • GPIO push button
  • 3.5 Amp USB-C Power Supply

Connect Pi Camera Module to Raspberry Pi

Connecting the Camera for This Project: https://youtu.be/Zfmo3bMycUg

Additional Help:

Connect a Push Button to GPIO Pin 17

This will be used as input to kick off the program.

Connecting Push Button for this project: https://youtu.be/Zfmo3bMycUg?t=437

Additional Help:

Connect an LED to GPIO PIN 4

This LED will turn on to indicate when the program is running. Make sure you use a current limiting resistor with the LED!

LED Connection for This Project: https://youtu.be/Zfmo3bMycUg?t=353

Additional Help:

Running Detection

rpi_setup.jpg

Now all the code and software is configured to run object detection!

Mount your Pi in your car and test it out! Drive Safe! :)

Command: python TFLite_detection_webcam_loop.py --modeldir=TFLite_model_bbd --output_path=processed_images

Where the --output_path you specify is where you want images saved.

The script will start running and wait for you to press the GPIO input button to start processing the video feed from the camera. Once you press the button, the green LED will turn on and the pi will start feeding and processing the video stream through the neural network. Processed images will be saved to the '--output_path' you specified over the command line.

If you like, make a video out of the images. You can do this with gif-making software, video-making software, or ffmpeg.

Help: https://stackoverflow.com/questions/24961127/how-...

Test If for Yourself and Let Me Know What You Think!