예제 #1
0
void loadTrainPosFile(CConfig conf, std::vector<CPosDataset> &posSet)
{
    std::string traindatafilepath = conf.trainpath + PATH_SEP +  conf.traindatafile;
    int n_folders;
    int n_files;
    std::vector<std::string> trainimagefolder;
    std::vector<CPosDataset> tempDataSet;
    std::string trainDataListPath;
    int dataSetNum;
    CClassDatabase database;
    cv::Point tempPoint;
    nCk nck;

    posSet.clear();

    //read train data folder list
    std::ifstream in(traindatafilepath.c_str());
    if(!in.is_open()){
        std::cout << "train data floder list is not found!" << std::endl;
        exit(1);
    }

    // read train pos folder
    in >> n_folders;
    std::cout << "number of training data folders : " << n_folders << std::endl;
    trainimagefolder.resize(n_folders);
    for(int i = 0;i < n_folders; ++i)
        in >> trainimagefolder.at(i);

    // close train pos data folder list
    in.close();

    std::cout << "train folders lists : " << std::endl;
    //read train file name and grand truth from file
    tempDataSet.clear();
    for(int i = 0;i < n_folders; ++i){
        trainDataListPath
                = conf.trainpath + PATH_SEP + trainimagefolder.at(i) + PATH_SEP + conf.traindatalist;

        std::cout << trainDataListPath << std::endl;
        std::string imageFilePath
                = conf.trainpath + PATH_SEP + trainimagefolder.at(i) + PATH_SEP;

        std::ifstream trainDataList(trainDataListPath.c_str());
        if(!trainDataList.is_open()){
            std::cout << "can't read " << trainDataListPath << std::endl;
            exit(1);
        }

        trainDataList >> n_files;

        for(int j = 0;j < n_files; ++j){
            CPosDataset posTemp;
            std::string nameTemp;


            //            posTemp.angles.clear();
            //            posTemp.centerPoint.clear();

            //read file names
            trainDataList >> nameTemp;
            posTemp.setRgbImagePath(imageFilePath + nameTemp);

            trainDataList >> nameTemp;
            posTemp.setDepthImagePath(imageFilePath + nameTemp);

            trainDataList >> nameTemp;// dummy

            //read class name
            std::string tempClassName;
            trainDataList >> tempClassName;
            //temp.className.push_back(tempClassName);
            posTemp.setClassName(tempClassName);

            // read image size
            cv::Mat tempImage = cv::imread(posTemp.getRgbImagePath(),3);
            cv::Size tempSize = cv::Size(tempImage.cols, tempImage.rows);

            // set center point
            tempPoint = cv::Point(tempImage.cols / 2, tempImage.rows / 2);
            posTemp.setCenterPoint(tempPoint);

            // registre class param to class database
            database.add(posTemp.getParam()->getClassName(), tempSize, 0);

            //read angle grand truth
            double tempAngle;
            trainDataList >> tempAngle;
            posTemp.setAngle(tempAngle);

            tempDataSet.push_back(posTemp);
        }

        trainDataList.close();
    }

    dataSetNum = tempDataSet.size();
    int dataOffset = 0;
    database.show();
    for(int j = 0;j < database.vNode.size(); j++){
        std::set<int> chosenData = nck.generate(database.vNode.at(j).instances, conf.imagePerTree);

        std::set<int>::iterator ite = chosenData.begin();

        while(ite != chosenData.end()){
            posSet.push_back(tempDataSet.at(*ite + dataOffset));
            ite++;
        }
        dataOffset += database.vNode.at(j).instances;
    }


    //    std::cout << "show chosen dataset" << std::endl;
    //    for(int i = 0; i < dataSet.size(); ++i){
    //        dataSet.at(i).showDataset();
    //    }
}
예제 #2
0
void loadTrainFile(CConfig conf, std::vector<CDataset> &dataSet)
{
  dataSet.resize(0);
  
  std::string traindatafilepath = conf.trainpath + PATH_SEP +  conf.traindatafile;
  int n_folders;
  int n_files;
  std::vector<std::string> trainimagefolder;
  CDataset temp;
  std::vector<CDataset> tempDataSet;
  std::string trainDataListPath;
  int dataSetNum;
  CClassDatabase database;
  cv::Point tempPoint;
  nCk nck;
  
  
  //read train data folder list
  std::ifstream in(traindatafilepath.c_str());
  if(!in.is_open()){
    std::cout << "train data floder list is not found!" << std::endl;
    exit(1);
  }

  //std::cout << "kokomade " << std::endl;
  
  // read folder number
  in >> n_folders;
  std::cout << "number of training data folder: "
	    << n_folders << std::endl;
  trainimagefolder.resize(n_folders);

  // read train folder name
  for(int i = 0;i < n_folders; ++i)
    in >> trainimagefolder.at(i);

  std::cout << "train image foloder num is " << trainimagefolder.size() << std::endl;
  in.close();
  //read train file name and grand truth from file
  tempDataSet.clear();
  for(int i = 0;i < n_folders; ++i){
    trainDataListPath 
      = conf.trainpath + PATH_SEP + trainimagefolder.at(i) 
      + PATH_SEP + conf.traindatalist;

    std::cout << trainDataListPath << std::endl;
    temp.imageFilePath 
      = conf.trainpath + PATH_SEP + trainimagefolder.at(i) + PATH_SEP;

    std::ifstream trainDataList(trainDataListPath.c_str());
    if(!trainDataList.is_open()){
      std::cout << "can't read " << trainDataListPath << std::endl;
      exit(0);
    }

    trainDataList >> n_files;
    
    for(int j = 0;j < n_files; ++j){
      //read file names
      trainDataList >> temp.rgbImageName;
      trainDataList >> temp.depthImageName;
      trainDataList >> temp.maskImageName;

      //read bounding box
      //trainDataList >> temp.bBox.x;
      //trainDataList >> temp.bBox.y;
      //trainDataList >> temp.bBox.width;
      //trainDataList >> temp.bBox.height;
      
      temp.centerPoint.clear();

      //read center point
      //trainDataList >> tempPoint.x;//temp.centerPoint.x;
      //trainDataList >> tempPoint.y;

      //temp.centerPoint.push_back(tempPoint);
      
      //read class name
      trainDataList >> temp.className;
      
      database.add(temp.className);

      //read angle grand truth
      trainDataList >> temp.angle;

      //show read data *for debug
      //temp.showDataset();
     
      tempDataSet.push_back(temp);
    }
    trainDataList.close();
  }
  dataSetNum = tempDataSet.size();
  int dataOffset = 0;
  database.show();
  for(int j = 0;j < database.vNode.size(); j++){
    std::set<int> chosenData = nck.generate(database.vNode.at(j).instances, conf.imagePerTree);
    
    std::set<int>::iterator ite = chosenData.begin();
    
    while(ite != chosenData.end()){
      dataSet.push_back(tempDataSet.at(*ite + dataOffset));
      ite++;
    }
    dataOffset += database.vNode.at(j).instances;
  }

  //in.close();
}