读取文件夹里面的图片生成对应的txt

#include <opencv\cv.h>
#include <string>
#include <vector>
#include <io.h>
#include <iostream>
#include <fstream>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
//#include <opencv2\imgcodecs.hpp>
//#include <opencv2\core\base.hpp>
using namespace std;
using namespace cv;
void getFiles(string path, vector<string>& files)
{
        struct _finddata_t fileinfo;
       string str;
        long fileHandle = _findfirst(str.assign(path).append( "/*" ).c_str(), &fileinfo);
        if (fileHandle == -1){
               return ;
       }
        while (!_findnext(fileHandle, &fileinfo)){
               if ((fileinfo.attrib &  _A_SUBDIR))
              {
                      if (strcmp(fileinfo.name, "." ) != 0 && strcmp(fileinfo.name, ".." ) != 0)
                            getFiles(str.assign(path).append( "/" ).append(fileinfo.name), files);
              }
               else
              {
                     files.push_back(str.assign(path).append( "/" ).append(fileinfo.name));
              }
       }
       _findclose(fileHandle);
}
int main( int argc, char ** argv)
{
        ofstream in;
        in.open( "svmTrainSet2.txt" ,ios::trunc);   // turn to creat the name of txt
        char * filePath = "E:/opencv_study/HOG+SVM/code/hat_background/Image/001" ;//the adress of pictrue
       vector<std::string> files;
       getFiles(filePath, files);
        int size = files.size();
        for ( int i = 0; i < size; i++)
       {
               //cout << files[i].c_str() << endl;
                 Mat img = imread(files[i].c_str());
               if (img.empty())
              {
                     cout << "Cannot get image " << files[i].c_str() << endl;
                     getchar();
                      //return -2;
              }
               else
              {
                     cout << "get image: " << files[i].c_str() << endl;
                      in<<files[i].c_str()<< "\n" ;
                      in<< "0" << "\n" ;
              }

       }

}


算法以及图像处理交流群:305606122,加群时请回答以下两个数组卷积结果

A[3][3]


B[3][3]



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值