Am here to get suggestions from you regarding my issue. Am new bee to this, i was stuck in this from yesterday, but unable to resolve it. Am trying to find the 2d array size in JNI, but am not getting successful result. The below code which i have. can you guys please sort out my problem.

JNIEXPORT jint JNICALL Java_com_example_imagejoiner_MyJoiner_test(JNIEnv*   
      env,
      jobject javaThis) {
   LOGV("test print");
   return 1;
 }
  JNIEXPORT void JNICALL     
  Java_com_example_imagejoiner_MyJoiner_joinNative(JNIEnv* env,
    jobject javaThis, jobjectArray jfilePaths, jstring jfinalImagePath, int   
 verticalOverlapPercent, int horizontalOverlapPercent) {

  const char *finalImagePath = env->GetStringUTFChars(jfinalImagePath, 0);

  const int imageCount = env->GetArrayLength(jfilePaths);
  int rows = 1;
  int columns = 4;

  Mat imageBuff[rows][columns];

  /*for (int i = 0; i < imageCount; i++) {
    jstring filePath = (jstring) env->GetObjectArrayElement( jfilePaths, i);
    const char *rawString = env->GetStringUTFChars(filePath, 0);

    LOGV("reading = %s", rawString);

    imageBuff[i] = imread(rawString, 1);

    if(!imageBuff[i].data) {
        LOGV("failed to read = %s", rawString);
    }

    env->ReleaseStringUTFChars(filePath, rawString);
    }*/

   //Creating a 2 dimensional array from the lieaner array
   int k = 0;
   for (int i = 0; i < rows; i++)
   {
    for (int j = 0; j < columns; j++)
    {
        jstring filePath = (jstring) env->GetObjectArrayElement( jfilePaths,   
      k);

        const char *rawString = env->GetStringUTFChars(filePath, 0);

        LOGV("reading = %s", rawString);

        imageBuff[i][j] = imread(rawString, 1);

        if(!imageBuff[i][j].data) {
            LOGV("failed to read = %s", rawString);
        }
        env->ReleaseStringUTFChars(filePath, rawString);

        k++;
      }
  }

  //Creating a 2 dimensional array from the 2 dimensional array
  /*for (int i = 0; i < rows; i++)
  {
    jstringArray filePath = (jstringArray) env->GetObjectArrayElement(   
      jfilePaths, i);

    for (int j = 0; j < columns; j++)
    {
        const char *rawString = env->GetStringUTFChars(filePath, j);

        LOGV("reading = %s", rawString);

        imageBuff[i][j] = imread(rawString, 1);

        if(!imageBuff[i][j].data) {
            LOGV("failed to read = %s", rawString);
        }

        env->ReleaseStringUTFChars(filePath, rawString);
    }
    }*/

Related posts

Recent Viewed