zoukankan      html  css  js  c++  java
  • opencv 批量图像读写

    处理图像数据集时通常要读写整个文件夹里的图像,这时就会用的图像的批量读写。

    比较常用的方法就是生成一个包含所有图像的txt列表

    生成txt文件的方法如下:

    利用cmd进入dos

    利用路径进入指定文件夹后生成txt文件

    然后可以利用txt列表读入图像并做处理。

    #include "opencv2/opencv.hpp"  
    #include "iostream"  
    #include <fstream>  
    #include <windows.h>
    #include <string>
    
    using namespace std;
    using namespace cv;
    
    
    
    int main()
    {
        Mat image;
        string ImgName;
        string savefile;
        int count = 1;
        ifstream fin("D:/opencv pro/readfiles/readfiles/English1.txt");//打开原始样本图片文件列表  
        while (getline(fin, ImgName)) //逐行读取文件列表  
        {
    
            cout << "processing:" << ImgName << endl;
            ImgName = "D:/opencv pro/readfiles/readfiles/" + ImgName;
            savefile = "D:/opencv pro/readfiles/readfiles/saved/" + to_string(count) + ".jpg"; 指定存储路径
            image = imread(ImgName);//读取图片  
            //imshow("1", image);
            if (image.data == 0)
            {
                printf("[error] 没有图片
    "); 
                return -1;
            }
            count++;
            imwrite(savefile, image);
    
        }
    
        waitKey(600000); //存储图像
        return 0;
    }
  • 相关阅读:
    MT【319】分段递推数列
    MT【318】分式不等式双代换
    Centos7环境变量
    VI快捷键
    Centos7 开机自动运行命令
    Centos7 编辑本地DNS解析配置文件
    Centos7修改主机名
    xadmin 自定义过滤器选项
    Centos7网卡配置文件
    Centos7 挂载
  • 原文地址:https://www.cnblogs.com/klitech/p/5955500.html
Copyright © 2011-2022 走看看