Qualcomm Robotics RB5/RB6 - Building your own Fast CV application

From RidgeRun Developer Connection
Jump to: navigation, search



Index





Building your own FastCV application

To build your own application using FastCV, first you will need to have installed the following, click on the links provided to learn the steps on how to install and configure them:


Adding FastCV to your source code[1]

FastCV is a C library that has two components, the first is a library of computer vision functions which is meant for running in ARM processors and the second, a hardware acceleration API that runs only on Qualcomm Snapdragon chipsets, such as the one in the Robotics RB5/RB6 platform.

1. To use FastCV in your source code you just need to include the fastcv.h header in your source file, as shown below. The header file is located in the <FASTCV_ROOT_DIR>/inc/ directory, where FASTCV_ROOT_DIR is the directory where you installed FastCV:

Note
To learn about the FastCV library functions, click on the following link FastCV library
#include "fastcv.h"


2. To take advantage of the library functions that were made for Snapdragon processors, the following APIs should be called to initialize and de-initialize FastCV:

Note
You can find more information about the operation modes of FastCV in <FASTCV_ROOT_DIR>/ReleaseNotes.pdf file in the FastCV directory.

Initialization

Add this API function before implementing the FastCV algorithms:

int fcvSetOperationMode(fcvOperationMode mode)

It sets the mode of operation, the 4 modes are:

  • FASTCV_OP_LOW_POWER: The QDSP implementation will be used unless the QDSP speed is 3 times slower than CPU speed.
  • FASTCV_OP_PERFORMANCE: The fastest implementation will be used.
  • FASTCV_OP_CPU_OFFLOAD: The QDSP implementation will be used when it’s available, otherwise it will find for GPU and CPU implementation.
  • FASTCV_OP_CPU_PERFORMANCE: The CPU fastest implementation will be used.

De-Initialization

Add this API function as part of the de-initialization of the FastCV implementation, which means it has to be called either at the end of the application when it is done running, or at the end of the part of the application when it is done using the FastCV algorithms:

void fcvCleanUp(void)


Building your application with Hexagon SDK[2]

Note
You can find more information about the build systems in Hexagon SDK in the <HEXAGON_SDK_ROOT_DIR>/docs/index.html file in the Hexagon SDK directory.

Once you have finished writing your application code implementing FastCV and you want to test it in your board, you will need to build it with Hexagon SDK and Linaro toolchain. Hexagon SDK has three make systems which are make.d, cmake and GNU make. We will focus on the make.d framework, for which you will need, in a basic build, the following directory for your application, let's call it myApplication, that you will create inside <HEXAGON_SDK_ROOT_DIR>/examples directory:

mkdir <HEXAGON_SDK_ROOT_DIR>/examples/myApplication
myApplication
├── include
│   └── fastcv.h
├── lib
│   └── libfastcv.a
├── Makefile
├── src
│   └── myApplication.cpp
└── UbuntuARM.min

In the include directory you will have the headers such as fastcv.h. In the lib directory you will need the FastCV static library libfastcv.a which is is located in the <FASTCV_ROOT_DIR>/lib/ directory. The src directory is where you will store your source code.

Makefile

The Makefile is a user-defined file that will contain all the elements necessary to build the application. An example of a basic makefile is:

 1 # Directory paths to be passed to the compiler
 2 INCDIRS += \
 3    include \
 4 
 5 #Error handling if the variant was not passed 
 6 ifndef V
 7 $(error Variant must be provided, pass a variant by adding 'V=<desired variant>' to your build command)
 8 endif
 9 
10 #Extracting the variant target
11 V_TARGET = $(word 1,$(subst _, ,$(V)))
12 
13 #Define the variants supported by the application
14 SUPPORTED_VS = $(default_VS)
15 
16 #Files required for the make.d framework
17 include $(HEXAGON_SDK_ROOT)/build/make.d/$(V_TARGET)_vs.min
18 include $(HEXAGON_SDK_ROOT)/build/defines.min
19 
20 #User-generated file specifying sources and dependencies to build the executable
21 include $(V_TARGET).min
22 
23 # File required for the make.d framework, always include the rules.min file last
24 include $(RULES_MIN)

The V_TARGET variable in line 11 of the Makefile, is the build target variant of the application, in the case for the Robotics RB5/RB6 it's an Ubuntu platform, so its value is UbuntuARM.

UbuntuARM.min

The file UbuntuARM.min included in line 21 of the Makefile, contains sources and dependencies to build the executable:

 1 #Name of the executable
 2 BUILD_EXES+=myApplication
 3 #Path to source files
 4 myApplication_CPP_SRCS += src/myApplication
 5 #Path to libraries
 6 myApplication_LIBS += lib/libfastcv
 7 #Linker flags
 8 myApplication_LD_FLAGS += -lpthread -lc -ldl 
 9 
10 # copy the resulting files to the output directory
11 BUILD_COPIES = \
12    $(DLLS) \
13    $(EXES) \
14    $(LIBS) \
15    $(SHIP_DIR)/ ;

Environment setup and make command

1. To setup the environment for the build follow the Step 3 from this link.
2. Change to the directory of your application, for example:

cd examples/myApplication

2. Run the following command to build the executable:

Note
Notice that the first part, before the underscore, of the V= variable must be the build target variant.
make tree V=UbuntuARM_myApplication

When the build process is finished the output files such as shared libraries and the executable will be saved to an output directory that will be named like the 'V=' variable you pass to the make command when building the application. Inside the output directory will be another one called ship which will contain the executable, for example, UbuntuARM_myApplication/ship/myApplication.

Running your application

1. To copy the binary file to the Qualcomm Robotics RB5/RB6 and run it, you can do it either via ADB or SSH. Click on ADB_GUIDE to learn how to connect via ADB or click on SSH_GUIDE to learn how to connect via SSH. In this guide we will show the two ways.

Copy and execute your application

1. Run the following command to copy the executable, remember to only use one of the alternatives, either ADB or SSH:

With ADB:

adb push <HEXAGON_SDK_ROOT_DIR>/examples/myApplication/UbuntuARM_myApplication/ship/myApplication /usr/bin

With SSH:

scp <HEXAGON_SDK_ROOT_DIR>/examples/myApplication/UbuntuARM_myApplication/ship/myApplication root@<RB5_IP_ADDRESS>:/usr/bin

2. Run the following command to access the board:

With ADB, your terminal will start with a # which means you are now inside the board's filesystem:

adb shell

With SSH:

ssh root@<RB5_IP_ADDRESS>

3. Run the following commands to give the app execution permissions and to execute the application:

Note
These commands are executed in the board.
chmod 777 /usr/bin/myApplication
/usr/bin/myApplication

References

  1. Qualcomm Technologies Inc. FastCV SDK Release Notes. Version 1.7.1. June 2019
  2. Qualcomm Technologies Inc. Hexagon SDK - Build resources. 2020


Index