Ask Your Question

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

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

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.setTermCriteria(new TermCriteria(TermCriteria.COUNT+TermCriteria.EPS, 500, 0.001));
   boolean b = model.trainEM(mMatrix);

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

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

berak gravatar image

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

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


@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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 215 times

Last updated: Sep 23 '15