1 | initial version |
currently, your code does not handle the sperating commas correctly, also, push_back() produces a single row Mat.
try like this:
std::ifstream file("img1.txt");
Mat depthImg;
int rows = 0;
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
char sep; //comma!
double x;
while (stream >> x && stream >> sep) {
depthImg.push_back(x);
}
rows ++;
}
// reshape to 2d:
depthImg = depthImg.reshape(1,rows);
2 | No.2 Revision |
currently, your code does not handle the sperating commas correctly, also, push_back() produces a single row Mat.
try like this:
std::ifstream file("img1.txt");
Mat depthImg;
int rows = 0;
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
char sep; //comma!
double x;
// read *both* a number and a comma:
while (stream >> x && stream >> sep) {
depthImg.push_back(x);
}
rows ++;
}
// reshape to 2d:
depthImg = depthImg.reshape(1,rows);
3 | No.3 Revision |
currently, your code does not handle the sperating seperating commas correctly, also, push_back() produces a single row Mat.
try like this:
std::ifstream file("img1.txt");
Mat depthImg;
int rows = 0;
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
char sep; //comma!
double x;
// read *both* a number and a comma:
while (stream >> x && stream >> sep) {
depthImg.push_back(x);
}
rows ++;
}
// reshape to 2d:
depthImg = depthImg.reshape(1,rows);