zoukankan      html  css  js  c++  java
  • 将文件夹中的图像路径自动生成txt文件(便于opencv遍历处理图像)

    代码:

    #include<iostream>
    #include<vector>
    #include<io.h>
    #include<fstream>
    
    using namespace std;
    
    ofstream off("img_pow_sta.txt", ios::out);
    vector<int> number;
    
    int num = 0;
    
    void getFiles(string path, vector<string>& files)
    {
        //文件句柄  
        long   hFile = 0;
        //文件信息  
        struct _finddata_t fileinfo;
        string p;
        if ((hFile = _findfirst(p.assign(path).append("\*").c_str(), &fileinfo)) != -1)
        {
            do
            {
                //如果是目录,迭代之  
                //如果不是,加入列表  
                if ((fileinfo.attrib &  _A_SUBDIR))
                {
                    if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
                        getFiles(p.assign(path).append("\").append(fileinfo.name), files);
                        num++;
                    }
                }
                else
                {
                    files.push_back(p.assign(path).append("\").append(fileinfo.name));
                    number.push_back(num);
                }
            } while (_findnext(hFile, &fileinfo) == 0);
            _findclose(hFile);
        }
    }
    
    int main() {
        char* filepath = "D:\Desktop\people\people";
        vector<string> files;
        getFiles(filepath, files);
        char str[30];
        int size = files.size();
        for (int i = 1; i < size; i++) {
            off << files[i].c_str();
            off << " ";
            //off << number[i];
            off << "
    ";
        }
        off.close();
        return 0;
    }
  • 相关阅读:
    链接、装载与库
    mysql 调用外部程序
    SAMBA 共享服务器搭建
    Django 部署
    python基础教程1
    django 文件上传
    Django URLconf
    django view
    admin site
    django book
  • 原文地址:https://www.cnblogs.com/ggYYa/p/7001403.html
Copyright © 2011-2022 走看看