opencv - Android NDK get object from Java -


i want know how custom object java c++?

i need implement method in c++ performance. have method working in java want port c++.

on java call method this:

private native boolean p(mat previous, string name); 

on cpp file need mat object. getting string easy! how can custom mat object similar c++(cv::mat)? need java mat cv::mat. here cpp file:

jniexport bool jnicall java_br_raphael_detector_simpsondetector_p                       (jnienv* env,jobject thiz, jobject previous, jstring name){ jboolean sim = false;  const char* n = env->getstringutfchars(name,0); std::string nome = n;   //release env->releasestringutfchars(name,n);  //then return return sim; 

}

a java mat object a totally different thing native cv::mat, can't 1 directly other.

that said, if know fields inside mat, , know corresponding fields in cv::mat, can write conversion function copies contents of fields one-by-one.

// first mat class jclass mat = (*env)->getobjectclass(env, previous);  // field jfieldid field = (*env)->getfieldid(env, mat, "fieldname", field type);  // method jmethodid method = (*env)->getmethodid(env, mat, "methodname", method signature); 

from there can read values of fields, or call methods

// getting field (*env)->getobjectfield(env, previous, field);  // calling method (*env)->callobjectmethod(env, previous, method, parameters); 

refer http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html details


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -