码迷,mamicode.com
首页 > 其他好文 > 详细

读取解析数据

时间:2018-12-17 17:36:45      阅读:177      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!