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