I need to convert csv file into matrices.I wrote the following code.
include <opencv2 imgproc="" imgproc.hpp="">
include <opencv2 opencv.hpp="">
include <opencv2 core="" core.hpp="">
include "opencv2/imgcodecs.hpp"
include <opencv2 highgui="" highgui_c.h="">
include <opencv2 ml.hpp="">
include <cstdlib>
include<algorithm>
include<fstream>
include<string>
include<iostream>
include<stdlib.h>
include<stdio.h>
using namespace cv; using namespace cv::ml; using namespace std; int main(int, char**){
const char *CSV_FILE = "/home/vidushi/Desktop/new/training.csv";
const char *CSV_FILE1 = "/home/vidushi/Desktop/new/testing.csv";
CvMLData dataFile;
CvMLData dataFile1;
// Load matrix data in csv format
if (dataFile.read_csv(CSV_FILE) != 0)
{
fprintf(stderr, "Can't read csv file %s\n", CSV_FILE);
return -1;
}
Mat dataMat(dataFile.get_values()); // Default data type is float
int labels[11] = {1,1,1,1,1,1,1,1,1,1,1};
Mat labelsMat(11, 1, CV_32SC1, labels);
CvMLData dataFile1;
// Load matrix data in csv format
if (dataFile1.read_csv(CSV_FILE1) != 0)
{
fprintf(stderr, "Can't read csv file %s\n", CSV_FILE1);
return -1;
}
Mat dataMat1(dataFile1.get_values()); // Default data type is float
Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
svm->train(dataMat, ROW_SAMPLE, labelsMat);
float res = svm->predict(dataMat1);
cout << "- Result of prediction:" << res;
return 0;
} When i try to compile this code.Error is generated - /home/vidushi/Desktop/new/svm_class.cpp:29:5: error: ‘CvMLData’ was not declared in this scope CvMLData dataFile; ^ /home/vidushi/Desktop/new/svm_class.cpp:30:14: error: expected ‘;’ before ‘dataFile1’ CvMLData dataFile1; ^ /home/vidushi/Desktop/new/svm_class.cpp:32:9: error: ‘dataFile’ was not declared in this scope if (dataFile.read_csv(CSV_FILE) != 0) ^ /home/vidushi/Desktop/new/svm_class.cpp:37:17: error: ‘dataFile’ was not declared in this scope Mat dataMat(dataFile.get_values()); // Default data type is float ^ /home/vidushi/Desktop/new/svm_class.cpp:41:14: error: expected ‘;’ before ‘dataFile1’ CvMLData dataFile1; ^ /home/vidushi/Desktop/new/svm_class.cpp:43:9: error: ‘dataFile1’ was not declared in this scope if (dataFile1.read_csv(CSV_FILE1) != 0) ^ /home/vidushi/Desktop/new/svm_class.cpp:48:18: error: ‘dataFile1’ was not declared in this scope
Please tell how to resolve this error. I am using opencv 3.2.0, ubuntu 16.04 LTS.