0

我正在创建一个库,用于在为 OCR 预处理图像之前检查图像是否模糊。我正在使用代码片段来执行此操作。当我尝试构建代码时,它显示未定义的引用错误:

 /home/blutech/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-  x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/blur-jni/blur-jni.o: in function Java_com_example_jniblur_ImageBlur_isBlurred:jni/blur-jni.cpp:49: error: undefined reference to 'IsBlurred'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libblur-jni.so] Error 1  

这是我的 Jni 代码:

JNIEXPORT jboolean JNICALL
Java_com_example_jniblur_ImageBlur_isBlurred(
    JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height) {
  jboolean inputCopy = JNI_FALSE;
  jbyte* const i = env->GetByteArrayElements(input, &inputCopy);

  float blur = 0.0;
  float extent = 0.0;
// cStyle -  reinterpret_cast<uint8*>(i)   env->GetByteArrayElements(input, &inputCopy);
  resetTimeLog();
  int blurred = IsBlurred(reinterpret_cast<uint8*>(i), width, height, &blur, &extent);

  timeLog("Finished image blur detection");
  printTimeLog();

  env->ReleaseByteArrayElements(input, i, JNI_ABORT);

  return blurred ? JNI_TRUE : JNI_FALSE;
}`  

这是我的 C 代码:

    DetectBlur(int* matrix, int width, int height,
    float* blur_conf, float* blur_extent) {
  int nedge = 0;
  int nda = 0;
  int nrg = 0;
  int nbrg = 0;

  // For each scale
  for (int current_scale = kDecomposition; current_scale > 0; --current_scale) {
    int scaled_width = width >> current_scale;
    int scaled_height = height >> current_scale;
    int window_size = 16 >> current_scale;  // 2, 4, 8
    // For each window
    for (int r = 0; r + window_size < scaled_height; r += window_size) {
      for (int c = 0; c + window_size < scaled_width; c += window_size) {
        int k, l;
        int emax = ComputeLocalMaximum(matrix, width, height,
            scaled_width, scaled_height, r, c, window_size, &k, &l);
        if (emax > kThreshold) {
          int emax1, emax2, emax3;
          switch (current_scale) {
            case 1:
              emax1 = emax;
              emax2 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 2);
              emax3 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 3);
              break;
            case 2:
              emax1 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 1);
              emax2 = emax;
              emax3 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 3);
              break;
            case 3:
              emax1 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 1);
              emax2 = ComputeEdgePointWeight(matrix, width, height,
                  k << current_scale, l << current_scale, 2);
              emax3 = emax;
              break;
          }

          nedge++;
          if (emax1 > emax2 && emax2 > emax3) {
            nda++;
          }
          if (emax1 < emax2 && emax2 < emax3) {
            nrg++;
            if (emax1 < kThreshold) {
              nbrg++;
            }
          }
          if (emax2 > emax1 && emax2 > emax3) {
            nrg++;
            if (emax1 < kThreshold) {
              nbrg++;
            }
          }
        }
      }
    }
  }    `
4

1 回答 1

1

IsBlurred(reinterpret_cast<uint8*>(i), width, height, &blur, &extent);

无论在哪里IsBlurred实现(其他源文件、静态库、共享库),都需要libblur-jni.so在编译时与您的链接。

查看您的来源,您有一个名为 DetectBlur 的函数,所以也许您打算调用它。

于 2013-11-12T14:06:09.957 回答