I have read a text file now I want to insert its values into the matrix. The values are tab separated in the form of rows and columns my data is :
5.000000 2.400000 4.000000 1.000000 0.800000
113.000000 94.320000 54.000000 59.000000 118.400000
384.000000 474.460000 330.000000 54.000000 158.050000
178.000000 185.710000 46.000000 132.000000 279.200000
174.000000 218.780000 61.000000 113.000000 255.000000
0.000000 0.000000 0.000000 0.000000 0.000000
I am inserting the values as:
#include <conio.h>
#include <io.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
#include <string>
#include <vector>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
using namespace cv;
using namespace cv::ml;
Mat CreateVector()
{
int Samples = 50, fea= 7;
Mat Vector(Samples, fea, CV_32FC1);
std::ifstream infile("table.txt");
try
{
std::string line;
int rowNum = 0;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int a, b, c, d, e, f, g;
if (!(iss >> a >> b >> c >> d >> e >> f >> g)) { break; } String Values[50][7] = line.split(" ");
for (int colNum = 0; colNum <= 10; colNum++)
{
Vector.put(rowNum, colNum, (int)FeatureValues[colNum]);
Vector.at(rowNum, colNum, (int)FeatureValues[colNum]);
Vector.insert(rowNum, colNum, (int)FeatureValues[colNum]);
Mat::inserter (rowNum, colNum, (int)FeatureValues[colNum]);
}
rowNum++; }
infile.close(); }
catch (Exception ex)
{ }
}
Kindly tell me how to split the values on tabs to get discrete values row by row. Since I am getting the codes in java which looks like this:
String FeatureValues[50][7] = line.split(" ");
Secondly guide me how to insert values of my csv file in Matrix named vector
What I have tried:
I have tried inserting the values into my vector using four ways yet after extensive google search i.e.
Vector.put(rowNum, colNum, (int)FeatureValues[colNum]);
Vector.at(rowNum, colNum, (int)FeatureValues[colNum]);
Vector.insert(rowNum, colNum, (int)FeatureValues[colNum]);
Mat::inserter (rowNum, colNum, (int)FeatureValues[colNum]);
but none is working while I guess put is function of java since working fine with java but I want in cpp