Skip to content

Instantly share code, notes, and snippets.

@saccadic
Created July 25, 2021 02:51
Show Gist options
  • Save saccadic/62ddac4c595c3a997f1df1a8992e431f to your computer and use it in GitHub Desktop.
Save saccadic/62ddac4c595c3a997f1df1a8992e431f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
using namespace std;
static cv::Mat readCsv(string path, int w, int h) {
std::vector<std::vector<float>> vv;
ifstream ifs(path);
string line;
while (getline(ifs, line)) {
std::istringstream i_stream(line);
string value;
std::vector<float> temp;
while (getline(i_stream, value, ',')) {
temp.push_back(std::stof(value));
}
vv.push_back(temp);
}
//cout << vv.size() << endl;
//cout << vv[0].size() << endl;
cv::Mat temp(0, vv[0].size(), cv::DataType<float>::type);
for (unsigned int i = 0; i < h; i++)
{
// Make a temporary cv::Mat row and add to NewSamples _without_ data copy
cv::Mat Sample(1, w, cv::DataType<float>::type, vv[i].data());
temp.push_back(Sample);
}
return temp;
}
static cv::Mat readCsv(string path) {
std::vector<std::vector<float>> vv;
ifstream ifs(path);
string line;
while (getline(ifs, line)) {
std::istringstream i_stream(line);
string value;
std::vector<float> temp;
while (getline(i_stream, value, ',')) {
temp.push_back(std::stof(value));
}
vv.push_back(temp);
}
//cout << vv.size() << endl;
//cout << vv[0].size() << endl;
cv::Mat temp(0, vv[0].size(), cv::DataType<float>::type);
for (unsigned int i = 0; i < vv.size(); i++)
{
// Make a temporary cv::Mat row and add to NewSamples _without_ data copy
cv::Mat Sample(1, vv[0].size(), cv::DataType<float>::type, vv[i].data());
temp.push_back(Sample);
}
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment