c++ - Error passing a cv::Mat to JNI using OpenCV on Android -


i developing android project opencv , jni.

actually changing face-detection sample.

the problem have when pass cv::mat reference gives strane output , not passed well.

to put in situation, have in fdactivity.java, main activity of android app:

 public mat oncameraframe(cvcameraviewframe inputframe) {     rgb = inputframe.rgba();     mat res = mnativedetector.process(rgb);     return res; } 

the process function this:

public mat process(mat rgb) {     mat n = null;     if(rgb.empty()) {         system.out.println("empty image");     }     else {         system.out.println("the image " + rgb.rows() + "x" + rgb.cols());         n = nativeskinfilter(mnativeobj, rgb.getnativeobjaddr());     }        return n; } 

where nativeskinfilter native function declaration

private static native mat nativeskinfilter(long thiz, long inputimage); 

in c++ side have function declaration (detectionbasedtracker.h):

jniexport jlong jnicall java_org_opencv_samples_facedetect_detectionbasedtracker_nativeskinfilter (jnienv *, jclass, jlong); 

the thing want return same image, passing c++ function (more complex implementation come know can correctly pass matrix), code (detectionbasedtracker.cpp):

jniexport jlong jnicall java_org_opencv_samples_facedetect_detectionbasedtracker_nativeskinfilter (jnienv * jenv,jclass,jlong rgb) {     mat* rgba = (mat*) rgb;     if(rgb == 0) {         logd("null matrix");     }     else {         logd("the matrix not null. has %i rows , %i columns", (*rgba).rows, (*rgba).cols);     }      return (jlong)rgb; } 

the ouptut have following:

07-07 13:00:07.671: i/choreographer(14980): skipped 55 frames!  application may doing work on main thread. 07-07 13:00:07.701: e/bufferqueue(14980): [unnamed-14980-0] dequeuebuffer: min undequeued buffer count (2) exceeded (dequeued=6 undequeudcount=0) 07-07 13:00:07.741: i/javacameraview(14980): preview frame received. need create mat , deliver clients 07-07 13:00:07.741: i/javacameraview(14980): frame size  576000 07-07 13:00:07.761: i/system.out(14980): image 480x800 07-07 13:00:07.761: d/facedetection/detectionbasedtracker(14980): matrix not null. has 1937716000 rows , 0 columns 07-07 13:00:07.761: e/cv::error()(14980): opencv error: assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void java_org_opencv_android_utils_nmattobitmap2(jnienv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave_desktop/50-sdk/opencv/modules/java/generator/src/cpp/utils.cpp, line 97 07-07 13:00:07.761: e/org.opencv.android.utils(14980): nmattobitmap catched cv::exception: /home/reports/ci/slave_desktop/50-sdk/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void java_org_opencv_android_utils_nmattobitmap2(jnienv*, jclass, jlong, jobject, jboolean) 07-07 13:00:07.761: a/libc(14980): fatal signal 11 (sigsegv) @ 0x0000000a (code=1), thread 15115 (thread-5379) 07-07 13:00:07.791: e/bufferqueue(14980): [unnamed-14980-0] dequeuebuffer: min undequeued buffer count (2) exceeded (dequeued=5 undequeudcount=1) 07-07 13:00:07.801: i/javacameraview(14980): preview frame received. need create mat , deliver clients 07-07 13:00:07.801: i/javacameraview(14980): frame size  576000 

i think have tried everything, seems correct way , it's still failing. can please please me?

thank time! appreciated.

this

jniexport jlong jnicall java_org_opencv_samples_facedetect_detectionbasedtracker_nativeskinfilter (jnienv *, jclass, jlong); 

should this

jniexport jlong jnicall java_org_opencv_samples_facedetect_detectionbasedtracker_nativeskinfilter (jnienv *, jclass, jobject, jlong); 

because call in java

n = nativeskinfilter(mnativeobj, rgb.getnativeobjaddr()); 

expects 4 parameters:

  • jnenv (obvious)
  • jclass class. or if invoking method instance jobject
  • jobject passing in object
  • jlong actual matrix looking for

in c++ side, after second parameter, parameters pass in on java side passed. in other words, every call via java->c++ (whether instance or static function) on c++ side first 2 parameters mandatory. follows parameters between "(" , ")" in java code.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -