The program using the opencv lib which I build from source runs slower than that using libopencv_java4.so

I got opencv android sdk and opencv source code from [opencv releases], and get libopencv_java4.so from sdk, and build opencv lib from source code using command below (use android ndk):

cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_shared -DBUILD_SHARED_LIBS=ON -DANDROID_ABI=arm64-v8a -DINSTALL_ANDROID_EXAMPLES=OFF -DANDROID_EXAMPLES_WITH_LIBS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DWITH_OPENCL=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DENABLE_CXX11=ON -DANDROID_SDK_TARGET=23 -DANDROID_NATIVE_API_LEVEL=23 -DANDROID_SDK=${ANDROID_SDK} -DANDROID_NDK=${ANDROID_NDK} -DBUILD_ANDROID_PROJECTS=OFF ../opencv-4.5.4

sum up, I have two libs, one of them is libopencv_java.so from opencv_android_sdk(let’s name it as lib1), another one is a couple of libopencv_*.so which built from source code(let’s name it as lib2) .

in addition, I build opencv from source code because I want to enable opencl.

in my project, I use cv::UMat to implement may algorithm, when I switch lib1 to lib2, I found my program become much more slower.
So, my question is there are any difference between lib1 and lib2?

I’m not native English speaker, I apologize if my description is confusing and please let me know, I will explain more.

After few days research, I found that the problem is that TBB is not enabled in lib2, lib2 take pthreads as it’s Parallel framework and pthreads is slower than TBB( I don’t know why! ), I add the option “-DWITH-TBB=ON” into cmake options, finally, lib2 works as well as lib1.
In addition, I use the cmake command below:

cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_static -DBUILD_SHARED_LIBS=OFF -DANDROID_ABI="arm64-v8a"  -DINSTALL_ANDROID_EXAMPLES=OFF -DANDROID_EXAMPLES_WITH_LIBS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DWITH_OPENCL=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DENABLE_CXX11=ON -DANDROID_SDK_TARGET=23 -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_SDK=${ANDROID_SDK} -DANDROID_NDK=${ANDROID_NDK} -DBUILD_ANDROID_EXAMPLES=OFF -DANDROID_PROJECTS_BUILD_TYPE=GRADLE -DBUILD_ANDROID_PROJECTS=OFF  -DBUILD_opencv_java=ON -DANT_EXECUTABLE=/root/ant/apache-ant-1.10.12/bin/ant.bat ../opencv-4.5.4
2 Likes