I have an OpenCV Android app. Most of its code is in Java but I have
one function that is in C.
The function gets a Mat object and returns a new one.
My question is how do I return a Mat from the native code to Java?
Couldn’t find any example of that.
Thanks.
Today I had to return a Mat from native code. I started with “Tutorial 2 Advanced – 2. Mix Java+Native OpenCV” it already passes two Mat (Images captured from camera) objects to the native code.
But I wanted to return extracted feature, thus I added
jlong addrDescriptorto the signature:In the java part I added the Mat
The method
getNativeObjAddr()does the trick. The Mat is allocated in java and its address is passed to the native code, thus there isn’t any explicit returning.The Mat was filled with the required data and is directly accessible in the java code after the JNI invokation returns.
Somwhere else in the code the Mat is released: