Lane and Object Detection
Using OpenCV and YOLOv7
|
Lane and object detection for use in autonomous vehicles using OpenCV and YOLOv7.
Binaries can be found in Releases or, if preferred, CMake can be used to build the project from source either through the PowerShell helper module:
or manually:
Here are the full list of options for Lane and Object Detection:
Checkout the documentation page built using Doxygen and hosted using Github pages.
This program uses YOLOv7 for object detection and OpenCV for lane detection. OpenCV is also used for handling IO such as reading and writing video file as well as display the output to a window.
The object detection is able to detect most road-related objects such as cars, buses, trucks, cyclists, pedestrians, traffic lights, etc. The accuracy and speed of detection is dependent upon the available GPU compute. For higher quality detection select a higher blob size. For more performant detection select a lower blob size, and/or select the tiny detector type and/or GPU backend. For maximum performance the CUDA backend should be used, however, this requires building OpenCV with CUDA which is not supported with this projects built-in installation script.
The lane detection code is custom made for this program. The one sentence summary would be that it: creates an ROI frame to isolate the road markings immediately in front of the car, runs the Canny algorithm to retrieve the edges, runs the Hough transform to get the straight lines, de-noises and categorises the straight lines to determine the location of the current lane.
The program has two modes:
Normal Mode which only displays the current driving state and the detected left and right lane line types:
Debug Mode which additionally displays the current FPS, average FPS and the ROI, Canny and Hough intermediary frames.
Both modes support recording the output of the main frame.
Pressing q will quit the program.
The project includes performance testing and graphing capability to test the FPS across the blob sizes and yolo types.
Build the C++ code as mentioned in Getting Started and run the performance tests (replace <<platform name>>) which will output their results into a SQLite database file:
Install the python dependencies:
Run the performance graph generation (single platform):
or for multiple platforms (this will generate individual platform and multi-platform graphs):
The following are some example graph outputs based on the following invocation:
The continuous integration workflow runs against all commits on pull requests, builds the code, runs unit tests and performs linting checks.
The continuous deployment workflow runs against all commits to main, builds the code and deploys the executables as a release.
For development a few extra tools are needed to check for linting issues locally which include the Linters and OpenCV submodules:
The development dependencies are:
All linting helper functions can be found in the Linters submodule.
Any generator can be used to build the project but to prior to running clang-tidy/clang-format CMake must be configured using a generator that creates a compile_commands.json file in the build directory (e.g. -G "Ninja", -G "NMake Makefiles", etc)
On windows, clang-tidy and clang-format can be installed using the LLVM-x.x.x-win64.exe binary from the LLVM release page or from chocolatey using choco install llvm -y.
On Windows, Visual Studio 2022 can be used by opening the folder as a CMake project and Visual Studio Code can be used by opening the folder through the Developer PowerShell for VS (otherwise you may see errors around cl.exe not being found).