Ask Your Question

Revision history [back]

You can use Utils.bitmapToMat function to convert you bitmap to OpenCV Mat on Java size directly. Then you can pass Mat.nativeObj to your jni function. Mat.nativeObj is a pointer to native C++ Mat Object. You get something like that:

// Java
Core.Mat tmpMat = new Mat();
Utils.bitmapToMat(srcBitmap);
Foo(tmpMat);

// JNI
JNIEXPORT void JNICALL Java_com_my_class_foo(
                JNIEnv* env, jobject thiz, jlong in, jlong out)
{
    cv::Mat* inMat = (cv::Mat*)in;
    cv::Mat* outMat = (cv::Mat*)out;
    // processing
    process_frame(*inMat, *outMat);
}