ubuntu中從同一個文件夾中讀取無命名規則的多個文件

#include  <stdio.h>

#include  <string>

#include  <math.h>

#include  <glob.h>

#include  <cv.h>

#include  <highgui.h>

#include  <cxcore.h>

 

using namespace std;

using namespace cv;

 

int main(int argc,char **argv)

{

IplImage *pFrame;

string InputPath;

InputPath=argv[1];

// InputPath="/home/gxb/build/bin/0123";      直接傳入路徑

if (InputPath.at(InputPath.length()-1)!='/')

InputPath+='/';

glob_t g={0};
char patt[1024];
snprintf(patt, 512, "%s%s", InputPath.c_str(),"*.jpg");
glob(patt, GLOB_DOOFFS, NULL, &g);

 

for(int i=0;i<g.gl_pathc;i++)

{

char *p = g.gl_pathv[i]; 

pFrame=cvLoadImage(p,-1);

vector<int> labels;

vector<string> image_name;

string label_name=basename(p);    //The images must be named as 'label_name.jpg'

string label,name,temp;

int split=label_name.find('_');

if (split>0)

{

label=label_name.substr(0,split);    //返回一個從指定位置開始的指定長度的字符串

temp=label_name.substr(split+1,label.find('.'));

name=temp.substr(0,temp.find('.'));    //或者直接name=label_name.substr(split+1, label.find('.'));   //copy from '_" to '.jpg'

 

}

 //printf("%d, %s\n", atoi(label.c_str(),name.c_str());       

cout<<label<<endl;

cout<<name<<endl;
labels.push_back(atoi(label.c_str());

image_name.push_back(name);

system(0);

}

 

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章