android - JNI, C++ problems -


i did opencv's application en windows , using jni convert code android having problems. in concrete native code not nothing.

this java class define native methods:

package com.example.telo3;  import org.opencv.core.mat;  public class process {      static {         system.loadlibrary("nativo");     }      public process(){          dir=inicializar_nativo();     }      public void procesar(mat framedetect, mat framedraw){          procesar_nativo(dir,framedetect.getnativeobjaddr(),framedraw.getnativeobjaddr());     }       private long dir;     private static native long inicializar_nativo();     private static native void procesar_nativo(long thiz, long framedetect, long framedraw); 

}

this jni code:

#include "nativo.h" #include <opencv2/objdetect/objdetect.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include "opencv2/video/tracking.hpp"  #include <iostream> #include <stdio.h> #include "facedetector.h" #include "draw.h" #include "almacena.h" #include "runnable.h"    using namespace std; using namespace cv;  #include <android/log.h>  #define log_tag "nativo" #define logd(...) ((void)__android_log_print(android_log_debug, log_tag, __va_args__))  struct variables {     almacena almacena;     draw draw;     facedetector face_detector; };  jniexport jlong jnicall java_com_example_telo3_process_inicializar_1nativo(         jnienv *, jobject) {      long dir = (long) new variables();      return (dir);   }  jniexport void jnicall java_com_example_telo3_process_procesar_1nativo(jnienv *,         jobject, jlong dir, jlong framedetect, jlong framedraw) {    mat* telo =(mat*)framedetect; mat* telo2= (mat*)framedraw;  ((variables*)dir)->almacena = ((variables*)dir)->face_detector.detect(*telo);    //almacena = face_detector.detect(frame_gray);    ((variables*)dir)->draw.dibujar(*telo2,((variables*)dir)->almacena);    //frame_capturado = draw.dibujar(frame_capturado, almacena);    if( (((variables*)dir)->almacena.get_faces()).size() ==0){      logd("no detecto caras"); }   } 

i think use jni correctly function detect not works correctly because when uses if return 0.

is framedetect 0? made test app based on , worked fine (that is, jlong converted , fine, shouldn't issue).

try catching error ndk-gdb better understand problem. attaching process might problem though if crashes straight away, in case put breakpoint on java side before crash, make execution pause there using debugger, attach ndk-gdb , continue let java process continue.

also recommend using reinterpret_cast<jlong> , reinterpret_cast<variables*> instead of c style casts, , save cast separate variable avoid casting time! cleaner code!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -