读取解析数据
Posted crazybird123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了读取解析数据相关的知识,希望对你有一定的参考价值。
clc clear all load imdb.mat [age,~]=datevec(datenum(imdb.photo_taken,7,1)-imdb.dob); fid = fopen(‘imdb.txt‘,‘wt‘); for i = 1:length(imdb.photo_taken) fprintf(fid, ‘%s,‘, char(imdb.full_path(i))); fprintf(fid, ‘%d,‘,age(i)); fprintf(fid,‘%d ‘,imdb.gender(i)); end fclose(fid)
int main() { std::ifstream fin("D:\数据\年龄性别\imdb_crop\0.txt");//打开原始样本图片文件列表 string readImgPartDir = "D:\数据\年龄性别\imdb_crop\"; string saveImgPartDir = "D:\数据\年龄性别\imdb_corect\"; string creatDirName;//文件夹名 string imgName;//图片名 string readLineName;//从txt中读取,每行是一个字符串 string readImg;//图片名完整路径 string saveImgDirImg; string saveImgDir; while (getline(fin, readLineName)) { cout << readLineName << endl; /*istringstream iss; iss.str(readLineName); iss >> creatDirName; iss >> imgName;*/ creatDirName = readLineName.substr(0, readLineName.find_first_of("\")); //cout << "creatDirName=" << creatDirName << endl; imgName = readLineName.substr(readLineName.find_last_of("\") + 1); //cout << "imgName=" << imgName << endl; readImg = readImgPartDir + creatDirName + "\" + imgName;//输入图片 saveImgDirImg = saveImgPartDir + creatDirName + "\" + imgName;//保存图片 saveImgDir = saveImgPartDir + creatDirName;//需要创建的文件夹 if (_access(saveImgDir.c_str(), 0) == -1) { int flag = _mkdir(saveImgDir.c_str()); if (flag == 0) { cout << "make successfully" << endl; } else { cout << "make failed" << endl; } } cout << "image path: " << readImg << endl; Mat image = imread(readImg); if (image.empty()) { printf("no image!"); continue; } else { cv::imwrite(saveImgDirImg, alignFace); } }//end while return 0; }
以上是关于读取解析数据的主要内容,如果未能解决你的问题,请参考以下文章
片段(Java) | 机试题+算法思路+考点+代码解析 2023