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);

}

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值