标签:turn image get 读取 readline make code atd for
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\n‘,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; }
标签:turn image get 读取 readline make code atd for
原文地址:https://www.cnblogs.com/crazybird123/p/10132538.html