# Exporting R model to OpenCV's Machine Learning Library

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.

• Writing a conversion script seems the most straightforward way to do this. – Amir Ali Akbari Dec 12 '14 at 16:18
• @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? – Prophet60091 Dec 12 '14 at 22:52

## 1 Answer

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.

• 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! – Prophet60091 Dec 15 '14 at 2:53
• 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). – Aleksandr Blekh Dec 15 '14 at 3:53