Opencv-dnn's erformance declined significantly on Android with JNI

asked 2019-01-09 21:17:58 -0500

updated 2019-01-10 01:54:21 -0500

berak gravatar image

My OpenCV-dnn shared lib program running in an Android APP through JNI is 2x slower than the original standalone executable binary. Its CPU usage is halved. BTW, the aarch is armv8a here.

.so lib and binary share same code and compiling options. So I guess some openmp features used by opencv dnn are restricted in Android APP.

The code is too long and quite irrelevant here. Just something like this.

code in common parts:

void detect() { 
    while (true) { 
    Image img = GetImageFromV4l();
    /* do opencv dnn forwarding */


std::thread thr;
JNICALL Java_blabla_Detect() {
  // preprocessing, loading models, etc
  thr = std::thread(std::bind(detect));


int main() {
   // preprocessing, loading models, etc
  return 0;

Opencv compiling flags:

-isystem /data/build/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O2 -DNDEBUG   -DNDEBUG

shared libs packaged with APK

And I did try to add -fopenmp flag, but that didn't help.

The following is the shared libs packaged with my APK. Did I miss something important for opencv/openmp?                 
edit retag flag offensive close merge delete