Created
July 25, 2021 02:51
-
-
Save saccadic/62ddac4c595c3a997f1df1a8992e431f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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