Qualcomm’s FastCV SDK promises hardware acceleration of computer vision applications, providing a slew of APIs for common signal processing tasks (e.g., filters) without ties to particular hardware.
Personally I’m interested in the behaviour of hardware accelerated software on mobile systems; this makes FastCV seem like an excellent research platform. However, open-source applications that make use of the framework are far in between. Qualcomm ships two demo Android applications: fastcvdemo amd fastcvcorner. Below are the not-so-straightforward steps to build these applications on a Pixel 3 Android 10 (despite the decade old official documentation).
Requirements
This is one of the rare instance where the IDE simplified the build process. Thus we’ll be using Eclipse for Java, ADT and CDT on Linux (Ubuntu 18.04) to build the demo applicaitons. Other OSes are likely to be compatible with the below steps (Windows is the Qualcomm recommended OS).
- JDK 8 (make sure it is not higher than this or else you wont be able to produce a
*.apk
file) - Eclipse for Java
- Android SDK Version 2.2 API Level 8 (install this through Android’s SDK Manager)
- Android DDMS and ADT (these can be installed from inside Eclipse as plugins)
- Refer to the Android ADT section of the Qualcomm installation docs
- Android NDK r6 (higher version may work but was not tested)
- Download NDK r6 Linux
- Other old versions
- Place the Android NDK directory at the same level as the Android SDK directory
- C/C++ Development Toolkit (CDT) (install it through Eclipse again; the latest version works)
- Download the FastCV SDK and install it into the same directory where the Android SDK and NDK are located
The final directory structure should look like (modulo directory names):
$HOME/Android/android-ndk-r6/
$HOME/Android/android-sdk/
$HOME/Android/android-fastcv/
Setup
Environment Variables
Do the following in the same session where you start Eclipse. Or add the lines to your bashrc.
- Add the SDK
platform-tools
andtools
directories to your path:export ANDROID_HOME=$HOME/Android/Sdk export PATH=$ANDROID_HOME/tools:$PATH export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$HOME/Android/android-ndk-r6:$PATH
- Set the
ANDROID_NDK_ROOT
variable:export ANDROID_NDK_ROOT=$HOME/Android/android-ndk-r6
Eclipse
To prevent obscure errors later down the line make sure Eclipse uses JDK 8.
Follow these instructions (essentially just editing eclipse.ini and repointing the installed JREs setting)
You can find the location of your Java installtion using:
update-alternatives --list java
ADT
This step prevents the ADT error on Eclipse startup: Failed to get the required ADT version number from the SDK
This is because Eclipse ADT and Android are both using the same SDK tools. Correct this by creating a new SDK directory for Eclipse eclusively alongside the original SDK. Follow this SO answer to create a new Eclipse Android SDK directory that contains symlinks to all subdirectories of the original Android SDK apart from the tools/
folder (which you have to download separately for version 25.x.x).
You directory should look as follows:
$HOME/Android/android-ndk-r6/
$HOME/Android/android-sdk/
...
tools/
$HOME/Android/android-sdk-eclipse/
<symlinks to android-sdk for all subdirectories except tools/>
$HOME/Android/android-fastcv/
To avoid more errors later follow this SO answer: download build-tools/
version 25.x.x Android Studio’s SDK Manager and remove all other version from the newly created Eclipse Android SDK build-tools/
directory.
IMPORTANT: Point Eclipse to your new Android SDK in Window > Preferences > Android > SDK Location. Make sure you see Android 2.2 API Level 8 in the list of available SDKs.
FastCV SDK
Copy the FastCV headers and static library to the Android NDK.
Note: make sure you don’t copy the library or header anywhere else in the NDK apart from android-8/
to prevent confusing build system errors
mkdir $HOME/Android/android-ndk-r6/platforms/android-8/arch-arm/usr/include/fastcv
cp $HOME/Android/android-fastcv/inc/fastcv.h $HOME/Android/android-ndk-r6/platforms/android-8/arch-arm/usr/include/fastcv/
cp $HOME/Android/android-fastcv/lib/Android/lib32/libfastcv.a $HOME/Android/android-ndk-r6/platforms/android-8/arch-arm/usr/lib
Import and Compile
Qualcomm’s installation instructions are mostly accurate.
- Import the Android project from existing code (pointing Eclipse to the FastCV SDK directory when prompted).
- Change the Android SDK path in Project > Properties > Android to API Level 8 and target Android 2.2 (it will work even on Android 10)
- Disable …abort if fatal errors are found in Window > Preferences > Lint Error Checking
- IMPORTANT: Add a
default.properties
file in the project root and add the single line:target=android-8
(per this obscure thread) - Convert to CDT C++ Project as specified in the Qualcomm docs
- Project > Clean… > Clean
- Project > Build All
Install applications on device
Contrary to what the Qualcomm docs say, the bin/
directory doesn’t necessarily contain an *.apk
file which you need to transfer the application to your Android device.
- Right click your project
- Select Android Tools > Export Signed Application Package
- Create a keystore with any password in any location (you can reuse this whenever you export another application)
- If you chose
bin/
as your output directory in step 3 then you can install thebin/<demo>.apk
to your connected device by:adb install bin/<demo>.apk
- The applications should be visible and runnable on your phone
loadjpeg
There is a third demo application in the FastCV SDK called loadjpeg. However, it does not work out-of-the-box. Following steps fix the application:
- Add an intent-filter to the
AndroidManifest.xml
:
<intent-filter>
... original intent filters ...
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
- Change all occurences of fastcvsample in
jni/Anroid.mk
to loadjpeg (as suggested here) - Build and install the project
- You might run into permission issues after starting the application (run
adb shell logcat
to see this). In this case make these additions to theLoadJpeg.java