Can the Java interface pass a Mat to OpenCV's C interface via JNI
Hello
I am writing a desktop Java application that uses the new Java interface to OpenCV. However, because of certain Java limitations I have to use JNI to capture the images from the hardware. This is done by creating an empty Mat on the Java side, and using getNativeObjAddr() to pass a pointer to the native side. On the native side the Mat is assigned the proper size and filled with the image data.
In the android example (tutorial 2) they use C++, and do something like this:
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
...
extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba)
{
Mat& mGr = *(Mat*)addrGray;
Mat& mRgb = *(Mat*)addrRgba;
... do stuff with the Mat objects ...
}
}
As you can see they make use of the C++ interface (extern C is used for linking purposes). However, so far I've been building the JNI side in plain C. My question is, can I use OpenCV's C interface to modify the Mat? I'm guessing the getNativeObjAddr method returns a pointer to the C++ class instance, and not a C struct. I'm also not sure on how the cast would differ from the C++ version.
Anyone here with JNI experience that would know this?
Thanks for your time!
Bit of a gravedig, but I'd be interested in this as well!