我正在使用NDK + OpenCV开发应用程序。我有以下问题:

我将所有本机方法都放在FoodRecgNativeLib.java中,我想从文件中读取opencv Matrix:

//in FoodRecgNativeLib.java

public static void NativeLoadFile(String path, String tag, Mat result)
{
    loadsfile(path,tag,result.nativeObj);
    return;
}
public native static void loadsfile(String path, String tag, long addr);

//.h file
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ca_uwo_csd_Threads_FoodRecgNativeLib */

#ifndef _Included_ca_uwo_csd_Threads_FoodRecgNativeLib
#define _Included_ca_uwo_csd_Threads_FoodRecgNativeLib
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_ca_uwo_csd_Threads_FoodRecgNativeLib_loadsfile
(JNIEnv *, jclass, jstring, jstring, jlong);
#ifdef __cplusplus
}
#endif
#endif

//in .cpp file, .h file is included

JNIEXPORT void JNICALL Java_ca_uwo_csd_Threads_FoodRecgNativeLib_loadsfile
 (JNIEnv *env, jobject cls, jstring path, jstring tag, jlong result_addr)
{
    cv::FileStorage fs(jstring2str(env,path), FileStorage::READ);
    Mat& data = *(Mat*)result_addr;;
    fs[jstring2str(env,tag)] >> data;
}

谁能检查我的代码有什么问题?

最佳答案

Java_ca_uwo_csd_Threads_FoodRecgNativeLib_loadsfile的声明和实现签名不匹配。将实现中的第二个参数类型从jobject更改为jclass

08-06 13:00