Setup Vitis HLS 2022.2 and OpenCV on Windows 11 OS

Setup Vitis HLS 2022 and OpenCV
Help us grow. Share with your friends!

Primarily, there is plenty of support to operate Vitis HLS and OpenCV on the Linux environment. This is mainly because of the ease of use on Linux. On Windows operating system, however, the story isn’t straightforward. I struggled a lot to get the two to work together finally. The lack of a proper guide sets you back from using Vitis HLS + OpenCV setup on Windows environment. Prior to Vitis HLS 2020.x, OpenCV came bundled with the installation. One could use it right out of the box after installation and you did not need to carry out any other steps. I even wrote a post a long time back, demonstrating Vivado HLS. I intend for this article to help other struggling souls to find a relatively clear guide on installing OpenCV for Vitis HLS 2022.

Installing OpenCV from source code

It’s important we compile OpenCV on Windows from sources. Download the OpenCV sources from this link. This links to an executable file. If you happen to be behind a firewall, you may prefer to download the source zip from github. Either way, you end up with the OpenCV sources. I ran the executable and gave it a path. It extracted all the sources to the given path.

We need two more tools to build OpenCV; MinGW and CMake.

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.

Inside the OpenCV folder, create a new folder called “mingw_build”. It could be any name you wish.

Now, it’s time to install Cmake-gui. Run the installer and let it install. After completing the installation, 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 above.

In the second field, it asks where you want to build the binaries. Here, you select the “mingw_build” directory that we created previously. If all goes well, you should be able to click the “Configure” button and end up with this screen.

Once you see the “Generating done” message, you can click on “Generate”.

Go to the mingw_build directory and fire up a command prompt window. In case you don’t know, Shift + right click > Open in terminal here. In case you don’t have the terminal, you should see a message to open it in PowerShell or command prompt. Anything will do.

In the Terminal window enter the following command.

mingw32-make

This process takes a while to complete since it actually compiles the C source files into object files. When you’re done with 100% success with the previous command we can proceed ahead.

mingw32-make install

This creates the final binary files required to actually use OpenCV in Windows environment.

Vitis HLS related configurations

We are halfway done to actually using Vitis HLS and OpenCV for our projects. Let’s configure the rest of the setup. Here, I am already assuming you installed Vitis 2022.2 or higher.

To be able to use OpenCV, we need to install a few environment variables again.

Go to Environment variables like earlier and set the following variables:

  1. LD_LIBRARY_PATH – <Path to OpenCV>\mingw_build\install\x64\mingw\lib
  2. OPENCV_INCLUDE – <Path to OpenCV>\mingw_build\install\include
  3. OPENCV_LIB – <Path to OpenCV>\mingw_build\install\x64\mingw\lib

I found out that it’s actually easier to create a HLS project through the tcl script using the command line interface. Finally, when you have a project created, you can quickly jump to using the GUI.

Creating a project through the Command line script

Fire up Vitis HLS in command line mode. You can do that by typing Vitis HLS 2022.2 command prompt and that fires up the command interface of Vitis HLS shell.

You can also launch Vitis HLS in command prompt mode by navigating into the folder and launching it there.

Next step, download the Vitis Libraries from github either through the git command line or directly by downloading the zip.

git clone https://github.com/Xilinx/Vitis_Libraries.git

For us, we are concerned with the “vision” libraries. Make sure you download the library because without this our projects won’t work.

Edit the tcl file for our project

Like I said earlier, we need to run the tcl file because this is an easier approach. We will switch to GUI mode later.

Read the comments carefully and edit the variables accordingly. You would definitely have different directory paths and those should reflect in this file correctly. The last line that declares the OPENCV_LIB_REF calls several openCV modules. For Windows Environment, they need to be invoked with their version numbers. It’s 3416 in my case. It could be something different if you happen to use an older or a newer version.

Creating a new project from examples

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.

  1. Create a new folder in the workspace directory. Copy all “run_hls_standalone.tcl”, and .cpp and .h files from the vision/L1/examples/axiconv folder.
  2. Start Vitis HLS in command prompt mode and navigate to the project directory.
  3. At this point, you should edit your tcl script ready with the correct paths.
  4. Invoke the tcl script and let it do its job.

You may end up with an error after this. This is because of a file called “xf_config_params.h” residing in the “tests” folder of the L1 examples. We don’t need this file but optionally you can include it in your compilation.

We are now ready to proceed with the GUI.

  1. Start Vitis HLS 2022.2 GUI.
  2. Open project > Select the project folder with the name “hls_test”. This is where all the project settings reside that are required for the GUI to pickup and continue.
  3. I edited the program a little to get it to run. Follow the edits as shown below.
    • Comment the “xf_config_params.h” line.
  4. Add the following lines in the .h file.

You should be able to see the project source in the GUI.

Click the Green arrow and click on “C Simulation”. If all goes well, it should finish the simulation and return no errors.

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.

Leave your comment below if you find any errors in my post and also any other tips that others may find useful.

Incoming search terms:

nuclearrambo

Salil is an electronics enthusiast working on various RF and Microwave systems. In his free time he writes on the blog, talks over ham radio or builds circuits. He has Yaesu FT2900R VHF transceiver, FT450D HF transceiver and a TYT UV8000E Handheld transceiver.

You may also like...

4 Responses

  1. ALEXIS CZEZAR TORRENO says:

    Hi,

    Thanks for the article/tutorial however may I ask for clarification on the TCL file part.
    “Edit the tcl file for our project”
    Which TCL file exactly? Is this the run_hls.tcl in the example folder? should i make a new file? should i append the sample code?

    I simply made a new file with the edits and ran the run_hls_standalone.tcl but i didnt create any project directory so I was confused.

    On the create a new project from examples part, i should copy the two .cpp and two .h files and the (edited run tcl file) so 5 files total?

    Thanks! Hopefully this works since I’ve been trying to make HLS work on my machine

    • nuclearrambo says:

      You can see the “code” right below the “Edit the TCL file” heading. Thats the tcl file. You can copy the text and paste it in a file called “run_standalone.tcl”.
      Everything in the post is with respect to this tcl file. Hope you got it now.

  2. jaya says:

    after running the tcl file I am getting :-lopencv_imgcodecs3416 -lopencv_imgproc3416 -lopencv_core3416 -lopencv_highgui3416 -lopencv_flann3416 -lopencv_features2d3416
    what error is this and where could I have been mistaken, please help……..i am stuck at this point since so many days. I have tried via GUI also…..but not working

    • nuclearrambo says:

      Can you paste the full message here? It seems that your script is working but I do not know what messages you are getting further.
      Try to follow the instructions very carefully.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.