Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Read text file into mat

$
0
0
Hi, my text file contains 640 rows 480 columns of floating points. Id like to read them into a matrix and reshape at the end. But the code below only reads a single data per row. Help me edit the stream >> x please. Data separated by commas example 2.752,2.7521,2.7522,2.7524,2.7528,2.7532,2.7536,2.7542,2.7548,2.7555,2.7562,2.7569,2.7576,2.7583,2.7591, std::ifstream file("img1.txt"); Mat depthImg; int rows = 0; std::string line; while (std::getline(file, line)) { std::istringstream stream(line); //double x; //while (stream >> x) { //depthImg.push_back(x); //} while (stream) { string s; if (!std::getline(stream, s, ',')) break; depthImg.push_back(std::stof(s)); } rows++; } // reshape to 2d: depthImg = depthImg.reshape(1, rows);

Viewing all articles
Browse latest Browse all 19555

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>