svm train method segmantation fault problem
Hello,
I am using svm train method.But segmentation fault is occurred train method's line.I am using linux machine. My code is :
Mat responseMat(resSize, 1, CV_32FC1, res);
Mat trainingDataMat(trainSize, featureSize, CV_32FC1,trainingData);
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
cout << "svm settings" << endl;
// Train the SVM
CvSVM SVM;
SVM.train(trainingDataMat, responseMat, Mat(), Mat(), params);
cout << "svm train" << endl;
since you're using a construct like : Mat responseMat(resSize, 1, CV_32FC1, res);
if the res pointer leaves the scope, before you're done with processing responseMat, you're doomed.
try: Mat responseMat = Mat(resSize, 1, CV_32FC1, res).clone(); // for a deep copy of the contents.
same for trainingDataMat
@hsrt What is your
trainingData
? Looks like the problem is there.My train data :
float *trainingData; trainingData = new float[trainSize]; for(int i = 0; i < trainSize; i++) {
t
trainVector is filled in my code...
Dear Berak, "res" is still alive on this line...
so, trainingData is a float** ? that won't be continuous memory
yes beark , you are right...
How can I create continuous array with dynamic size? it looks like :
Mat sampleMat = (Mat_<float>(1,featureSize) << (trainData[i][0], trainData[i][1], trainData[i][2]....));
ah, that explains your other question ;)
what if you simply push_back() one value after the other, and reshape(1,cols) afterwards to get a NxM matrix ?
I am jumping between questions :)
I will try this way...