I'm wonder if it's possible to export a model trained in R, to OpenCV's Machine Learning (ML) library format? The latter appears to save/read models in XML/YAML, whereas the former might be exportable via PMML. Specifically, I'm working with Random Forests, which are classifiers available both in R and OpenCV's ML library.

Any advice on how I can get the two to share models would be greatly appreciated.

  • $\begingroup$ Writing a conversion script seems the most straightforward way to do this. $\endgroup$ Commented Dec 12, 2014 at 16:18
  • $\begingroup$ @AmirAliAkbari - Have you done something like that with R and OpenCV? If so, can you provide an example in the form of an answer? If not, can you point out some promising approaches for writing such a conversion script? $\endgroup$ Commented Dec 12, 2014 at 22:52

1 Answer 1


Instead of exporting your models, consider creating an R-based interoperable environment for your modeling needs. Such environment would consists of R environment proper as well as integration layers for your third-party libraries. In particular, for the OpenCV project, consider either using r-opencv open source project (https://code.google.com/p/r-opencv), or integration via OpenCV C++ APIs and R Rcpp package (http://dirk.eddelbuettel.com/code/rcpp.html). Finally, if you want to add PMML support to the mix and create a deployable-to-cloud solution, take a look at the following excellent blog post with relevant examples: http://things-about-r.tumblr.com/post/37861967022/predictive-modeling-using-r-and-the.

  • 1
    $\begingroup$ Unfortunately, it looks as if r-opencv is relatively unmaintained (last updates 9 months ago, followed by 5 years ago). The PMML option and associated link appear to be great resources. Thanks! $\endgroup$ Commented Dec 15, 2014 at 2:53
  • $\begingroup$ I see. Well, depending on how you look at it, this might be an opportunity to revive the project (of course, if you're interested and can devote some time to it). I'm glad the other information is helpful to you. Thanks for accepting the answer, which you can also upvote, if you feel generous today :-). Good luck with your project! And keep an eye on Azure Machine Learning, which I haven't included in my answer, as I consider this offering currently 1) still too raw; 2) not cost-effective; 3) not flexible enough (vs. pure R-based). $\endgroup$ Commented Dec 15, 2014 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.