Can the Java interface pass a Mat to OpenCV's C interface via JNI

asked 2013-04-24 03:30:28 -0600

peanutman gravatar image

updated 2013-04-24 04:10:38 -0600

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!

edit retag flag offensive close merge delete

Comments

Bit of a gravedig, but I'd be interested in this as well!

ibrahima gravatar imageibrahima ( 2015-10-20 19:34:38 -0600 )edit