opencv_contrib: Aruco Java - crash

System information (version)
  • OpenCV => 3.2
  • Operating System / Platform => Android/java
Detailed description

I build OpenCV and Aruco module, from Git. Download OpenCV master branch and contrib. copy Aruco folder from contrib to modules folder of opencv and run build script:

cmake \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_NATIVE_API_LEVEL=android-14 \
-DANDROID_SDK=/Users/admin/Library/Android/sdk \
-DANDROID_NDK=/Users/admin/Library/Android/sdk/ndk-bundle \
-DANT_EXECUTABLE=/Users/admin/Documents/apache-ant/bin/ant \
-DJAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home \
-DJAVA_JVM_LIBRARY=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/include/jni.h \
-DJAVA_INCLUDE_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/include \
-DBUILD_FAT_JAVA_LIB=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake $@ ../..

everything went well. i include libraries and generated java classes in Android Studio. OpenCV is working, I tried several functions and it works. But with Aruco something is wrong, it always crash on Aruco.detectMarkers(…)

Generated java code:

public static void detectMarkers(Mat image, Dictionary dictionary, List<Mat> corners, Mat ids)
{
   Mat corners_mat = new Mat();
   detectMarkers_1(image.nativeObj, dictionary.nativeObj, corners_mat.nativeObj, ids.nativeObj);
   Converters.Mat_to_vector_Mat(corners_mat, corners);
   corners_mat.release();
   return;
}

I create my wraper around detectMarkers() almost like generated code and it works but without parameter OutputArrayOfArrays corners and it works. If i add this parameter, my function will look like generated and then i see error:

OpenCV Error: The function/feature is not implemented (Only Mat vector, UMat vector, and vector<vector> OutputArrays are currently supported.) in void cv::aruco::_copyVector2Output(std::vector<std::vector<cv::Point_<float> > >&, cv::OutputArrayOfArrays), file /Users/admin/Downloads/opencv-3.2.0/modules/aruco/src/aruco.cpp, line 595

so my guess is why it is impossible to use the generated code - because bad conversion between java Mat and C++ OutputArrayOfArrays

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Thanks. I rewraped the function by myself, like the following code, and it works.

extern "C"
JNIEXPORT void JNICALL
Java_com_a3dprintingsystems_robopose_CvAruco_detectMarkers_11(JNIEnv *env, jclass type,
                                                           jlong imgAddr, jlong dictionaryAddr,
                                                           jlong cornersAddr, jlong idsAddr) {

    cv::Mat* image = (cv::Mat*)imgAddr;
    Ptr<aruco::Dictionary> dictionary = *((Ptr<aruco::Dictionary>*)(dictionaryAddr));
    Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();

    vector< int > ids;
    vector< vector< Point2f > > corners, rejected;
    vector< Vec3d > rvecs, tvecs;

    aruco::detectMarkers(*image, dictionary, corners, ids, detectorParams, rejected);

    aruco::drawDetectedMarkers(*image, corners, ids, Scalar(255, 255, 0));

    vector_int_to_Mat(ids, *((cv::Mat*)idsAddr));
    vector_vector_Point2f_to_Mat(corners, *((cv::Mat*)cornersAddr));
}

And in Android, use it like this:

Mat ids = new Mat();
List<Mat> corners = new ArrayList<>();
CvAruco.detectMarkers(grayFrame, Aruco.getPredefinedDictionary(DICT_4X4_50), corners, ids);

Hope it helps