SVM copy constructor is private

asked 2014-09-29 10:28:18 -0600

thdrksdfthmn gravatar image

updated 2014-09-29 10:49:31 -0600

I am using a SVM classifier for validating my detections. But when I have tried to copy the SVM it says the the copy constructor is private.

/usr/local/include/opencv2/ml/ml.hpp:553:5: error: ‘CvSVM::CvSVM(const CvSVM&)’ is private

If I change to m_svm = svmIn it says that operator = is also private.

/usr/local/include/opencv2/ml/ml.hpp:554:12: error: ‘CvSVM& CvSVM::operator=(const CvSVM&)’ is private

Now I am wondering how to copy my classifier? Shall I construct it every time?

edit retag flag offensive close merge delete


Have a look at this

boaz001 gravatar imageboaz001 ( 2014-09-29 11:14:30 -0600 )edit

Ok, but my question is how to copy SVM? No way, I cannot, that is the answer?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-29 11:42:00 -0600 )edit

Not with a copy or assignment operator, it is this way because of the underlying data (pointers and such are not managed) so you have to do that yourself or disable the copy and assignment operator, that's why the fix is there to disable them. Maybe the read/write member functions can be of any use for you...

boaz001 gravatar imageboaz001 ( 2014-09-29 15:39:45 -0600 )edit

it is not allowed to copy or assign it. (that's the purpose of a private copy constructor)

also, please use the c++ SVM class instead.

berak gravatar imageberak ( 2014-09-30 00:02:41 -0600 )edit

@berak: I was using cv::SVM classifier(trainingData, classes, cv::Mat(), cv::Mat(), svmParams); an I am using OpenCV 2.4.9, so I thin inside the class the CvSVM is used

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-30 02:21:23 -0600 )edit

better, but obviously still the same problem. can you avoid to copy it ?

SVM a;

SVM b=a; // illegal.

SVM & b = a; // legal;

Ptr<SVM> a = new SVM;

Ptr<SVM> b = a; // legal

berak gravatar imageberak ( 2014-09-30 02:41:16 -0600 )edit

Yes, I have managed to find a way of avoiding the copy.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-30 03:34:46 -0600 )edit