Qualcomm Robotics RB5/RB6 - Building your own Fast CV application
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:
#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:
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]
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:
# Directory paths to be passed to the compiler INCDIRS += \ include \ #Error handling if the variant was not passed ifndef V $(error Variant must be provided, pass a variant by adding 'V=<desired variant>' to your build command) endif #Extracting the variant target V_TARGET = $(word 1,$(subst _, ,$(V))) #Define the variants supported by the application SUPPORTED_VS = $(default_VS) #Files required for the make.d framework include $(HEXAGON_SDK_ROOT)/build/make.d/$(V_TARGET)_vs.min include $(HEXAGON_SDK_ROOT)/build/defines.min #User-generated file specifying sources and dependencies to build the executable include $(V_TARGET).min # File required for the make.d framework, always include the rules.min file last 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:
#Name of the executable BUILD_EXES+=myApplication #Path to source files myApplication_CPP_SRCS += src/myApplication #Path to libraries myApplication_LIBS += lib/libfastcv #Linker flags myApplication_LD_FLAGS += -lpthread -lc -ldl # copy the resulting files to the output directory BUILD_COPIES = \ $(DLLS) \ $(EXES) \ $(LIBS) \ $(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
3. Run the following command to build the executable:
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:
chmod 777 /usr/bin/myApplication /usr/bin/myApplication
References