I'm dealing with the parameter passing between an Android Application with OpenCV and the JNI. Using the OpenCV libraries in Java I have something like this in the Android app code.
Android OpenCV Java Code:
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 Code:
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;
}
But when I try to make de conversion from (Mat) to (IplImage *) in the C Code my app fails. So my question is about how to pass a CvRect and a Mat object from my Android Java code to the JNI. Is there a better way to do this?
Thanks a lot.
It seems that there is a difference between the Java Mat and the C Mat object, but you can pass the address of the native Mat object that your Java Mat object stores. Change your code to the following:
Android OpenCV Java Code:
//call to the native function
int resProc = Native.processImages_native(rect, mat.getNativeObjAddr());
C Code:
jint Java_com_test_Native_processImages_1native
(JNIEnv* env, jclass jc, CvRect rect, jlong mat){
int res = processImages(rect, *((Mat*)mat));
return (jint)res;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With