Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing cv:Mat from android to jni

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;
    }
}
like image 475
patrick Avatar asked Feb 10 '23 19:02

patrick


1 Answers

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;
}
like image 63
jet47 Avatar answered Feb 15 '23 10:02

jet47