Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Copying an SVM

I try the following code in C++ using OpenCV 2.42 and it fails when attempting to copy the svm

include <opencv2/opencv.hpp>
using namespace cv;

int main(int argc, char *argv[]){

    Mat trainData(100, 3, CV_32F);
    randu(trainData, 0.0f, 10.f);

    Mat classes = Mat::zeros(100, 1, CV_32F);
    for(int i = 50; i < classes.rows; i++)<float>(i) = 1.0f;

    Mat sample = Mat::ones(1, 3, CV_32F);

    SVM svm;
    svm.train_auto(trainData, classes, Mat(), Mat(), SVMParams(), 2);

    SVM svm2 = SVM(svm);

and gives the message (VS2010 Windows XP)

OpenCV Error: Assertion failed (udata < (uchar*)ptr && ((uchar*)ptr - udata) <=
(ptrdiff_t)(sizeof(void*)+16)) in unknown function, file ..\..\..\src\opencv\mod
ules\core\src\alloc.cpp, line 78

Is this a bug, or is there something I am missing about copying an SVM? I expected it to copy the decision function, support vectors, and other parameters, but something seems to be going wrong. I had a look at the source in ml.hpp and it doesn't seem to define a copy constructor.