OpenCV Bad performance Android

Hi,

I am working on an Android app that uses opencv 4.6.0 compiled like so and it is 100 to 150x slower on most cv2 calls compared to opencv-python on Windows. I expect the performance difference to be 3-4x, which is also what I see when testing with numpy.

For example the below on a 1920x1080 image takes 600ms on a snapdragon 820 and is done in 5ms on i7-8650U. While according to most benchmarks these CPUs differ only about 3-4x in performance.

blur = cv2.GaussianBlur(image, (5, 5), 0)

If I run the same functions on both platforms with numpy I only see a roughly 3x performance degradation

What causes this huge performance penality and how can we improve it?

what does print(cv2.getBuildInformation()) report ?

(ARM/NEON optimizations ?)

Here we go:

General configuration for OpenCV 4.6.0 =====================================
  Version control:               68b7b68-dirty
  Platform:
    Timestamp:                   2022-11-02T10:15:43Z
    Host:                        Linux 5.10.16.3-microsoft-standard-WSL2 x86_64
    Target:                      Android 1 aarch64
    CMake:                       3.16.3
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release
  CPU/HW features:
    Baseline:                    NEON FP16
  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /home/user/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  (ver 12.0.8)
    C++ flags (Release):         -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security     -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG   -DNDEBUG
    C++ flags (Debug):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security     -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fno-limit-debug-info   -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /home/user/.buildozer/android/platform/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
    C flags (Release):           -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security    -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG   -DNDEBUG
    C flags (Debug):             -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security    -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fno-limit-debug-info   -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -L/home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/android-build -lpython3.9  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
    Linker flags (Debug):        -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -L/home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/android-build -lpython3.9  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m log
    3rdparty dependencies:
  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
    Disabled:                    java java_bindings_generator world
    Disabled by dependency:      -
    Unavailable:                 python2 ts
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO
  Android NDK:                   /home/user/.buildozer/android/platform/android-ndk-r23b (ver 23.1.7779620)
    Android ABI:                 arm64-v8a
    NDK toolchain:               standalone: /home/user/.buildozer/android/platform/android-ndk-r23b
    STL type:                    c++_static
    Native API level:            21
  Android SDK:                   /home/user/.buildozer/android/platform/android-sdk (tools: 6514223 build tools: 33.0.0)
    android tool:                /home/user/.buildozer/android/platform/android-sdk/tools/android
  GUI:                           NONE
  Media I/O:
    ZLib:                        z (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES
  Video I/O:
  Parallel framework:            pthreads
  Trace:                         YES (with Intel ITT)
  Other third-party libraries:
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.19.1)
  Python 3:
    Interpreter:                 /home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 (ver 3.9.9)
    Libraries:                   /home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/android-build/libpython3.9.so
    numpy:                       /home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/python-installs/movingcarrecognizer/arm64-v8a/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
    install path:                /home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/python-installs/movingcarrecognizer/arm64-v8a
  Python (for build):            /home/user/mcr/mcr_app/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3
  Java:
    ant:                         NO
    Java wrappers:               NO
    Java tests:                  NO