void HPE_parseImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); unsigned int i=0; vector<string> fileNames; getDirList(path, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { string &file = *it, ext; size_t len = file.length(); if (len>4) { ext = file.substr(len-4, 4); } if (ext==".jpg") { Ptr<HPE_parseObj> curr(new HPE_parseObj); curr->name = file; if (i<100) { train.back().push_back(curr); } else { test.back().push_back(curr); } ++i; } } }
String SensorFileSysWalker::getFileUpDown( String file , int move ) { ASSERTMSG( move != 0 , "Unexpected" ); String dir = getDir( file ); StringList files; // read directory getDirList( dir , files ); // find current index String fileOnly = getFileOnly( file ); int index = files.find( fileOnly ); ASSERTMSG( index >= 0 , "Unexpected: " + file ); int indexMove = ( move > 0 )? ( ( files.count() - index ) * move ) / 100 : ( index * move ) / 100; // assure at least move by 1 if( indexMove == 0 ) indexMove = ( move > 0 )? 1 : -1; index += indexMove; if( index < 0 ) index = 0; else if( index >= files.count() ) index = files.count() - 1; String fileNew = dir + "\\" + files.get( index ); return( fileNew ); }
void OR_sunImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); string classNameFile(path + "ClassName.txt"); ifstream infile(classNameFile.c_str()); string line; while (getline(infile, line)) { Ptr<OR_sunObj> curr(new OR_sunObj); curr->name = line; string currPath(path + curr->name); vector<string> fileNames; getDirList(currPath, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { curr->imageNames.push_back(*it); } train.back().push_back(curr); } }
void SensorFileSysWalker::sendNewDirectoryInfo() { logger.logInfo( "sendNewDirectoryInfo: execute..." ); // send current directory list StringList files; getDirList( curDir , files ); for( int k = 0; k < files.count(); k++ ) { String file = files.get( k ); sendSignal( SIGNAL_DIR_LISTITEM , file ); } }
void GR_skigImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); for (unsigned int i=1; i<=6; ++i) { char number[2]; sprintf(number, "%u", i); string pathDatasetRgb(path + "subject" + number + "_rgb/"); string pathDatasetDep(path + "subject" + number + "_dep/"); vector<string> fileNames; getDirList(pathDatasetRgb, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { string &file = *it; Ptr<GR_skigObj> curr(new GR_skigObj); curr->rgb = pathDatasetRgb + file; curr->dep = file; curr->dep[0] = 'K'; curr->dep = pathDatasetDep + curr->dep; size_t posPerson = file.find("person_"); size_t posBackground = file.find("backgroud_"); size_t posIllumination = file.find("illumination_"); size_t posPose = file.find("pose_"); size_t posType = file.find("actionType_"); if (string::npos != posPerson && string::npos != posBackground && string::npos != posIllumination && string::npos != posPose && string::npos != posType) { curr->person = (unsigned char)atoi( file.substr(posPerson + strlen("person_"), 1).c_str() ); curr->background = (backgroundType)atoi( file.substr(posBackground + strlen("backgroud_"), 1).c_str() ); curr->illumination = (illuminationType)atoi( file.substr(posIllumination + strlen("illumination_"), 1).c_str() ); curr->pose = (poseType)atoi( file.substr(posPose + strlen("pose_"), 1).c_str() ); curr->type = (actionType)atoi( file.substr(posType + strlen("actionType_"), 2).c_str() ); train.back().push_back(curr); } else { printf("incorrect file name: %s", file.c_str()); } } } }
//--------------------------------------------------------------------------- // addDirList //--------------------------------------------------------------------------- IPropertyTree* addDirList(const char* comp, const char* path) { // Get or add Component node IPropertyTree* compNode = addComponent(comp); assertex(compNode); // Add new Directory node assertex(path); char ppath[_MAX_PATH]; strcpy(ppath, path); removeTrailingPathSepChar(ppath); IPropertyTree* node = createPTree("Directory"); node->addProp("@name", ppath); getDirList(ppath, node); return compNode->addPropTree("Directory", node); }
void IR_affineImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); // detect image extension string ext; vector<string> fileNames; getDirList(path, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { string &name = *it; if (name.length()>=8 && name.substr(0, 3)=="img") { ext = name.substr(name.length()-4, 4); break; } } for (unsigned int i=1; i<=6; ++i) { Ptr<IR_affineObj> curr(new IR_affineObj); char tmp[2]; sprintf(tmp, "%u", i); curr->imageName = path + "img" + tmp + ext; if (i>1) { string matName(path + "H1to" + tmp + "p"); ifstream infile(matName.c_str()); for (int k=0; k<3; ++k) { for (int j=0; j<3; ++j) { infile >> curr->mat(k, j); } } } train.back().push_back(curr); }
int pushDirs(CollectionType collectionType, CollectionItemType itemType, std::list<std::pair<std::string, std::string> > * const lst, KIM::Log * const log) { std::map<CollectionType, std::string> collectionStrings; collectionStrings[KIM_CWD] = "CWD"; collectionStrings[KIM_ENVIRONMENT] = "environment"; collectionStrings[KIM_USER] = "user"; collectionStrings[KIM_SYSTEM] = "system"; std::string dirList; if (getDirList(collectionType, itemType, &dirList, log)) return true; std::istringstream iss(dirList); std::string token; while (std::getline(iss, token, ':')) { lst->push_back(std::make_pair(collectionStrings[collectionType], token)); } return false; }
void IS_weizmannImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); vector<string> fileNames; getDirList(path, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { string &imageName = *it; if (imageName.find('.') == string::npos) // only folders, discard .mat { Ptr<IS_weizmannObj> curr(new IS_weizmannObj); curr->imageName = imageName; curr->srcBw = imageName + "/src_bw/" + imageName + ".png"; curr->srcColor = imageName + "/src_color/" + imageName + ".png"; curr->humanSeg = imageName + "human_seg/"; train.back().push_back(curr); } } }
void GameStateLoad::readGameSlots() { FileParser infile; std::stringstream filename; std::vector<std::string> save_dirs; getDirList(PATH_USER + "saves/" + SAVE_PREFIX, save_dirs); std::sort(save_dirs.begin(), save_dirs.end(), compareSaveDirs); game_slots.resize(save_dirs.size(), NULL); visible_slots = (game_slot_max > static_cast<int>(game_slots.size()) ? static_cast<int>(game_slots.size()) : game_slot_max); for (size_t i=0; i<save_dirs.size(); ++i){ // save data is stored in slot#/avatar.txt filename.str(""); filename << PATH_USER << "saves/" << SAVE_PREFIX << "/" << save_dirs[i] << "/avatar.txt"; if (!infile.open(filename.str(),false)) continue; game_slots[i] = new GameSlot(); game_slots[i]->id = toInt(save_dirs[i]); while (infile.next()) { // load (key=value) pairs if (infile.key == "name") game_slots[i]->stats.name = infile.val; else if (infile.key == "class") { game_slots[i]->stats.character_class = popFirstString(infile.val); game_slots[i]->stats.character_subclass = popFirstString(infile.val); } else if (infile.key == "xp") game_slots[i]->stats.xp = toInt(infile.val); else if (infile.key == "build") { for (size_t j = 0; j < PRIMARY_STATS.size(); ++j) { game_slots[i]->stats.primary[j] = popFirstInt(infile.val); } } else if (infile.key == "equipped") { std::string repeat_val = popFirstString(infile.val); while (repeat_val != "") { game_slots[i]->equipped.push_back(toInt(repeat_val)); repeat_val = popFirstString(infile.val); } } else if (infile.key == "option") { game_slots[i]->stats.gfx_base = popFirstString(infile.val); game_slots[i]->stats.gfx_head = popFirstString(infile.val); game_slots[i]->stats.gfx_portrait = popFirstString(infile.val); } else if (infile.key == "spawn") { game_slots[i]->current_map = getMapName(popFirstString(infile.val)); } else if (infile.key == "permadeath") { game_slots[i]->stats.permadeath = toBool(infile.val); } } infile.close(); game_slots[i]->stats.recalc(); game_slots[i]->stats.direction = 6; game_slots[i]->preview.setStatBlock(&(game_slots[i]->stats)); loadPreview(game_slots[i]); } }
void PD_caltechImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); createDirectory((path + "../images/")); vector<string> objectNames; getDirList(path, objectNames); for (vector<string>::iterator it=objectNames.begin(); it!=objectNames.end(); ++it) { Ptr<PD_caltechObj> curr(new PD_caltechObj); curr->name = *it; string objectPath(path + "../images/" + curr->name + "/"); createDirectory(objectPath); string seqImagesPath(path + curr->name + "/"); vector<string> seqNames; getDirList(seqImagesPath, seqNames); for (vector<string>::iterator itSeq=seqNames.begin(); itSeq!=seqNames.end(); ++itSeq) { string &seqName = *itSeq; createDirectory((objectPath + seqName)); FILE *f = fopen((seqImagesPath + seqName).c_str(), "rb"); #define SKIP 28+8+512 fseek(f, SKIP, SEEK_CUR); unsigned int header[9]; size_t res = fread(header, 9, 4, f); double fps; res = fread(&fps, 1, 8, f); fseek(f, 432, SEEK_CUR); /*printf("width %u\n", header[0]); printf("height %u\n", header[1]); printf("imageBitDepth %u\n", header[2]); printf("imageBitDepthReal %u\n", header[3]); printf("imageSizeBytes %u\n", header[4]); printf("imageFormat %u\n", header[5]); printf("numFrames %u\n", numFrames); printf("fps %f\n", fps); printf("trueImageSize %u\n", header[8]);*/ unsigned int numFrames = header[6]; string ext; switch (header[5]) { case 100: case 200: ext = "raw"; break; case 101: ext = "brgb8"; break; case 102: case 201: ext = "jpg"; break; case 103: ext = "jbrgb"; break; case 001: case 002: ext = "png"; break; } for (unsigned int i=0; i<numFrames; ++i) { unsigned int size; res = fread(&size, 1, 4, f); char imgName[20]; sprintf(imgName, "/%u.%s", i, ext.c_str()); curr->imageNames.push_back(imgName); // comment fseek and uncomment next block to unpack all frames fseek(f, size, SEEK_CUR); /*char *img = new char[size]; fread(img, size, 1, f); string imgPath(objectPath + seqName + imgName); FILE *fImg = fopen(imgPath.c_str(), "wb"); fwrite(img, size, 1, fImg); fclose(fImg); delete[] img;*/ fseek(f, 12, SEEK_CUR); } if (0 != res) // should fix unused variable warning { res = 0; } fclose(f); } train.back().push_back(curr); } }
int main(int argc, char *argv[]) { int j; char *to_move; int opcnt, maxops; char path[PATH_MAX]; char tfile[PATH_MAX]; char target[PATH_MAX]; char spath[PATH_MAX]; char *p; int nslashes; int opt; int usecs; char *stopFile; int scnt; opcnt = 0; srandom(0); stopFile = NULL; maxops = 0; usecs = 1; while ((opt = getopt(argc, argv, "l:m:s:z:")) != -1) { switch (opt) { case 's': usecs = atoi(optarg); break; case 'z': stopFile = optarg; break; case 'm': maxops = atoi(optarg); break; case 'l': logfp = fopen(optarg, "w+"); if (logfp == NULL) errExit("fopen"); setbuf(logfp, NULL); break; default: usageError(argv[0]); } } if (optind + 1 >= argc) usageError(argv[0]); opcnt = 0; for (;;) { getDirList(argv[optind]); switch (argv[optind + 1][0]) { case 'c': snprintf(path, sizeof(path), "%s/%ld%s%s_%d", dirList[random() % dcnt], (long) getpid() % 100, MARKER_STRING, "cr", opcnt); if (strlen(path) > DLIM) continue; nslashes = 0; for (p = path; *p; p++) if (*p == '/') nslashes++; if (nslashes > 1) if (random() % nslashes > 0) continue; if (mkdir(path, 0700) == 0) logMessage("mkdir: %s\n", path); scnt = 1; while ((random() % 3) < 2) { snprintf(spath, sizeof(path), "%s/%ld%s%s%d_%d", path, (long) getpid() % 100, MARKER_STRING, "scr", scnt, opcnt); if (strlen(spath) > DLIM) break; if (mkdir(spath, 0700) == 0) logMessage("mkdir: %s\n", spath); strncpy(path, spath, PATH_MAX); path[PATH_MAX - 1] = '\0'; scnt++; } break; case 'd': if (dcnt == 0) continue; snprintf(path, sizeof(path), "%s", dirList[random() % dcnt]); while (strstr(path, MARKER_STRING) != NULL) { if (rmdir(path) == -1) break; logMessage("rmdir: %s\n", path); p = strrchr(path, '/'); if (p == NULL) break; *p = '\0'; } break; case 'm': if (dcnt < 3) continue; to_move = dirList[random() % dcnt]; if (strstr(to_move, MARKER_STRING) != NULL) { p = strrchr(to_move, '/'); snprintf(tfile, sizeof(tfile), "%s", p + 1); p = strstr(tfile, "__ren"); if (p != NULL) *p = '\0'; snprintf(target, sizeof(target), "%s/%s__ren%04d-%ld", dirList[random() % dcnt], tfile, opcnt, (long) getpid()); if (strlen(target) > DLIM) break; if (rename(to_move, target) == 0) logMessage("rename: %s ==> %s\n", to_move, target); } break; } for (j = 0; j < dcnt; j++) { free(dirList[j]); dirList[j] = NULL; } opcnt++; usleep(usecs); if (maxops > 0 && opcnt >= maxops) break; if (access(stopFile, F_OK) == 0) break; } exit(EXIT_SUCCESS); }
void SLAM_tumindoorImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); string infoPath(path + "info/"); // get info map name, .csv should be only one such file in folder string csvName; vector<string> infoNames; getDirList(infoPath, infoNames); for (vector<string>::iterator it=infoNames.begin(); it!=infoNames.end(); ++it) { string &name = *it; if (name.length()>3 && name.substr( name.length()-4, 4 )==".csv") { if (csvName.length()==0) { csvName = name; } else { printf("more than one .csv file in info folder\n"); return; } } } if (csvName.length()==0) { printf("didn't find .csv file in info folder\n"); return; } ifstream infile((infoPath + csvName).c_str()); string line; while (getline(infile, line)) { vector<string> elems; split(line, elems, ';'); Ptr<SLAM_tumindoorObj> curr(new SLAM_tumindoorObj); curr->name = elems[0]; if (curr->name.substr(0, strlen("dslr_left")) == "dslr_left") { curr->type = LEFT; } else if (curr->name.substr(0, strlen("dslr_right")) == "dslr_right") { curr->type = RIGHT; } else { curr->type = LADYBUG; } for (unsigned int i=0; i<4; ++i) { for (unsigned int j=0; j<4; ++j) { curr->transformMat(i, j) = atof(elems[1 + j + i*4].c_str()); } } train.back().push_back(curr); } }