zoukankan      html  css  js  c++  java
  • 读取解析数据

    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;
    }
  • 相关阅读:
    OpenJudge 2721 忽略大小写比较字符串大小
    Poj 2586 / OpenJudge 2586 Y2K Accounting Bug
    Poj 2109 / OpenJudge 2109 Power of Cryptography
    Poj 1328 / OpenJudge 1328 Radar Installation
    Poj 2965 The Pilots Brothers' refrigerator
    Poj 2503 / OpenJudge 2503 Babelfish
    Poj 2388 Who's in the Middle
    模板:cin.getline用法
    Poj 3094 Quicksum
    Charles-Mac安装、配置及苹果手机安装证书
  • 原文地址:https://www.cnblogs.com/crazybird123/p/10132538.html
Copyright © 2011-2022 走看看