Recently, I've been researching how to write image processing IPs using Vitis HLS, which requires integration with OpenCV. However, the setup for OpenCV in Vitis HLS is somewhat complicated, which is why I'm sharing this process guide for everyone's reference.
The general process involves using CMake with MinGW to build and install OpenCV, then setting up the Linker Flags for OpenCV and Vitis Vision Library within Vitis HLS. Therefore, I will explain the process step by step in detail.
Install MinGW and CMake- MinGW
MinGW can be downloaded through this link.
Extract MinGW files somewhere. It looks something like this.
Add MinGW to your Environment variables. The path to the MinGW bin should be added to the Path variables.
- CMake
CMake can be downloaded through this link.
Just download it and install through.msi file, and you will see the CMake GUI like the following image after you execute it.
OpenCV can be downloaded through this link. The version I use is 3416.
Execute the.exe and choose the location you want to extract.
Inside the OpenCV folder, create a new folder called “HLS_Build”. It could be any name you wish.
Now, it’s time to make OpenCV.
Run Cmake-gui through the start menu. In the sources field, choose the OpenCV source path. The source path should be something like I showed.
In the second field, it asks where you want to build the binaries. Here, you select the “HLS_Build” directory that we created previously. If all goes well, you should be able to click the “Configure” button.
Check WITH_OPENGL
Check ENABLE_CXX11
Uncheck WITH_IPP
Uncheck ENABLE_PRECOMPILED_HEADERS
After making your selections, click the configure button again. If there are still red items after execution, continue clicking configure until all items turn white. Then click Generate.
When you see "Configuring done" and "Generating done", it indicates that the process is complete.
Open cmd in “HLS_Build” folder.
Enter mingw32-make to start the compilation. If there are no errors and the progress reaches 100%, congratulations, the compilation was successful.
Enter mingw32-make install. After the process is complete, an install directory will be generated in the “HLS_Build” folder.
Notice: You must properly set the LD_LIBRARY_PATH environment variable for dynamic library search paths and the OpenCV path information in the user's environment for this script and the Vitis Vision example design to function correctly. Additionally, the paths for OpenCV's include libraries and binaries must be included in the system's environment variables. Otherwise, errors related to library inclusion will occur during simulation.
LD_LIBRARY_PATH D:\opencv\HLS_Build\install\x64\mingw\lib
OPENCV_INCLUDE D:\opencv\HLS_Build\install\include
OPENCV_LIB D:\opencv\HLS_Build\install\x64\mingw\lib
Path D:\opencv\HLS_Build\install\x64\mingw\lib;D:\opencv\HLS_Build\install\x64\mingw\bin
The path is based on the location you set yourself.
Download Vitis Vision Library and Link to Vitis HLSVitis Vision Library can be downloaded through this link.
For us, we are concerned with the “vision” libraries. Make sure you download the library because without this our projects won’t work.
The L1 examples contain plenty of projects to try. I would be using the “axiconv_accel” project and recreating it as a starting point for a bigger project.
Create a new folder in the Vitis HLS workspace directory. Copy xf_axiconv_accel.cpp, xf_axiconv_accel_config.h and xf_axiconv_tb.cpp from the vision/L1/examples/axiconv folder.
Then, add the respective files to the Source and Test Bench sections.
Modify the content of these three files. For detailed files, please refer to the attachment.
At Project -> Project Settings, you need to add the necessary flags to the CFLAG and CSIMFLAG in the test file of simulation settings.
-ID:/Xilinx/Vitis_Libraries-2023.2/vision/L1/include -ID:/opencv/HLS_Build/install/include -std=c++14 -Wno-unknown-pragmas
In the Linker Flags, enter the following code:
-L D:/opencv/HLS_Build/install/x64/mingw/lib -lopencv_imgcodecs3416 -lopencv_imgproc3416 -lopencv_core3416 -lopencv_highgui3416 -lopencv_flann3416 -lopencv_features2d3416
3416 refers to the OpenCV version. If you have installed a different version, you need to make the corresponding modifications.
In the synthesis settings, you need to add the following to the CFLAGS in the module file:
-ID:/Xilinx/Vitis_Libraries-2023.2/vision/L1/include -std=c++14 -Wno-unknown-pragmas
Since this example requires an input image, you can place a JPG file in the Source directory.
- C Simulation
- C Synthesis
This shows that we are able to use the vision libraries in Vitis HLS with OpenCV in the Windows Environment. Now, the testbench takes and image and outputs and image. It also prints some text that we didn’t see when running it. The fix is simple and you should be able to figure that out.
Reference
Comments