Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

svm->train raise exception with out train

i have vector<vector<float> > of features in size 1800*160 now i need train svm on it, i try use OPENCV SVM but in debug mode svm->train return false and in release mode this exeption raised :

Exception thrown at 0x00007FFF587AC387 (vcruntime140.dll):Access violation reading location 0x00000048B7FED000.

my code:

void Classifier::trainSVM(vector<vector<float> > data,cv::Mat Lable)
{
    // Train the SVM
    cv::Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
    svm->setType(cv::ml::SVM::C_SVC);
    svm->setKernel(cv::ml::SVM::LINEAR);
    svm->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER, 50000, 1e-6));
    cv::Mat trainingData = cv::Mat(data.size(), 160, CV_32FC1, data.data());
    std::cout << "\nBegan Training Svm in vector faces.";
    bool trained = svm->train(trainingData, cv::ml::ROW_SAMPLE, Lable);
    if (trained)
        svm->save("svm_data.xml");
    std::cout << "\nEnd Training Svm in vector faces.";

}

my opencv version is: 3.2