I'm trying to send a Mat object from android side to jni side, i do not want to send mat object address. But my jni code returns 0 for no of rows in Mat, which i'm not getting.
Android-Java code is :
buttton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Utils.bitmapToMat(bitmap, mat);
Log.d(TAG,Integer.toString(m.rows())+" "+Integer.toString(m.cols()));
textView.setText(Integer.toString(openCVJNI(m)));
}
});
JNI code is :
extern "C" {
JNIEXPORT jint JNICALL
Java_com_example_color_MainActivity_openCVJNI(JNIEnv *env, jobject thiz, Mat inputImage)
{
return inputImage.rows;
}
}
See https://github.com/Itseez/opencv/tree/master/samples/android/tutorial-2-mixedprocessing sample.
org.opencv.core.Mat
has getNativeObjAddr
method, it returns long
, which can be interpreted as pointer to cv::Mat
.
Java code:
openCVJNI(m.getNativeObjAddr());
JNI code:
Java_com_example_color_MainActivity_openCVJNI(JNIEnv *env, jobject thiz, long addrInputImage)
{
cv::Mat* pInputImage = (cv::Mat*)addrInputImage;
return pInputImage->rows;
}
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