Android 3.1 ANN_MLP HoG Descriptor

asked 2016-03-26 07:24:26 -0500

Jian.Xi gravatar image

updated 2016-03-26 08:04:08 -0500

berak gravatar image

Hello everyone,

I'm working now at a pattern recognition Project and using ANN_MLP. I trained this model at frist with Opencv3.1 and using HoG as feature extractor in Windows and after that I was trying to load in it in Android. For Android I use the OpenCV-3.1.0-android-sdk. I've googled and it shows that since Java opencv 2.4 there is no load method for StatModel object. So i tried to load it with JNI. Here I have two questions:

1. When i create a HoG descriptor instance using the following codes,

{
HOGDescriptor mHoGDescriptor = new HOGDescriptor(_winSize, _blockSize, _blockStride, _cellSize, _nbins);
 }

========================================================== [I got the fatal exception:]

FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.objdetect.HOGDescriptor.HOGDescriptor_1:(DDDDDDDDI)J
at org.opencv.objdetect.HOGDescriptor.HOGDescriptor_1(Native Method)
at org.opencv.objdetect.HOGDescriptor.<init>(HOGDescriptor.java:46)
at com.example.jian.reader.FeatureEvaluator$HoGFeature.<init>(FeatureEvaluator.java:27)
at com.example.jian.reader.MainActivity.initializeModels(MainActivity.java:537)
at com.example.jian.reader.MainActivity.onCreate(MainActivity.java:524)

==========================================================

2. In JNI loading model function, I use this method

JNIEXPORT jlong JNICALL Java_com_example_jian_reader_BridgeNativeModel_nativeCreateObject
  (JNIEnv *jenv, jclass, jstring jFileName){

    LOGD("Java_com_example_jian_reader_BridgeNativeModel_nativeCreateObject enter");

    const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
    string stdFileName(jnamestr);
    jlong result = 0;
    LOGD("jnamestr %s", jnamestr);

    try
    {
        Ptr<ml::ANN_MLP> model = Algorithm::load<ml::ANN_MLP>(stdFileName);
        if(model != NULL){
            LOGD("Model load successed");
            string schema = model->getDefaultName();
            Mat layers = model->getLayerSizes();
            int TrainingMethod = model->getTrainMethod();

            LOGD("schema:%s ", schema.c_str());
            LOGD("layers rows:%d ", layers.rows);
            for (size_t i = 0; i < layers.rows; i++)
            {
                LOGD("\t[Layers Size: %d]", i);
                for (size_t j = 0; j < layers.cols; j++)
                {
                    LOGD(" has %d nodes",  layers.at<int>(i, j));
                }
            }
            LOGD("TrainingMethod:%d ", TrainingMethod);
            LOGD("[Number of iterations/elements::%d ]", model->getTermCriteria().maxCount);
        }

        result = <jlong>(model);
    }
}

========================================================== So I don't konw how to covert ANN_MLP instance to jlong, this is the compliling error

Reader/app/src/main/jni/BridgeNativeModel_jni.cpp: In function 'jlong Java_com_example_jian_reader_BridgeNativeModel_nativeCreateObject(JNIEnv*, jclass, jstring)':
Reader/app/src/main/jni/BridgeNativeModel_jni.cpp:55:18: error: expected primary-expression before '<' token
         result = <jlong>(model);

Any Inputs will be appreciated! Jian

edit retag flag offensive close merge delete