Getting Started with SDSoC
This chapter provides the information you need to bring up your design using the xfOpenCV library functions.
Prerequisites
- Download and install the SDx development environment according to the
directions provided in SDSoC
Environments Release Notes, Installation, and Licensing
Guide (UG1294). Before
launching the SDx development environment on Linux, set the
$SYSROOT
environment variable to point to the Linux root file system if using terminal to build project, delivered with the reVISION platform. For example:export SYSROOT = <local folder>/zcu104_rv_ss/sw/a53_linux/a53_linux/sysroot/aarch64-xilinx-xilinx
- Download the Zynq® UltraScale+™ MPSoC Embedded Vision Platform zip file and extract its contents. Create the SDx development environment workspace in the zcu104_rv_ss folder of the extracted design file hierarchy. For more details, see the reVISION Getting Started Guide.
- Set up the ZCU104 evaluation board. For more details, see the reVISION Getting Started Guide.
- Download the xfOpenCV library. This
library is made available through github. Run the following
git clone
command to clone the xfOpenCV repository to your local disk:git clone https://github.com/Xilinx/xfopencv.git
Migrating HLS Video Library to xfOpenCV
The HLS video library will soon be deprecated .All the functions and most of the infrastructure available in HLS video library are now available in xfOpenCV with their names changed and some modifications. These HLS video library functions ported to xfOpenCV support SDSoc build flow also.
This section provides the details on using the C++ video processing functions and the infrastructure present in HLS video library.
Infrastructure Functions and Classes
All the functions imported from HLS video library now take xf::Mat (in sync with xfOpenCV library) to represent image data instead of hls::Mat. The main difference between these two is that the hls::Mat uses hls::stream to store the data whereas xf::Mat uses a pointer. Therefore, hls:: Mat cannot be exactly replaced with xf::Mat for migrating.
Below table summarizes the differences between member functions of hls::Mat to xf::Mat.
Member Function | hls::Mat (HLS Video lib) | Xf::Mat (xfOpenCV lib) |
---|---|---|
channels() | Returns the number of channels | Returns the number of channels |
type() | Returns the enum value of pixel type | Returns the enum value of pixel type |
depth() | Returns the enum value of pixel type | Returns the depth of pixel including channels |
read() | Readout a value and return it as a scalar from stream | Readout a value from a given location and return it as a packed (for multi-pixel/clock) value. |
operator >> | Similar to read() | Not available in xfOpenCV |
operator << | Similar to write() | Not available in xfOpenCV |
Write() | Write a scalar value into the stream | Writes a packed (for multi-pixel/clock) value into the given location.. |
Infrastructure files available in HLS Video Library hls_video_core.h, hls_video_mem.h, hls_video_types.h are moved to xf_video_core.h, xf_video_mem.h, xf_video_types.h in xfOpenCV Library and hls_video_imgbase.h is deprecated. Code inside these files unchanged except that these are now under xf::namespace.
Classes
- Memory Window Buffer
- hls::window is now xf::window. No change in the implementation, except the namespace change. This is located in “xf_video_mem.h” file.
- Memory Line Buffer
- hls::LineBuffer is now xf::LineBuffer. No difference between the two, except xf::LineBuffer has extra template arguments for inferring different types of RAM structures, for the storage structure used. Default storage type is “RAM_S2P_BRAM” with RESHAPE_FACTOR=1. Complete description can be found here xf::LineBuffer. This is located in xf_video_mem.h file.
Funtions
- OpenCV interface functions
- These functions covert image data of OpenCV Mat format to/from HLS AXI types. HLS Video Library had 14 interface functions, out of which, two functions are available in xfOpenCV Library: cvMat2AXIvideo and AXIvideo2cvMat located in “xf_axi.h” file. The rest are all deprecated.
- AXI4-Stream I/O Functions
- The I/O functions which convert hls::Mat to/from AXI4-Stream compatible data type (hls::stream) are hls::AXIvideo2Mat, hls::Mat2AXIvideo. These functions are now deprecated and added 2 new functions xf::AXIvideo2xfMat and xf:: xfMat2AXIvideo to facilitate the xf::Mat to/from conversion. To use these functions, the header file "xf_infra.h" must be included.
xf::window
A template class to represent the 2D window buffer. It has three parameters to specify the number of rows, columns in window buffer and the pixel data type.
Class definition
template<int ROWS, int COLS, typename T>
class Window {
public:
Window()
/* Window main APIs */
void shift_pixels_left();
void shift_pixels_right();
void shift_pixels_up();
void shift_pixels_down();
void insert_pixel(T value, int row, int col);
void insert_row(T value[COLS], int row);
void insert_top_row(T value[COLS]);
void insert_bottom_row(T value[COLS]);
void insert_col(T value[ROWS], int col);
void insert_left_col(T value[ROWS]);
void insert_right_col(T value[ROWS]);
T& getval(int row, int col);
T& operator ()(int row, int col);
T val[ROWS][COLS];
#ifdef __DEBUG__
void restore_val();
void window_print();
T val_t[ROWS][COLS];
#endif
};
Parameter Descriptions
The following table lists the xf::Window class members and their descriptions.
Parameter | Description |
---|---|
Val | 2-D array to hold the contents of buffer. |
Member Function Description
Function | Description |
---|---|
shift_pixels_left() | Shift the window left, that moves all stored data within the window right, leave the leftmost column (col = COLS-1) for inserting new data. |
shift_pixels_right() | Shift the window right, that moves all stored data within the window left, leave the rightmost column (col = 0) for inserting new data. |
shift_pixels_up() | Shift the window up, that moves all stored data within the window down, leave the top row (row = ROWS-1) for inserting new data. |
shift_pixels_down() | Shift the window down, that moves all stored data within the window up, leave the bottom row (row = 0) for inserting new data. |
insert_pixel(T value, int row, int col) | Insert a new element value at location (row, column) of the window. |
insert_row(T value[COLS], int row) | Inserts a set of values in any row of the window. |
insert_top_row(T value[COLS]) | Inserts a set of values in the top row = 0 of the window. |
insert_bottom_row(T value[COLS]) | Inserts a set of values in the bottom row = ROWS-1 of the window. |
insert_col(T value[ROWS], int col) | Inserts a set of values in any column of the window. |
insert_left_col(T value[ROWS]) | Inserts a set of values in left column = 0 of the window. |
insert_right_col(T value[ROWS]) | Inserts a set of values in right column = COLS-1 of the window. |
T& getval(int row, int col) | Returns the data value in the window at position (row,column). |
T& operator ()(int row, int col) | Returns the data value in the window at position (row,column). |
restore_val() | Restore the contents of window buffer to another array. |
window_print() | Print all the data present in window buffer onto console. |
Template Parameter Description
Parameter | Description |
---|---|
ROWS | Number of rows in the window buffer. |
COLS | Number of columns in the window buffer. |
T | Data type of pixel in the window buffer. |
Window<K_ROWS, K_COLS, unsigned char> kernel;
xf::LineBuffer
A template class to represent 2D line buffer. It has three parameters to specify the number of rows, columns in window buffer and the pixel data type.
Class definition
template<int ROWS, int COLS, typename T, XF_ramtype_e MEM_TYPE=RAM_S2P_BRAM, int RESHAPE_FACTOR=1>
class LineBuffer {
public:
LineBuffer()
/* LineBuffer main APIs */
/* LineBuffer main APIs */
void shift_pixels_up(int col);
void shift_pixels_down(int col);
void insert_bottom_row(T value, int col);
void insert_top_row(T value, int col);
void get_col(T value[ROWS], int col);
T& getval(int row, int col);
T& operator ()(int row, int col);
/* Back compatible APIs */
void shift_up(int col);
void shift_down(int col);
void insert_bottom(T value, int col);
void insert_top(T value, int col);
T val[ROWS][COLS];
#ifdef __DEBUG__
void restore_val();
void linebuffer_print(int col);
T val_t[ROWS][COLS];
#endif
};
Parameter Descriptions
The following table lists the xf::LineBuffer class members and their descriptions.
Parameter | Description |
---|---|
Val | 2-D array to hold the contents of line buffer. |
Member Functions Description
Function | Description |
---|---|
shift_pixels_up(int col) | Line buffer contents Shift up, new values will be placed in the bottom row=ROWS-1. |
shift_pixels_down(int col) | Line buffer contents Shift down, new values will be placed in the top row=0. |
insert_bottom_row(T value, int col) | Inserts a new value in bottom row= ROWS-1 of the line buffer. |
insert_top_row(T value, int col) | Inserts a new value in top row=0 of the line buffer. |
get_col(T value[ROWS], int col) | Get a column value of the line buffer. |
T& getval(int row, int col) | Returns the data value in the line buffer at position (row, column). |
T& operator ()(int row, int col); | Returns the data value in the line buffer at position (row, column). |
Template Parameter Description
Parameter | Description |
---|---|
ROWS | Number of rows in line buffer. |
COLS | Number of columns in line buffer. |
T | Data type of pixel in line buffer. |
MEM_TYPE | Type of storage element. It takes one of the following enumerated values: RAM_1P_BRAM, RAM_1P_URAM, RAM_2P_BRAM, RAM_2P_URAM, RAM_S2P_BRAM, RAM_S2P_URAM, RAM_T2P_BRAM, RAM_T2P_URAM. |
RESHAPE_FACTOR | Specifies the amount to divide an array. |
LineBuffer<3, 1920, XF_8UC3, RAM_S2P_URAM,1> buff;
Video Processing Functions
The following table summarizes the video processing functions ported from HLS Video Library into xfOpenCV Library along with the API modifications.
Functions | HLS Video Library -API | xfOpenCV Library-API |
---|---|---|
addS |
|
|
AddWeighted |
|
|
Cmp |
|
|
CmpS |
|
|
Max |
|
|
MaxS |
|
|
Min |
|
|
MinS |
|
|
PaintMask |
|
|
Reduce |
|
|
Zero |
|
|
Sum |
|
|
SubS |
|
|
SubRS |
|
|
Set |
|
|
Absdiff |
|
|
And |
|
|
Dilate |
|
|
Duplicate |
|
|
EqualizeHist |
|
|
erode |
|
|
FASTX |
|
|
Filter2D |
|
|
GaussianBlur |
|
|
Harris |
|
|
CornerHarris |
|
|
HoughLines2 |
|
|
Integral |
|
|
Merge |
|
|
MinMaxLoc |
|
|
Mul |
|
|
Not |
|
|
Range |
|
|
Resize |
|
|
sobel |
|
|
split |
|
|
Threshold |
|
|
Scale |
|
|
InitUndistortRectifyMapInverse |
|
|
Avg, mean, AvgStddev |
|
|
CvtColor |
|
Color Conversion |
Using the xfOpenCV Library
This section describes using the xfOpenCV library in the SDx development environment.
include folder constitutes all the necessary components to build a Computer Vision or Image Processing pipeline using the library. The folders common and core contain the infrastructure that the library functions need for basic functions, Mat class, and macros. The library functions are categorized into three folders, features, video and imgproc based on the operation they perform. The names of the folders are self-explanatory.
To work with the library functions, you need to include the path to the The xfOpenCV library is structured as shown in the following table. The include folder in the SDx project. You can include relevant header files for the library functions you will be working with after you source the include folder’s path to the compiler. For example, if you would like to work with Harris Corner Detector and Bilateral Filter, you must use the following lines in the host code:
#include “features/xf_harris.hpp” //for Harris Corner Detector
#include “imgproc/xf_bilateral_filter.hpp” //for Bilateral Filter
#include “video/xf_kalmanfilter.hpp”
After the headers are included, you can work with the library functions as described in the xfOpenCV Library API Reference using the examples in the examples folder as reference.
The following table gives the name of the header file, including the folder name, which contains the library function.
Function Name | File Path in the include folder |
---|---|
xf::accumulate | imgproc/xf_accumulate_image.hpp |
xf::accumulateSquare | imgproc/xf_accumulate_squared.hpp |
xf::accumulateWeighted | imgproc/xf_accumulate_weighted.hpp |
The xfOpenCV library is structured as shown in the following table.xf::absdiff, xf::add, xf::subtract, xf::bitwise_and, xf::bitwise_or, xf::bitwise_not, xf::bitwise_xor,xf::multiply ,xf::Max, xf::Min, xf::compare, xf::zero, xf::addS, xf::SubS, xf::SubRS ,xf::compareS, xf::MaxS, xf::MinS, xf::set | core/xf_arithm.hpp |
xf::addWeighted | imgproc/xf_add_weighted.hpp |
xf::bilateralFilter | imgproc/xf_histogram.hpp |
xf::boxFilter | imgproc/xf_box_filter.hpp |
xf::boundingbox | imgproc/xf_boundingbox.hpp |
xf::Canny | imgproc/xf_canny.hpp |
xf::Colordetect | imgproc/xf_colorthresholding.hpp, imgproc/xf_bgr2hsv.hpp, imgproc/xf_erosion.hpp, imgproc/xf_dilation.hpp |
xf::merge | imgproc/xf_channel_combine.hpp |
xf::extractChannel | imgproc/xf_channel_extract.hpp |
xf::convertTo | imgproc/xf_convert_bitdepth.hpp |
xf::crop | imgproc/xf_crop.hpp |
xf::filter2D | imgproc/xf_custom_convolution.hpp |
xf::nv122iyuv, xf::nv122rgba, xf::nv122yuv4, xf::nv212iyuv, xf::nv212rgba, xf::nv212yuv4, xf::rgba2yuv4, xf::rgba2iyuv, xf::rgba2nv12, xf::rgba2nv21, xf::uyvy2iyuv, xf::uyvy2nv12, xf::uyvy2rgba, xf::yuyv2iyuv, xf::yuyv2nv12, xf::yuyv2rgba,xf::rgb2iyuv,xf::rgb2nv12,xf::rgb2nv21,xf::rgb2yuv4,xf::rgb2uyvy,xf::rgb2yuyv,xf::rgb2bgr,xf::bgr2uyvy,xf::bgr2yuyv,xf::bgr2rgb,xf::bgr2nv12,xf::bgr2nv21,xf::iyuv2nv12,xf::iyuv2rgba,xf::iyuv2rgb,xf::iyuv2yuv4,xf::nv122uyvy,xf::nv122yuyv,xf::nv122nv21,xf::nv212rgb,xf::nv212bgr,xf::nv212uyvy,xf::nv212yuyv,xf::nv212nv12,xf::uyvy2rgb,xf::uyvy2bgr,xf::uyvy2yuyv,xf::yuyv2rgb,xf::yuyv2bgr,xf::yuyv2uyvy,xf::rgb2gray,xf::bgr2gray,xf::gray2rgb,xf::gray2bgr,xf::rgb2xyz,xf::bgr2xyz... | imgproc/xf_cvt_color.hpp |
xf::dilate | imgproc/xf_dilation.hpp |
xf::demosaicing | imgproc/xf_demosaicing.hpp |
xf::erode | imgproc/xf_erosion.hpp |
xf::fast | features/xf_fast.hpp |
xf::GaussianBlur | imgproc/xf_gaussian_filter.hpp |
xf::cornerHarris | features/xf_harris.hpp |
xf::calcHist | imgproc/xf_histogram.hpp |
xf::equalizeHist | imgproc/xf_hist_equalize.hpp |
xf::HOGDescriptor | imgproc/xf_hog_descriptor.hpp |
xf::Houghlines | imgproc/xf_houghlines.hpp |
xf::inRange | imgproc/xf_inrange.hpp |
xf::integralImage | imgproc/xf_integral_image.hpp |
xf::densePyrOpticalFlow | video/xf_pyr_dense_optical_flow.hpp |
xf::DenseNonPyrLKOpticalFlow | video/xf_dense_npyr_optical_flow.hpp |
xf::LUT | imgproc/xf_lut.hpp |
xf::KalmanFilter | video/xf_kalmanfilter.hpp |
xf::magnitude | core/xf_magnitude.hpp |
xf::MeanShift | imgproc/xf_mean_shift.hpp |
xf::meanStdDev | core/xf_mean_stddev.hpp |
xf::medianBlur | imgproc/xf_median_blur.hpp |
xf::minMaxLoc | core/xf_min_max_loc.hpp |
xf::OtsuThreshold | imgproc/xf_otsuthreshold.hpp |
xf::phase | core/xf_phase.hpp |
xf::paintmask | imgproc/xf_paintmask.hpp |
xf::pyrDown | imgproc/xf_pyr_down.hpp |
xf::pyrUp | imgproc/xf_pyr_up.hpp |
xf::reduce | imgrpoc/xf_reduce.hpp |
xf::remap | imgproc/xf_remap.hpp |
xf::resize | imgproc/xf_resize.hpp |
xf::scale | imgproc/xf_scale.hpp |
xf::Scharr | imgproc/xf_scharr.hpp |
xf::SemiGlobalBM | imgproc/xf_sgbm.hpp |
xf::Sobel | imgproc/xf_sobel.hpp |
xf::StereoPipeline | imgproc/xf_stereo_pipeline.hpp |
xf::sum | imgproc/xf_sum.hpp |
xf::StereoBM | imgproc/xf_stereoBM.hpp |
xf::SVM | imgproc/xf_svm.hpp |
xf::Threshold | imgproc/xf_threshold.hpp |
xf::warpTransform | imgproc/xf_warp_transform.hpp |
The different ways to use the xfOpenCV library examples are listed below:
Downloading and Using xfOpenCV Libraries from SDx GUI
You can download xfOpenCV directly from SDx GUI. To build a project using the example makefiles on the Linux platform:
- From SDx IDE, click Xilinx and select SDx Libraries.
- Click Download next to
the Xilinx xfOpenCV Library.
The library is downloaded into <home directory>/Xilinx/SDx/2019.1/xfopencv. After the library is downloaded, the entire set of examples in the library are available in the list of templates while creating a new project.Note: The library can be added to any project from the IDE menu options.
- To add a library to a project, from SDx IDE, click Xilinx and select SDx Libraries.
- Select Xilinx xfOpenCV Library and click Add to project. The dropdown menu consists of options of which project the libraries need to be included to.
All the headers as part of the include/ folder in xfOpenCV library would be copied into the local project directory as <project_dir>/libs/xfopencv/include. All the settings required for the libraries to be run are also set when this action is completed.
Building a Project Using the Example Makefiles on Linux
Use the following steps to build a project using the example makefiles on the Linux platform:
- Open a terminal.
- When building for revision platform, set the environment variable SYSROOT to <the path to platform folder>/sw/a53_linux/a53_linux/sysroot/aarch64-xilinx-linux.
- Change the platform variable to point to the downloaded platform folder in makefile. Ensure that the folder name of the downloaded platform is unchanged.
- When building for revision platform , change IDIRS and LDIRS variables in the
Makefile as
follows:
IDIRS = -I. -I${SYSROOT}/usr/include -I ../../include LDIRS = --sysroot=${SYSROOT} -L=/lib -L=/usr/lib -Wl,-rpath-link=${SYSROOT}/lib,-rpath-link=${SYSROOT}/usr/lib
- Change the directory to the location where you want to build the
example.
cd <path to example>
- When building for revision platform , add
#include"opencv2/imgcodecs/imgcodecs.hpp"
in xf_headers.h file ,both in if and else part. - Set the environment variables to run SDx development
environment.
- For c
shell:
source <SDx tools install path>/settings.csh
- For bash
shell:
source <SDx tools install path>/settings.sh
- For c
shell:
- Type the
make
command in the terminal. The sd_card folder is created and can be found in the <path to example> folder.
Using reVISION Samples on the reVISION Platform
Use the following steps to run a unit test for bilateral filter on zcu104_rv_ss:
- Launch the SDx development environment using the desktop icon
or the Start menu.
The Workspace Launcher dialog appears.
- Click Browse to enter a
workspace folder used to store your projects (you can use workspace folders to
organize your work), then click OK to
dismiss the Workspace Launcher
dialog.Note: Before launching the SDx IDE on Linux, ensure that you use the same shell that you have used to set the
$SYSROOT
environment variable. This is usually the file path to the Linux root file system.The SDx development environment window opens with the Welcome tab visible when you create a new workspace. The Welcome tab can be closed by clicking the X icon or minimized if you do not wish to use it.
- Select
The New Project dialog box opens.
from the SDx development environment menu bar. - Specify the name of the project. For example Bilateral.
- Click Next.
The the Choose Hardware Platform page appears.
- From the Choose Hardware Platform page, click the Add Custom Platform button.
- Browse to the directory where you extracted the reVISION platform files. Ensure that you select the zcu104_rv_ss folder.
- From the Choose Hardware Platform page, select zcu104_rv_ss (custom).
- Click Next.
The Templates page appears, containing source code examples for the selected platform.
- From the list of application templates, select bilateral - File I/O and click Finish.
- add
#include"opencv2/imgcodecs/imgcodecs.hpp"
in xf_headers.h file present under project/src/examples/bilateral/,both in if and else part. - Click the Active build
configurations drop-down from the SDx
Project Settings window, to select the active configuration or
create a build configuration.
The standard build configurations are Debug and Release. To get the best runtime performance, switch to use the Release build configuration as it uses a higher compiler optimization setting than the Debug build configuration.
- Set the Data motion network clock frequency (MHz) to the required frequency, on the SDx Project Settings page.
- Right-click the project and select Build Project or press Ctrl+B keys to build the project, in the Project Explorer view.
- Copy the contents of the newly created sd_card folder to the SD card. The sd_card folder contains all the files required to
run designs on the
ZCU104
board. - Insert the SD card in the
ZCU104
board card slot and switch it ON.Note: A serial port emulator (Teraterm/ minicom) is required to interface the user commands to the board. - Upon successful boot, run the following command in the Teraterm
terminal (serial port
emulator.)
#cd /media/card #remount
- Run the .elf file for the
respective functions.
For more information, see the Using the xfOpenCV Library Functions on Hardware.
Using the xfOpenCV Library on a non-reVISION Platform
This section describes using the xfOpenCV library on a non-reVISION platform, in the SDx™ development environment. The examples in xfOpenCV require OpenCV libraries for successful compilation. As non-reVISION platform may or may not contain opencv libs, as a perquisites it is required to install/compile opencv libraries(with compatible libjpeg.so).
Use the following steps to import the xfOpenCV library into a SDx project and execute it on a custom platform:
-
Launch the SDx development environment using the desktop icon or the Start menu.
The Workspace Launcher dialog appears.
-
Click Browse to enter a workspace folder used to store your projects (you can use workspace folders to organize your work), then click OK to dismiss the Workspace Launcher dialog.
The SDx development environment window opens with the Welcome tab visible when you create a new workspace. The Welcome tab can be closed by clicking the X icon or minimized if you do not wish to use it.
-
Select SDx development environment menu bar.
from theThe New Project dialog box opens.
- Specify the name of the project. For example Test.
-
Click Next.
The the Choose Hardware Platform page appears.
- From the Choose Hardware Platform page, select a suitable platform. For example, zcu102.
-
Click Next.
The Choose Software Platform and Target CPU page appears.
- From the Choose Software Platform and Target CPU page, select an appropriate software platform and the target CPU. For example, select A9 from the CPU dropdown list for ZC702 and ZC706 reVISION platforms.
- Click Next. The Templates page appears, containing source code examples for the selected platform.
-
From the list of application templates, select Empty Application and click Finish.
The New Project dialog box closes. A new project with the specified configuration is created. The SDx Project Settings view appears. Notice the progress bar in the lower right border of the view, Wait for a few moments for the C/C++ Indexer to finish.
-
The standard build configurations are Debug and Release. To get the best run-time performance, switch to use the Release build configuration as it uses a higher compiler optimization setting than the Debug build configuration.
- Set the Data motion network clock frequency (MHz) to the required frequency, on the SDx Project Settings page.
- Select the Generate bitstream and Generate SD card image check boxes.
- Right-click on the newly created project in the Project Explorer view.
-
From the context menu that appears, select C/C++ Build Settings.
The Properties for <project> dialog box appears.
- Click the Tool Settings tab.
- Expand the tree.
-
Click the icon to add the "<xfopencv_location>\include" and "<OpenCV_location>\include" folder locations to the Include Paths list.
Note: The OpenCV library is not provided by Xilinx for custom platforms. You are required to provide the library. Use the reVISION platform in order to use the OpenCV library provided by Xilinx. - In the same page, under , specify "-hls-target 1" in the Software Platform Inferred Flags.
- Click Apply.
- Expand the tree.
- Click the icon and add the following libraries to the
Libraries(-l) list. These libraries
are required by OpenCV.
- opencv_core
- opencv_imgproc
- opencv_imgcodecs
- opencv_features2d
- opencv_calib3d
- opencv_flann
- opencv_video
- opencv_videoio
-
Click the icon and add <opencv_Location>/lib folder location to the Libraries search path (-L) list.
Note: The OpenCV library is not provided by Xilinx for custom platforms. You are required to provide the library. Use the reVISION platform in order to use the OpenCV library provided by Xilinx. - Click Apply to save the configuration.
- Click OK to close the Properties for <project> dialog box.
- Expand the newly created project tree in the Project Explorer view.
- Right-click the src folder and select Import. The Import dialog box appears.
- Select File System and click Next.
- Click Browse to navigate to the <xfopencv_Location>/examples folder location.
-
Select the folder that corresponds to the library that you desire to import. For example, accumulate.
- Right-click the library function in the Project Explorer view and select Toggle HW/SW to move the function to the hardware.
-
Right-click the project and select Build Project or press Ctrl+B keys to build the project, in the Project Explorer view.
The build process may take anytime between few minutes to several hours, depending on the power of the host machine and the complexity of the design. By far, the most time is spent processing the routines that have been tagged for realization in hardware.
- Copy the contents of the newly created .\<workspace>\<function>\Release\sd_card folder to the SD card. The sd_card folder contains all the files required to run designs on a board.
-
Insert the SD card in the board card slot and switch it ON.
Note: A serial port emulator (Teraterm/ minicom) is required to interface the user commands to the board. - Upon successful boot, navigate to the ./mnt folder and run the following command at
the prompt:
#cd /mnt
Note: It is assumed that the OpenCV libraries are a port of the root filesystem. If not, add the location of OpenCV libraries toLD_LIBRARY_PATH
using the$ export LD_LIBRARY_PATH=<location of OpenCV libraries>/lib
command. - Run the .elf executable file. For more information, see the Using the xfOpenCV Library Functions on Hardware.
Changing the Hardware Kernel Configuration
- Update the <path to xfOpenCV git folder>/xfOpenCV/examples/<function>/xf_config_params.h file.
- Update the makefile along with the xf_config_params.h file:
- Find the line with the function name in the makefile. For bilateral
filter, the line in the makefile will be
xf::BilateralFilter<3,1,0,1080,1920,1>
. - Update the template parameters in the makefile to reflect changes made in the xf_config_params.h file. For more details, see the xfOpenCV Library API Reference.
- Find the line with the function name in the makefile. For bilateral
filter, the line in the makefile will be
Using the xfOpenCV Library Functions on Hardware
The following table lists the xfOpenCV library functions and the command to run the respective examples on hardware. It is assumed that your design is completely built and the board has booted up correctly.
Example | Function Name | Usage on Hardware |
---|---|---|
accumulate | xf::accumulate | ./<executable name>.elf <path to input image 1> <path to input image 2> |
accumulatesquared | xf::accumulateSquare | ./<executable name>.elf <path to input image 1> <path to input image 2> |
accumulateweighted | xf::accumulateWeighted | ./<executable name>.elf <path to input image 1> <path to input image 2> |
addS | xf::addS | ./<executable name>.elf <path to input image> |
arithm | xf::absdiff, xf::add, xf::subtract, xf::bitwise_and, xf::bitwise_or, xf::bitwise_not, xf::bitwise_xor | ./<executable name>.elf <path to input image 1> <path to input image 2> |
addweighted | xf::addWeighted | ./<executable name>.elf <path to input image 1> <path to input image 2> |
Bilateralfilter | xf::bilateralFilter | ./<executable name>.elf <path to input image> |
Boxfilter | xf::boxFilter | ./<executable name>.elf <path to input image> |
Boundingbox | xf::boundingbox | ./<executable name>.elf <path to input image> <No of ROI's> |
Canny | xf::Canny | ./<executable name>.elf <path to input image> |
channelcombine | xf::merge | ./<executable name>.elf <path to input image 1> <path to input image 2> <path to input image 3> <path to input image 4> |
Channelextract | xf::extractChannel | ./<executable name>.elf <path to input image> |
Colordetect | xf::bgr2hsv, xf::colorthresholding, xf:: erode, and xf:: dilate | ./<executable name>.elf <path to input image> |
compare | xf::compare | ./<executable name>.elf <path to input image 1> <path to input image 2> |
compareS | xf::compareS | ./<executable name>.elf <path to input image> |
Convertbitdepth | xf::convertTo | ./<executable name>.elf <path to input image> |
Cornertracker | xf::cornerTracker | ./exe <input video> <no. of frames> <Harris Threshold> <No. of frames after which Harris Corners are Reset> |
crop | xf::crop | ./<executable name>.elf <path to input image> |
Customconv | xf::filter2D | ./<executable name>.elf <path to input image> |
cvtcolor IYUV2NV12 | xf::iyuv2nv12 | ./<executable name>.elf <path to input image 1> <path to input image 2> <path to input image 3> |
cvtcolor IYUV2RGBA | xf::iyuv2rgba | ./<executable name>.elf <path to input image 1> <path to input image 2> <path to input image 3> |
cvtcolor IYUV2YUV4 | xf::iyuv2yuv4 | ./<executable name>.elf <path to input image 1> <path to input image 2> <path to input image 3> <path to input image 4> <path to input image 5> <path to input image 6> |
cvtcolor NV122IYUV | xf::nv122iyuv | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor NV122RGBA | xf::nv122rgba | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor NV122YUV4 | xf::nv122yuv4 | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor NV212IYUV | xf::nv212iyuv | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor NV212RGBA | xf::nv212rgba | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor NV212YUV4 | xf::nv212yuv4 | ./<executable name>.elf <path to input image 1> <path to input image 2> |
cvtcolor RGBA2YUV4 | xf::rgba2yuv4 | ./<executable name>.elf <path to input image> |
cvtcolor RGBA2IYUV | xf::rgba2iyuv | ./<executable name>.elf <path to input image> |
cvtcolor RGBA2NV12 | xf::rgba2nv12 | ./<executable name>.elf <path to input image> |
cvtcolor RGBA2NV21 | xf::rgba2nv21 | ./<executable name>.elf <path to input image> |
cvtcolor UYVY2IYUV | xf::uyvy2iyuv | ./<executable name>.elf <path to input image> |
cvtcolor UYVY2NV12 | xf::uyvy2nv12 | ./<executable name>.elf <path to input image> |
cvtcolor UYVY2RGBA | xf::uyvy2rgba | ./<executable name>.elf <path to input image> |
cvtcolor YUYV2IYUV | xf::yuyv2iyuv | ./<executable name>.elf <path to input image> |
cvtcolor YUYV2NV12 | xf::yuyv2nv12 | ./<executable name>.elf <path to input image> |
cvtcolor YUYV2RGBA | xf::yuyv2rgba | ./<executable name>.elf <path to input image> |
Demosaicing | xf::demosaicing | ./<executable name>.elf <path to input image> |
Difference of Gaussian | xf:: GaussianBlur, xf:: duplicateMat, xf:: delayMat, and xf::subtract | ./<exe-name>.elf <path to input image> |
Dilation | xf::dilate | ./<executable name>.elf <path to input image> |
Erosion | xf::erode | ./<executable name>.elf <path to input image> |
Fast | xf::fast | ./<executable name>.elf <path to input image> |
Gaussianfilter | xf::GaussianBlur | ./<executable name>.elf <path to input image> |
Harris | xf::cornerHarris | ./<executable name>.elf <path to input image> |
Histogram | xf::calcHist | ./<executable name>.elf <path to input image> |
Histequialize | xf::equalizeHist | ./<executable name>.elf <path to input image> |
Hog | xf::HOGDescriptor | ./<executable name>.elf <path to input image> |
Houghlines | xf::HoughLines | ./<executable name>.elf <path to input image> |
inRange | xf::inRange | ./<executable name>.elf <path to input image> |
Integralimg | xf::integralImage | ./<executable name>.elf <path to input image> |
Lkdensepyrof | xf::densePyrOpticalFlow | ./<executable name>.elf <path to input image 1> <path to input image 2> |
Lknpyroflow | xf::DenseNonPyrLKOpticalFlow | ./<executable name>.elf <path to input image 1> <path to input image 2> |
Lut | xf::LUT | ./<executable name>.elf <path to input image> |
Kalman Filter | xf::KalmanFilter | ./<executable name>.elf |
Magnitude | xf::magnitude | ./<executable name>.elf <path to input image> |
Max | xf::Max | ./<executable name>.elf <path to input image 1> <path to input image 2> |
MaxS | xf::MaxS | ./<executable name>.elf <path to input image> |
meanshifttracking | xf::MeanShift | ./<executable name>.elf <path to input video/input image files> <Number of objects to track> |
meanstddev | xf::meanStdDev | ./<executable name>.elf <path to input image> |
medianblur | xf::medianBlur | ./<executable name>.elf <path to input image> |
Min | xf::Min | ./<executable name>.elf <path to input image 1> <path to input image 2> |
MinS | xf::MinS | ./<executable name>.elf <path to input image> |
Minmaxloc | xf::minMaxLoc | ./<executable name>.elf <path to input image> |
otsuthreshold | xf::OtsuThreshold | ./<executable name>.elf <path to input image> |
paintmask | xf::paintmask | ./<executable name>.elf <path to input image> |
Phase | xf::phase | ./<executable name>.elf <path to input image> |
Pyrdown | xf::pyrDown | ./<executable name>.elf <path to input image> |
Pyrup | xf::pyrUp | ./<executable name>.elf <path to input image> |
reduce | xf::reduce | ./<executable name>.elf <path to input image> |
remap | xf::remap | ./<executable name>.elf <path to input image> <path to mapx data> <path to mapy data> |
Resize | xf::resize | ./<executable name>.elf <path to input image> |
scale | xf::scale | ./<executable name>.elf <path to input image> |
scharrfilter | xf::Scharr | ./<executable name>.elf <path to input image> |
set | xf::set | ./<executable name>.elf <path to input image> |
SemiGlobalBM | xf::SemiGlobalBM | ./<executable name>.elf <path to left image> <path to right image> |
sobelfilter | xf::Sobel | ./<executable name>.elf <path to input image> |
stereopipeline | xf::StereoPipeline | ./<executable name>.elf <path to left image> <path to right image> |
stereolbm | xf::StereoBM | ./<executable name>.elf <path to left image> <path to right image> |
subRS | xf::SubRS | ./<executable name>.elf <path to input image> |
subS | xf::SubS | ./<executable name>.elf <path to input image> |
sum | xf::sum | ./<executable name>.elf <path to input image 1> <path to input image 2> |
Svm | xf::SVM | ./<executable name>.elf |
threshold | xf::Threshold | ./<executable name>.elf <path to input image> |
warptransform | xf::warpTransform | ./<executable name>.elf <path to input image> |
zero | xf::zero | ./<executable name>.elf <path to input image> |