Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access c++ code from java program. For that I used concept of JNI.
I declare one native method in java, whose return type is Mat class of opencv, as follows :
Java
public native Mat getFrames();

Then using javah utility, I created c implementation(Header File) of my java class JNITest.h using command : javah -jni java_class_name. This header file is as follows :

Java
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */

#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     JNITest
 * Method:    getFrames
 * Signature: ()Lorg/opencv/core/Mat;
 */
JNIEXPORT jobject JNICALL Java_JNITest_getFrames(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

I implement this Java_JNITest_getFrames method in cpp file as follows:

C++
JNIEXPORT jobject JNICALL Java_JNITest_getFrames(JNIEnv *en, jobject)
{
    Mat frame;
    VideoCapture cap("D:\\ImageProcessing\\1.jpg");
    cap>>frame;
    jobject jb ;
    Mat * ptrImg = &frame;
    jb=(jobject)ptrImg;
    return jb;
}

But, this above code is not working.
So, how to convert opencv Mat class object to this jobject ?
And how do I return that object ?
Posted
Updated 28-Aug-15 0:56am
v2
Comments
Richard MacCutchan 28-Aug-15 6:56am    
What does "not working" mean?
RupeshMote 28-Aug-15 7:27am    
"not working" means: From c++ code I return object of jobject and in Java file received it in object of Mat as :
Mat vdFrame = new Mat();
vdFrame = vdTest.getFrames();

So that exception raises.

1 solution

See this Stack Overflow question: "Returning Mat object from native code to java in OpenCV"[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900