Android library does not include Stitcher?

Hi,
I tried to use the Stitcher in an Android project with the libraries built from the sources using the command below. But the library does not contain the Stitcher (no stitcher class or method in the java sources). Any idea if I’m missing a build flag or what I can do to get the Stitcher included in the java interface?

cmake \
    -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
    -DANDROID_ABI=$ABI  \
    -DANDROID_NATIVE_API_LEVEL=$ANDROID_PLATFORM \
    -DANDROID_COMPILE_SDK_VERSION:STRING=$ANDROID_PLATFORM \
    -DANDROID_TARGET_SDK_VERSION:STRING=$ANDROID_PLATFORM \
    -GNinja \
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
    -DCMAKE_BUILD_TYPE:STRING=Release \
    -DBUILD_TESTS=FALSE -DBUILD_PERF_TESTS=FALSE \
    -DBUILD_ANDROID_EXAMPLES=FALSE \
    -DCMAKE_CONFIGURATION_TYPES:STRING=Release \
    -DBUILD_opencv_highgui:BOOL=OFF \
    -DBUILD_opencv_js_bindings_generator:BOOL=OFF \
    -DBUILD_opencv_objc_bindings_generator:BOOL=OFF \
    -DINSTALL_CREATE_DISTRIB=ON \
    -DBUILD_DOCS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=ON -DWITH_IPP=OFF -DWITH_MSMF=OFF \
    -DWITH_OPENEXR:BOL=OFF -DBUILD_OPENEXR:BOOL=OFF \
    -DWITH_PROTOBUF:BOOL=OFF \
    -DCMAKE_CXX_FLAGS_MINSIZEREL:STRING="-Oz -DNDEBUG" \
    -DCMAKE_C_FLAGS_MINSIZEREL:STRING="-Oz -DNDEBUG" \
    -DENABLE_BUILD_HARDENING:BOOL=ON \
    -DENABLE_THIN_LTO:BOOL=ON \
../opencv

its not your fault.
weird as it is, noone yet cared to add java wrappings for this module.

if you want to try, add java a the end of this line:

so it says:

WRAP python java)

(then rerun cmake and all …)

1 Like
1 Like

Thanks for the quick response. Sadly opencv fails the build process when I add the java bindings. There are 4 lines with errors, the last 3 lines I was able to fix by introducing local variables and casting the java types (e.g. jdouble) to c++ type (e.g. double) before passing it to the function.
But the first error where it says call to non-static member function without an object argument in the expression(*(cv::detail::MatchesInfo*)matches_info_nativeObj) ) I don’t understand.
It just casts the matches_info_nativeObj to a pointer to a MatchesInfo pointer, right? (sorry, my C++ is a bit rusty) Why does it complain about an object argument?

[1118/1120] Building CXX object modules/java/jni/CMakeFiles/opencv_java.dir/__/generator/src/cpp/opencv_java.cpp.o
FAILED: modules/java/jni/CMakeFiles/opencv_java.dir/__/generator/src/cpp/opencv_java.cpp.o 
/opt/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi30 --gcc-toolchain=/opt/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/opt/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -DCVAPI_EXPORTS -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/root/opencv/modules/core/misc/java/src/cpp -I/root/opencv/modules/imgproc/misc/java/src/cpp -I/root/opencv/modules/ml/misc/java/src/cpp -I/root/opencv_contrib/modules/phase_unwrapping/misc/java/src/cpp -I/root/opencv/modules/photo/misc/java/src/cpp -I/root/opencv_contrib/modules/plot/misc/java/src/cpp -I/root/opencv_contrib/modules/xphoto/misc/java/src/cpp -I/root/opencv_contrib/modules/bioinspired/misc/java/src/cpp -I/root/opencv/modules/features2d/misc/java/src/cpp -I/root/opencv_contrib/modules/img_hash/misc/java/src/cpp -I/root/opencv/modules/imgcodecs/misc/java/src/cpp -I/root/opencv/modules/videoio/misc/java/src/cpp -I/root/opencv/modules/calib3d/misc/java/src/cpp -I/root/opencv/modules/objdetect/misc/java/src/cpp -I/root/opencv_contrib/modules/structured_light/misc/java/src/cpp -I/root/opencv/modules/video/misc/java/src/cpp -I/root/opencv_contrib/modules/xfeatures2d/misc/java/src/cpp -I/root/opencv_contrib/modules/ximgproc/misc/java/src/cpp -I/root/opencv_contrib/modules/aruco/misc/java/src/cpp -I/root/opencv_contrib/modules/bgsegm/misc/java/src/cpp -I/root/opencv_contrib/modules/face/misc/java/src/cpp -I/root/opencv/modules/stitching/misc/java/src/cpp -I/root/opencv_contrib/modules/tracking/misc/java/src/cpp -I/root/opencv/modules/java/generator/src/cpp -Imodules/java_bindings_generator/gen/cpp -I/root/opencv/modules/core/include -I/root/opencv/modules/flann/include -I/root/opencv/modules/imgproc/include -I/root/opencv/modules/ml/include -I/root/opencv_contrib/modules/phase_unwrapping/include -I/root/opencv/modules/photo/include -I/root/opencv_contrib/modules/plot/include -I/root/opencv_contrib/modules/xphoto/include -I/root/opencv_contrib/modules/bioinspired/include -I/root/opencv/modules/features2d/include -I/root/opencv_contrib/modules/img_hash/include -I/root/opencv/modules/imgcodecs/include -I/root/opencv/modules/videoio/include -I/root/opencv/modules/calib3d/include -I/root/opencv_contrib/modules/datasets/include -I/root/opencv/modules/objdetect/include -I/root/opencv_contrib/modules/shape/include -I/root/opencv_contrib/modules/structured_light/include -I/root/opencv/modules/video/include -I/root/opencv_contrib/modules/xfeatures2d/include -I/root/opencv_contrib/modules/ximgproc/include -I/root/opencv_contrib/modules/aruco/include -I/root/opencv_contrib/modules/bgsegm/include -I/root/opencv_contrib/modules/face/include -I/root/opencv/modules/stitching/include -I/root/opencv_contrib/modules/tracking/include -isystem . -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security     -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 -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments  -fvisibility=hidden -fvisibility-inlines-hidden -fstack-protector-strong -fPIC  -Wno-deprecated-declarations -Oz -DNDEBUG   -DNDEBUG -D_FORTIFY_SOURCE=2 -fPIC   -std=c++11 -MD -MT modules/java/jni/CMakeFiles/opencv_java.dir/__/generator/src/cpp/opencv_java.cpp.o -MF modules/java/jni/CMakeFiles/opencv_java.dir/__/generator/src/cpp/opencv_java.cpp.o.d -o modules/java/jni/CMakeFiles/opencv_java.dir/__/generator/src/cpp/opencv_java.cpp.o -c /root/opencv/modules/java/generator/src/cpp/opencv_java.cpp
In file included from /root/opencv/modules/java/generator/src/cpp/opencv_java.cpp:8:
In file included from modules/java_bindings_generator/gen/cpp/opencv_jni.hpp:22:
/root/build/modules/java_bindings_generator/gen/cpp/stitching.inl.hpp:851:38: error: call to non-static member function without an object argument
        cv::detail::FeaturesMatcher::operator ()( (*(cv::detail::ImageFeatures*)features1_nativeObj), (*(cv::detail::ImageFeatures*)features2_nativeObj), (*(cv::detail::MatchesInfo*)matches_info_nativeObj) );
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/root/build/modules/java_bindings_generator/gen/cpp/stitching.inl.hpp:875:46: error: non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'
        cv::detail::focalsFromHomography( H, (double)f0, (double)f1, (bool)f0_ok, (bool)f1_ok );
                                             ^~~~~~~~~~
/root/opencv/modules/stitching/include/opencv2/stitching/detail/autocalib.hpp:67:62: note: passing argument to parameter 'f0' here
void CV_EXPORTS_W focalsFromHomography(const Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok);
                                                             ^
In file included from /root/opencv/modules/java/generator/src/cpp/opencv_java.cpp:8:
In file included from modules/java_bindings_generator/gen/cpp/opencv_jni.hpp:22:
/root/build/modules/java_bindings_generator/gen/cpp/stitching.inl.hpp:5020:45: error: non-const lvalue reference to type 'float' cannot bind to a temporary of type 'float'
        me->mapForward( (float)x, (float)y, (float)u, (float)v );
                                            ^~~~~~~~
/root/opencv/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp:253:62: note: passing argument to parameter 'u' here
void SphericalProjector::mapForward(float x, float y, float &u, float &v)
                                                             ^
In file included from /root/opencv/modules/java/generator/src/cpp/opencv_java.cpp:8:
In file included from modules/java_bindings_generator/gen/cpp/opencv_jni.hpp:22:
/root/build/modules/java_bindings_generator/gen/cpp/stitching.inl.hpp:5044:46: error: non-const lvalue reference to type 'float' cannot bind to a temporary of type 'float'
        me->mapBackward( (float)u, (float)v, (float)x, (float)y );
                                             ^~~~~~~~
/root/opencv/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp:266:63: note: passing argument to parameter 'x' here
void SphericalProjector::mapBackward(float u, float v, float &x, float &y)
                                                              ^
4 errors generated.
ninja: build stopped: subcommand failed.

Ah, nice, I’ll try this workaround for now. Thanks!

when in doubt, show generated code, e.g. from:

This is the function which fails with call to non-static member function without an object argument

//
//  void cv::detail::FeaturesMatcher::operator ()(ImageFeatures features1, ImageFeatures features2, MatchesInfo& matches_info)
//

JNIEXPORT void JNICALL Java_org_opencv_stitching_Stitching_apply_10 (JNIEnv*, jclass, jlong, jlong, jlong);

JNIEXPORT void JNICALL Java_org_opencv_stitching_Stitching_apply_10
  (JNIEnv* env, jclass , jlong features1_nativeObj, jlong features2_nativeObj, jlong matches_info_nativeObj)
{
    
    static const char method_name[] = "stitching::apply_10()";
    try {
        LOGD("%s", method_name);
        cv::detail::FeaturesMatcher::operator ()( (*(cv::detail::ImageFeatures*)features1_nativeObj), (*(cv::detail::ImageFeatures*)features2_nativeObj), (*(cv::detail::MatchesInfo*)matches_info_nativeObj) );
    } catch(const std::exception &e) {
        throwJavaException(env, &e, method_name);
    } catch (...) {
        throwJavaException(env, 0, method_name);
    }
}
1 Like