2012-03-27 81 views
3

我正在处理Android应用程序与OpenCV和JNI之间传递的参数。在Java中使用OpenCV库我在Android应用程序代码中使用了类似的东西。Android和JNI之间的参数传递

的Android OpenCV的Java代码:

Mat mat; //Mat object with data 
Rect rect; //Rect object with data 

//call to the native function 
int resProc = Native.processImages_native(rect, mat); 

C代码:

JNIEXPORT jint JNICALL Java_com_test_Native_processImages_1native 
(JNIEnv*, jclass, CvRect, Mat); 

... 

jint Java_com_test_Native_processImages_1native 
(JNIEnv* env, jclass jc, CvRect rect, Mat mat){ 
    int res = processImages(rect, mat); 
    return (jint)res; 
} 

... 

int processImages(CvRect rect, Mat mat) 
{    
    IplImage *ipl_Img = &mat.operator IplImage(); // here FAILS 
    CvRect rect_value = rect; 
} 

但是,当我试图让从(MAT)去转换(IplImage结构*)在C代码我的应用程序失败。所以我的问题是关于如何将Android Java代码中的CvRect和Mat对象传递给JNI。有一个更好的方法吗?

非常感谢。

回答

1

似乎有是Java Mat以及C Mat对象之间的差异,但你可以通过本机Mat对象的Java Mat对象存储的地址。你的代码更改为以下:

的Android OpenCV的Java代码:

//call to the native function 
int resProc = Native.processImages_native(rect, mat.getNativeObjAddr()); 

C代码:

jint Java_com_test_Native_processImages_1native 
(JNIEnv* env, jclass jc, CvRect rect, jlong mat){ 
    int res = processImages(rect, *((Mat*)mat)); 
    return (jint)res; 
} 
+0

似乎工作,非常感谢! – brachialste 2014-10-02 20:48:17