Why CvSVM is non-copyable?

asked 2014-11-04 11:06:35 -0600

juanmanpr gravatar image

CvSVM class copy constructors are private.

private:
CvSVM(const CvSVM&);
CvSVM& operator = (const CvSVM&);

This generates a lot of trouble to manage several classifiers in stl containers. What is the best way to manage, for instance, a vector of CvSVM? I have tried by using C++11's unique_ptr but after training, when using the predict method, I get an error message saying that I have to train before predicting (which I already did).

Thanks,

edit retag flag offensive close merge delete

Comments

2

use a cv::Ptr<CvSVM> ?

( actually, the only way to use it in upcoming opencv3.0 would be : Ptr<ml::SVM> = ml::SVM::create(); )

berak gravatar imageberak ( 2014-11-04 11:19:56 -0600 )edit

@berak, so I guess I will move this project to 3.0 now that I still can, thanks

juanmanpr gravatar imagejuanmanpr ( 2014-11-04 11:40:52 -0600 )edit

oooooh, wait, i did not say that you should move to 3.0 now ;) (might be still too much of an adventure, it's still in alpha)

all i was trying to say was, that e.g : vector<Ptr<CvSVM>> vec; vec.push_back(new CvSVM); might work in your case.

berak gravatar imageberak ( 2014-11-04 11:47:41 -0600 )edit
1

@berak Oh thanks for warning, I know it is in alpha, but I really like the Ptr<> = create() scheme. In any case, it is working now in 2.4.9 also, both with unique_ptr and Ptr (I had a bug). Thank you :)

juanmanpr gravatar imagejuanmanpr ( 2014-11-04 12:47:41 -0600 )edit