您的位置:首页 > 其它

c 语言小技巧之二 自动创建目录

2017-09-04 16:33 232 查看
int main()

{

 

 bool first = true;

 double average = 0.0;

 fstream fout;

 fout.open("log2017904.txt", ios::app | ios::out);

 int noface = 0;

 char imgpath[260];

 char imgpath2[260];

 string imagefolder_path = "E:\\face_data\\CASIA-WebFace";

// vector<string> files;

// getFiles("E:\\face_data\\CASIA-WebFace", files);

 

 int label = 0;

 fstream fin;

 fin.open("E:\\face_data\\cleaned list-casia.txt", ios::in || ios::app);

 string stemp;

 while (!fin.eof())

 {

  fin >> stemp >>label;

  cout << "stemp " << stemp << endl;

  sprintf(imgpath, "%s/%s", imagefolder_path.c_str(), stemp.c_str());

  Mat img = imread(imgpath);

  imshow("img", img);

  cvWaitKey(3);

  int last = stemp.find_last_of(".");

  int begin1 = stemp.find_last_of("\\");

  int begin2 = stemp.find_last_of("/");

  int begin = max(begin1, begin2);

  string sub_path = stemp.substr(0, begin);

  string name_image = stemp.substr(begin + 1, last - begin - 1);

  cout << "name " << name_image << endl;

  int facecount = FD_Detect(FD_handle, img.data, img.cols, img.rows, rect);

  if (facecount > 0)

  {

   char dir[260];

   sprintf(dir, "5K_new_20170901//%s", sub_path.c_str());

   if (_access(dir, 0) == -1)

   {

    _mkdir(dir);

    /*for (int i = 0; i < 2; i++)

    {

     sprintf(dir, "5K_new_20170901//%d", i);

     _mkdir(dir);

    }*/

   }

   //sprintf(imgpath2, "5K_new_20170901\\%s\\%s.jpg", name.c_str(), name_image.c_str())

   sprintf(imgpath2, "5K_new_20170901\\%s",stemp.c_str());

   cout << "imgpath2" << imgpath2 << endl;

   FF_FeaExtract(FF_handle, img.data, img.cols, img.rows, feature, rect[0], imgpath2);

  }

  else

  {

   noface++;

   fout << "no facecount" << endl;

  }

 }

 system("pause");

// fout << imgpath << endl;

 

 FD_Destroy(FD_handle);

 delete[] rect;

 return 1;

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: