Ask Your Question
0

Save a random tree in python and load it in C++

asked 2017-11-03 10:09:43 -0600

updated 2019-12-09 07:48:52 -0600

ojesus gravatar image

Hi everyone,

I ask my question here, because I need to know if I save a random forest (random trees in openCV) in python (with openCV), can I load it in C++ ? I don't have code yet, I just want to know if it's possible ?

Thanks! Arthur

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-03 10:33:39 -0600

berak gravatar image

sure that should be possible. on the python side it is:

rf = cv2.ml.RTrees_create()
# ... train it
rf.save("rf.yml")
# also see:
# help(cv2.ml.RTrees_create())

on the c++ side it is:

// note, that loading a model creates a new object (in both py and c++):
Ptr<ml::RTrees> rf = ml::StatModel::load<ml::RTrees>("rf.yml");
float p = rf->predict(something);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-11-03 10:09:43 -0600

Seen: 1,152 times

Last updated: Nov 03 '17