Saturday, 6 August 2022

How to include only OpenCV Android library that I need?

I am trying to use OpenCV library for my Android app (OpenCV 4.6.0). But the size of my app is really big after I added the library. I want to only include the part of the library that I use, which is imgproc and core (specifically Sobel edge detection). I have tried to edit the CMakeLists.txt (which is located on libcxx_helper) to this:

cmake_minimum_required(VERSION 3.6)

# dummy target to bring libc++_shared.so into packages
add_library(opencv_jni_shared STATIC dummy.cpp)

set(OpenCV_DIR D:/Project/AndroidStudioProject/SobelProject/sdk/native/jni)

find_package(OpenCV REQUIRED core imgproc)
add_executable(opencv_sobel dummy.cpp)
target_link_libraries(opencv_sobel core imgproc ${EXTERNAL_LIBS})

I expect there will be a libopencv_sobel.so generated from the above CMakeLists.txt, but nothing is generated. So, I load the library with this:

init {
    System.loadLibrary('opencv_java4')
}

Then I run the app. But the size of my app is still the same. I am unfamiliar with C++ and NDK.

Any help would be very appreciated.



from How to include only OpenCV Android library that I need?

No comments:

Post a Comment