This is an implementation for High-Level Synthesis, which recognizes the color of LEDs in traffic lights being developed for an autonomous driving competition. We refer to a previous study[1] as the algorithm for detecting traffic light. This repository explains how to run C simulation, how to generate Bitstream, and how to run the generated circuit. Commits on the master branch (a.k.a. main branch) may not match the contents of this README. Please refer to release tags for exact information.
- Vitis HLS 2022.1
- Vivado 2022.1
- OpenCV 4.4.0 (Used for test bench only in Vitis HLS)
- Kria KV260 Vision AI Starter Kit
-
Clone this repository
git clone git@github.com:MEVIUS-FPT/hls_traffic_light_recognition.git -b v1.2
-
Create Vitis HLS project
The following command will generate a directory about the project named traffic_light_recognition_vitis_hls/ by Vitis HLS.cd hls vitis_hls create_vitis_hls_project.tcl
-
Start GUI and open the created project
-
Follow the instructions for the test image to save the image properly
-
Set the OpenCV library path
In the Simulation tab of Project Settings, we have set the following. It may differ depending on your environment.- Linker Flags
-L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_imgproc
- CFLAGS Value in traffic_light_recognition_tb.cpp
-I/usr/local/include/opencv4 -std=c++14
-
Run
The result of recognition for the input image is displayed as a number. The meanings of the numbers are as follows:Result Meaning 3 Green 2 Yellow 1 Red 0 Color recognition failed due to no detection
-
C Synthesis and Export RTL as IP from Vitis HLS
-
Create Block Design
Add ZYNQ PS, DMA Controller, and Traffic Light Recognition IP to the block design file. Then configure the IP core settings: For ZYNQ PS, enable one GP port (master) and one HP port (slave). For DMA Controller, disableScatter Gather Engine
andWrite Channel
and setWidth of Buffer Length Register
to 26. In addition, setMemory Map Data Width
andStream Data Width
of theRead Channel
to 32. Finally, connect the blocks together withRun Connection Automation
. The block design will be as follows: -
Generate Bitstream
The hardware utilization after implementation for K26 is as follows:
After generating Bitstream, let's see how it works on your board. This section must be run on the FPGA board.
- Upload necessary files to jupyter notebook server
The required files are as follows:- Generated
.bit
and.hwh
- sample notebook
- Input Image
Images used in C Simulation can be used
- Generated
- Edit Notebook
The path to the.bit
and the path to the input image are hard-coded, so please make the appropriate settings in your environment. - Run
The filename of input images and the resulting values as described in the C simulation section will be output.
Available under The 3-Clause BSD License.
[1] OMACHI, Masako; OMACHI, Shinichiro. Traffic light detection with color and edge information. In: 2009 2nd IEEE International Conference on Computer Science and Information Technology. IEEE, 2009. p. 284-287.