Ask Your Question
2

How to load EM model using OpenCV android sdk V3.0.0

asked 2015-09-23 09:59:19 -0600

Muaaz gravatar image

Hi all, I am using EM.Java to create a model and I save it to the file but I can't find the way to load it back for prediction purpose.

    EM model = EM.create();
    model.setClustersNumber(32);
    model.setCovarianceMatrixType(EM.COV_MAT_SPHERICAL);
    model.setTermCriteria(new TermCriteria(TermCriteria.COUNT+TermCriteria.EPS, 500, 0.001));
   boolean b = model.trainEM(mMatrix);
    if(b){

        model.save("TrainedModelGMM.xml");
    }

I will really appriciate if some one can guide me how to load trained model ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-09-23 10:03:16 -0600

berak gravatar image

updated 2015-09-23 10:42:10 -0600

that's a known bug , for now, unfortunately there's no way to do so without falling back to JNI/NDK (the problem is not even specific to EM, but applies to all the ml classes).

you'll have to create a new EM instance (in c++) with:

Ptr<ml::EM> em = Algorithm::load<ml::EM>(filename);

and return that to your java code like:

    return (jlong)(new Ptr<ml::EM>(em));

yes, it has to be wrapped into a 2nd Ptr to keep the refcounts proper ;(

(and again, the problem with the script, that generates the java/python/matlab wrappers is, that it cannot deduce the template argument at that stage)

edit flag offensive delete link more

Comments

@Muaaz, just saying, if you could append your problem to above bug report - maybe it helps to focus the devs on this ;)

berak gravatar imageberak ( 2015-09-23 13:11:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-23 09:59:19 -0600

Seen: 728 times

Last updated: Sep 23 '15