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

来源:互联网 发布:tnt网络瘫痪 编辑:程序博客网 时间:2024/05/17 03:45


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

 

原创粉丝点击