使用CSV文件去读图像和标签

来源:互联网 发布:linux 解压gz文件 编辑:程序博客网 时间:2024/05/29 18:40
//使用CSV文件去读图像和标签,主要使用stringstream和getline方法staticvoid read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator =';') {std::ifstream file(filename.c_str(), ifstream::in);if (!file) {string error_message ="No valid input file was given, please check the given filename.";CV_Error(CV_StsBadArg, error_message);}string line, path, classlabel;while (getline(file, line)) {stringstream liness(line);getline(liness, path, separator);getline(liness, classlabel);if(!path.empty()&&!classlabel.empty()) {images.push_back(imread(path, 0));labels.push_back(atoi(classlabel.c_str()));}}}
原创粉丝点击