Ask Your Question
0

where is the jni wrapper

asked 2018-03-15 22:40:57 -0600

As well known, porting c/c++ library to android need two step, cross compile to achieve shared/static library and then write jni wrapper, which allow us to call c/c++ function with java code.

However, i could not find the jni code and native java function declaration in this repository, expect a little about mat in module/java/generator and also the python script gen_java.py.

So where is the jni wrapper code? is it generated by gen_java.py and then directly link to library ?

Thankful for any useful answers.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-03-16 01:10:25 -0600

berak gravatar image

updated 2018-03-16 01:11:45 -0600

yes, it is generated by gen_java.py.

after you run cmake/make, you'll find the generated c++ / java code in

build/modules/java_bindings_generator

edit flag offensive delete link more

Comments

1

thanks for a lot and i think this python script is so cool!

eugenelee gravatar imageeugenelee ( 2018-03-16 03:06:02 -0600 )edit
1

i found many data structures cannot be auto generated. For example, class Mat. And i find its native java declaration in modules/core/misc/java/core+Mat.java, but i could not find its jni wrapper, Could you tell me if you know. Thank you very much!

eugenelee gravatar imageeugenelee ( 2018-03-17 09:49:16 -0600 )edit

"i found many data structures cannot be auto generated" -- indeed.

"but i could not find its jni wrapper" -- did you miss: opencv\modules\java\generator\src\cpp?

berak gravatar imageberak ( 2018-03-17 09:59:26 -0600 )edit

yeah i found something related in module/java/generator/src/cpp/Mat.cpp, but the function name there is strange. For example, Java_org_opencv_core_Mat_n_1Mat__DDIDDDD, i don't understand what is the meaning of the string DDIDDDD and i could not find the corresponding name with java native declaration. I think they are what i am searching but do not understand the name changing.

eugenelee gravatar imageeugenelee ( 2018-03-17 10:09:47 -0600 )edit

search for "jni naming conventions" oe "jni name mangling"

also described here

those are the argument types, Double, Double, Int, ...

berak gravatar imageberak ( 2018-03-17 10:28:39 -0600 )edit

it's meant to be understood by a compiler, not a human ;)

berak gravatar imageberak ( 2018-03-17 10:29:31 -0600 )edit

Thanks, i saw that III is explained to a signature in that website link. So two more questions:

  1. JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III (JNIEnv* env, jclass, jint rows, jint cols, jint type); is the jni wrapper of java method private static native long n_Mat(int rows, int cols, int type);, right? i am still a little confused because i think the function name should be JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_Mat, without the number 1 and the signature III.
  2. In function JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III, there is a line return (jlong) new Mat( rows, cols, type );, how could Mat converted to long? because i didn't see user-defined conversation like operator long() in class mat.
eugenelee gravatar imageeugenelee ( 2018-03-17 22:25:32 -0600 )edit

i am sorry for the second question because it is silly. The new operation will return a pointer so it is valid to convert Mat * to long.

eugenelee gravatar imageeugenelee ( 2018-03-17 22:37:32 -0600 )edit
1

thanks. I have solved the first question by reading the document oracle, _1 is escape sequence standing for _, so n_1Mat in jni stands for n_Mat in c/c++. And in jni, overloaded native methods should be followed by two underscores (“__”) , then followed by the mangled argument signature.

eugenelee gravatar imageeugenelee ( 2018-03-18 03:04:32 -0600 )edit

i don't think, your 2nd question is silly. it probably takes anyone a deep breath, to dig that pointers are "just a number" ;)

berak gravatar imageberak ( 2018-03-18 03:19:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-15 22:40:57 -0600

Seen: 263 times

Last updated: Mar 15 '18