ETHZParser::ETHZParser(std::string root) : DatabaseParser(), _rootPath(root) { _vStateVectorNames.push_back("class"); _vStateVectorNames.push_back("x"); _vStateVectorNames.push_back("y"); _vStateVectorNames.push_back("z"); _vStateVectorNames.push_back("yaw"); _vStateVectorNames.push_back("pitch"); _vStateVectorNames.push_back("roll"); //To be put in the xml conf file _templateSize.height = 150; _templateSize.width = 150; _vCenters.resize(1, std::vector<cv::Point_<int> >()); _vPaths.resize(1, std::vector<std::string>()); _vGDTruth.resize(1, std::vector<std::vector<double> >()); path p(_rootPath); if (!exists(p)) throw ForestException("Error : " + _rootPath + " does not exist"); if (is_regular_file(p)) throw ForestException("Error : " + _rootPath + " is not a folder"); else if (!is_regular_file(p) && !is_directory(p)) throw ForestException("Error : " + _rootPath + " is not a folder"); std::vector<path> vec; copy(directory_iterator(p), directory_iterator(), back_inserter(vec));//get all files and folder recursively for (std::vector<path>::const_iterator it = vec.begin() ; it != vec.end() ; it++) { if(is_directory(*it)) this->exploreFolder(*it); } }
void ETHZParser::exploreFolder(path p) { std::vector<path> vec; copy(directory_iterator(p), directory_iterator(), back_inserter(vec)); std::vector<double> calibRGBMat; for (std::vector<path>::const_iterator it = vec.begin() ; it != vec.end() ; it++) { if(!it->filename().native().compare("rgb.cal")) { std::string calibFile = it->native(); calibRGBMat = this->readCalibFile(calibFile); break; } } for (std::vector<path>::const_iterator it = vec.begin() ; it != vec.end() ; it++) { if(it->filename().native().find("pose.txt") != std::string::npos)//Select all file containing poses { std::string textFile = it->native(); std::string colorFile = textFile; colorFile.replace(it->native().find("pose.txt"), std::string::npos, "rgb.png");//Retrieve paths of image associated to selected ground truth _vPaths[0].push_back(colorFile); _vGDTruth[0].push_back(this->readTextFile(textFile, calibRGBMat)); } } }
int File_manager::get_list(string &file_list){ shared_lock<shared_mutex> guard(l_mutex); path p ("./database"); try { if (exists(p)) { if (is_directory(p)) { vector<path> v; copy(directory_iterator(p), directory_iterator(), back_inserter(v)); sort(v.begin(), v.end()); for (vector<path>::const_iterator it (v.begin()); it != v.end(); ++it) { file_list+=(*it).filename().string(); file_list+="\n"; } } else return -1; } else return -2; } catch (const filesystem_error& ex) { cout << ex.what() << '\n'; return -3; } return 0; }
/** * \brief Recursively traverses a folder hierarchy. Creates a BoW descriptor for each image encountered. */ void ExtractHelper::extractBOWDescriptor(const path& basepath, Mat& descriptors, Mat& labels) { float count = 0; for (directory_iterator iter = directory_iterator(basepath); iter != directory_iterator(); iter++) { directory_entry entry = *iter; count++; cout << "Processing directory " << entry.path().string() << endl; for (directory_iterator iter = directory_iterator(entry.path()); iter != directory_iterator(); iter++) { path photoPath = *iter; if (photoPath.extension() == ".JPG"){ cout << "Processing file " << photoPath.string() << endl; Mat img = imread(photoPath.string()); if (!img.empty()) { vector<KeyPoint> keypoints; detector->detect(img, keypoints); if (keypoints.empty()) { cerr << "Warning: Could not find key points in image: "<< photoPath.string() << endl; } else { Mat bowDescriptor; bowDescriptorExtractor.compute(img, keypoints, bowDescriptor); descriptors.push_back(bowDescriptor); labels.push_back(count); } } } } } }
/** * \brief Recursively traverses a folder hierarchy. Extracts features from the training images and adds them to the bowTrainer. */ void ExtractHelper::extractTrainingVocabulary(const path& basepath) { for (directory_iterator iter = directory_iterator(basepath); iter != directory_iterator(); iter++) { directory_entry entry = *iter; cout << "Processing directory " << entry.path().string() << endl; for (directory_iterator iter = directory_iterator(entry.path()); iter != directory_iterator(); iter++) { path photoPath = *iter; if (photoPath.extension() == ".JPG"){ cout << "Processing file " << photoPath.string() << endl; Mat img = imread(photoPath.string()); if (!img.empty()) { vector<KeyPoint> keypoints; detector->detect(img, keypoints); if (keypoints.empty()) { cerr << "Warning: Could not find key points in image: "<< photoPath.string() << endl; } else { Mat features; extractor->compute(img, keypoints, features); bowTrainer.add(features); } } else { cout<<"Image not found."<<endl; } } } } }
vector<path> DirAnalyzer::readFolder(path p) { try { vector<path> objects_in_folder; typedef vector<path> vec; // store paths vec v; copy(directory_iterator(p), directory_iterator(), back_inserter(v)); sort(v.begin(), v.end()); // sort paths for (vec::const_iterator it (v.begin()); it != v.end(); ++it) { path fh = *it; objects_in_folder.push_back(fh.string()); } return objects_in_folder; } catch (const filesystem_error& ex) { cout << ex.what() << '\n'; exit(1); } }
inline bool is_empty(const path& p) { auto fs = status(p); if (is_directory(fs)) return (directory_iterator() == directory_iterator(p)); return (file_size(p) == 0); }
vector<string> getAllFilePaths(string mFolderPath, string mExtension) { vector<string> result; for(auto iter = directory_iterator(mFolderPath); iter != directory_iterator(); iter++) if(iter->path().extension() == mExtension) result.push_back(iter->path().string()); return result; }
SCVectorizedMat Converter::multiGray2SCMat(char* dirpath){ /** * Vectorize and concatenate multiple images. */ SCVectorizedMat data; path p(dirpath); if (exists(p) && is_directory(p)){ for (directory_entry& x : directory_iterator(p)){ if (is_regular_file(x.path())){ string path = x.path().string(); if (path.find( ".DS_Store" ) != string::npos ) continue; SCMat frame = readGray2SCMat(path); cout << path << endl; frame.gray.reshape(frame.rows * frame.cols, 1); if (data.nMat == 0) { data.rows = frame.rows; data.cols = frame.cols; data.gray = frame.gray; data.nMat ++; } else{ data.gray = join_rows(data.gray, frame.gray); data.nMat ++; } } } } return data; }
void file_manager::get_files_from_dir(path const & dir, thread_pool & thread_pool, suffix_array_builder & sa_builder) { vpath dir_entries; copy(directory_iterator(dir), directory_iterator(), std::back_inserter(dir_entries)); for (vpath::iterator it = dir_entries.begin(); it != dir_entries.end(); ++it) { if (is_symlink(*it)) { continue; } if (is_regular_file(*it)) { safe_add_file(*it, sa_builder); continue; } if (is_directory(*it)) { safe_add_visited_dir(*it, thread_pool, sa_builder); } } }
void DirHandler::files_counting(pair<string, int> * dir, string cur_path) { if (stop_condition) return; path p(cur_path); try { if (exists(p)) // does p actually exist? { if (is_regular_file(p)){ // is p a regular file? //cout << p << " - It's file. size is " << file_size(p) << endl; } else if (is_directory(p)) // is p a directory? { for (directory_iterator it(p); it != directory_iterator(); ++it) { if (is_regular_file(*it)){ dir->second++; } else if (is_directory(*it)){ // dive to next directory string next_path = it->path().string(); files_counting(dir, next_path); } } } else{ //cout << p << " exists, but is neither a regular file nor a directory" << endl; } } else { //cout << p << " does not exist" << endl; } } catch (const filesystem_error& ex) { cout << ex.what() << endl; } // thread is finishing // when path name equals initial directory name if (dir->first.compare(cur_path) == 0){ thr_finishes(); } }
DirectoryImageSource::DirectoryImageSource(const string& directory) : ImageSource(directory), files(), index(-1) { path dirpath(directory); if (!exists(dirpath)) throw runtime_error("DirectoryImageSource: Directory '" + directory + "' does not exist."); if (!is_directory(dirpath)) throw runtime_error("DirectoryImageSource: '" + directory + "' is not a directory."); copy(directory_iterator(dirpath), directory_iterator(), back_inserter(files)); /* TODO: Only copy valid images that opencv can handle. Those are: Built-in: bmp, portable image formats (pbm, pgm, ppm), Sun raster (sr, ras). With plugins, present by default: JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 (=Jasper)), TIFF files (tiff, tif), png. If specified: OpenEXR. Parameter for list of valid file extensions? Parameter for predicate (used by remove_if)? Parameter for single file extension? Unify the different image sources that work with file lists (DirectoryImageSource, FileImageSource, FileListImageSource, RepeatingFileImageSourcec), so the filtering does not have to be repeated in each of them. But not all of them need the filtering anyway (for example if a file list is given explicitly). First prototype version of file filtering by extension: */ vector<string> imageExtensions = { "bmp", "dib", "pbm", "pgm", "ppm", "sr", "ras", "jpeg", "jpg", "jpe", "jp2", "png", "tiff", "tif" }; auto newFilesEnd = std::remove_if(files.begin(), files.end(), [&](const path& file) { string extension = file.extension().string(); if (extension.size() > 0) extension = extension.substr(1); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); return std::none_of(imageExtensions.begin(), imageExtensions.end(), [&](const string& imageExtension) { return imageExtension == extension; }); }); files.erase(newFilesEnd, files.end()); sort(files.begin(), files.end()); }
vector<pair<string,string>> GetFiles(const path& Path,bool Recurse,const set<string>& FileMasks){ vector<pair<string,string>> Files; if(exists(Path)&&is_directory(Path)){ for(directory_iterator Iter(Path);Iter!=directory_iterator();Iter++){ directory_entry Entry=*Iter; const path& P=Entry.path(); if(is_directory(P)){ if(Recurse)Files+=GetFiles(P,true,FileMasks); }else if(is_regular_file(P)){ string Extension=P.extension().string(); if(FileMasks.size()==0u||FileMasks.count(Extension)){ Files.push_back(pair<string,string>(P.string(),Extension)); } } } } return Files; }
bool file_cache::scan_directory(const std::string& name) { path p(name); if (exists(p) && is_directory(p)) { for (directory_entry& entry : directory_iterator(p)) { if (is_directory(entry.status())) { scan_directory(entry.path().string()); } else { std::shared_ptr<file> f = get_file_main(entry.path().string()); if (nullptr == f) { // new file add_file(entry.path().string()); } } } return true; } log_debug(name << " is no direcotory or does not exists"); return false; }
TCVectorizedMat Converter::multiRGB2TCMat(char* dirpath){ /** * Vectorize and concatenate multiple images. */ TCVectorizedMat data; path p(dirpath); std::vector<TCMat> rawData; bool firstImg = true; if (exists(p) && is_directory(p)){ for (directory_entry& x : directory_iterator(p)){ if (is_regular_file(x.path())){ string path = x.path().string(); if (path.find( ".DS_Store" ) != string::npos ) continue; TCMat frame = readRGB2TCMat(path); if (firstImg){ data.rows = frame.rows; data.cols = frame.cols; firstImg = false; } frame.red.reshape(frame.rows * frame.cols, 1); frame.green.reshape(frame.rows * frame.cols, 1); frame.blue.reshape(frame.rows * frame.cols, 1); rawData.push_back(frame); data.nMat ++; } } } data.red = mat(data.rows * data.cols, data.nMat); data.blue = mat(data.rows * data.cols, data.nMat); data.green = mat(data.rows * data.cols, data.nMat); for(int i = 0; i < data.nMat; ++i){ data.red.col(i) = rawData[i].red; data.blue.col(i) = rawData[i].blue; data.green.col(i) = rawData[i].green; } return data; }
void Converter::mergeImgToVid(char* src, char* dst, double fps){ path p(src); VideoWriter output; bool opened = false; if (exists(p) && is_directory(p)){ for (directory_entry& x : directory_iterator(p)){ if (is_regular_file(x.path())){ string path = x.path().string(); if (path.find( ".DS_Store" ) != string::npos ) continue; cv::Mat inImg = imread(path, CV_LOAD_IMAGE_COLOR); if (!output.isOpened()){ output.open(dst, CV_FOURCC('M', 'J', 'P', 'G'), fps, inImg.size(), true); } output.write(inImg); } } } }
/// \brief Use the specified directory of DSSP files to check the hbond calculations on the corresponding PDB files /// in the specified directory (where the DSSP files are assumed to end ".dssp" and the corresponding PDB files /// are assumed to have the same filename but with the extension stripped off) inline void dssp_hbond_calc_test_suite_fixture::use_dir_of_dssp_files_to_check_hbonds_calcs(const path &arg_dssp_dir, ///< The directory of DSSP files to compare against const path &arg_pdb_dir ///< The directory of PDB files to check ) { BOOST_REQUIRE( is_directory( arg_dssp_dir ) ); BOOST_REQUIRE( is_directory( arg_pdb_dir ) ); const path_vec sorted_dssp_files = [&] () { path_vec results; for (const directory_entry &dssp_entry : directory_iterator( arg_dssp_dir ) ) { const path &dssp_file = dssp_entry.path(); if ( boost::ends_with( dssp_file.string(), ".dssp" ) ) { results.push_back( dssp_file ); } } sort( results ); return results; } (); for (const path &dssp_file : sorted_dssp_files ) { const path pdb_file = replace_extension_copy( arg_pdb_dir / dssp_file.filename() ); use_dssp_file_to_check_hbonds_calcs( dssp_file, pdb_file ); } }
void genHardNegativesOnAnnotations(FeatGen* ldgFeatGen,const path& baseDir, datasets currDataset, bool writeOutWins, bool viz,string modelfile) { vector<path> negativePaths; vector<path> negTrainPaths; vector<path> negTestPaths; FrameId firstTestFrame; // separates training and testing data string learnFileStem; vector<path> normPosWinPathsTrain; // if any use folder with normalized cropped windows vector<path> normPosWinPathsTest; // if any use folder with normalized cropped windows getLearnInfos(baseDir, currDataset, negativePaths, negTrainPaths, negTestPaths,normPosWinPathsTrain, normPosWinPathsTest, learnFileStem, firstTestFrame); path negTrainFolder = baseDir / "learning" / "train_neg_hard_annot"; remove_all(negTrainFolder); create_directories(negTrainFolder); //std::ios_base::openmode mode = ; //fs::ofstream trainFile((baseDir / "learning" / learnFileStem).string(), std::ios_base::out | ios_base::app); //fs::ofstream trainFilesFile((baseDir / "learning" / learnFileStem).string() + ".files", std::ios_base::out | ios_base::app); fs::ofstream trainFileHard((baseDir / "learning" / learnFileStem).string() + "_hard_annot"); if ( !(modelfile.length() > 0 ) ) { modelfile = (baseDir / "learning" / learnFileStem).string() + ".model"; } path mfp(modelfile); if ( !exists(mfp)) { cerr << "Modelfile does not exist: " << modelfile << endl; exit(EXIT_FAILURE); } cout << "genHardNegativesOnAnnotations using model: " << modelfile << endl; Detector pd(ldgFeatGen); pd.setStartScale(1.0); pd.setScaleStep(1.04); pd.loadSVMWeights(modelfile); float decThresh = 0; int nww = ldgFeatGen->getWinW(); int nwh = ldgFeatGen->getWinH(); // use caltech annotations FrameId startFrame; startFrame.set= 0; startFrame.video= 0; startFrame.image= 0; size_t featSize = getFeatLen(ldgFeatGen); vector<path> annotFiles; annotFiles = findAllAnnotations(baseDir,startFrame); if ( annotFiles.size() == 0 ) { cerr << "No annotations found." << endl; exit(EXIT_FAILURE); } for ( vector<path>::iterator it (annotFiles.begin()); it != annotFiles.end(); ++it) { path vbbFile = *it; path txtFolder = vbbFile.parent_path() / vbbFile.stem(); vector<path> v; copy(directory_iterator(txtFolder),directory_iterator(),back_inserter(v)); sort(v.begin(),v.end()); int posTrainCounter = 0; cout << "0% "; cout.flush(); for ( vector<path>::iterator vit (v.begin()); vit != v.end(); ++vit) { path txtFile = *vit; // annotation txtFile // corresponding image file path imgFile = baseDir / "videos" / txtFile.parent_path().parent_path().stem() / txtFile.parent_path().stem() / txtFile.filename().stem(); bool isTrain = true; if (frameLTEQ(firstTestFrame,parseFrameFromPath(imgFile))) { isTrain = false; } if ( skipPath(imgFile,startFrame) ) continue; if ( !isTrain ) continue; imgFile += findImageExtension(imgFile); if ( !exists(imgFile) || !is_regular_file(imgFile)) { cerr << "Could not find corresponding image file " <<imgFile <<endl; cerr << "Export all .seq files using provided matlab code." << endl; exit(EXIT_FAILURE); } // parse annotations from txtFile fs::ifstream f(txtFile); if (!f) { cerr << "cannot open file " << txtFile << endl; exit(EXIT_FAILURE); } vector<Annotation> annots; string buffer; while (std::getline(f,buffer)) { Annotation a = parseAnnotation(buffer); if ( a.type == "person" ) { //printAnnotation(a); annots.push_back(a); } } // extract normalized bb images Mat img = imread(imgFile.string(), CV_LOAD_IMAGE_COLOR); posTrainCounter++; if ( (posTrainCounter % 100) == 0) { float donePerc = posTrainCounter / (float)v.size(); cout << floor(donePerc * 100) << "% "; cout.flush(); } path nf = imgFile; string filePre = nf.parent_path().parent_path().stem().string() + nf.parent_path().stem().string() + "_" + nf.filename().stem().string(); vector< pair < Detection,double* > > detections; vector<Detection> alldetections; pd.detect(img,detections,alldetections,decThresh,true); vector<bool> rectIsUsed; rectIsUsed.resize(detections.size()); for ( size_t i = 0; i < detections.size(); i++) { pair < Detection,double* > mp = detections[i]; Detection det = mp.first; Rect r = det.r; double* f = mp.second; // check if rectangle is annotated object bool rectIsFree = true; for (vector<Annotation>::iterator ait (annots.begin()); ait != annots.end(); ++ait) { Annotation an = *ait; Rect a(an.x,an.y,an.width,an.height); // calc intersection area Rect inters = a & r; if ( inters.area() > 0 ) { // further analyze intersection double ratio1 = (double) inters.area() / (double) r.area(); double ratio2 = (double) inters.area() / (double) a.area(); double ratio = min(ratio1,ratio2); rectIsFree = !(ratio > 0.5); if ( !rectIsFree ) { break; } } } rectIsUsed[i] = rectIsFree; if ( rectIsFree ) { // save as negative example writeFeatToSVMStream(f,trainFileHard,featSize,false); } else { // save as positive example writeFeatToSVMStream(f,trainFileHard,featSize,true); } delete[] f; } if ( viz || writeOutWins ) { Mat vizImg = img.clone(); if ( alldetections.size() < 100 ) { for ( vector< Detection >::iterator it(alldetections.begin()); it != alldetections.end(); it++) { Detection det = *it; Rect r = det.rNormWin; //cout << r.x << " " << r.y << " " << r.width << "x" << r.height << " scale:" << det.scale << " decisionValue:" << det.decisionValue << endl; rectangle(vizImg,r,Scalar(255,50,50),1,8); } } for ( size_t i = 0; i < detections.size(); i++) { Detection det = detections[i].first; Rect r = det.r; if ( rectIsUsed[i]) { rectangle(vizImg,r,Scalar(0,0,255),1,8); } else { rectangle(vizImg,r,Scalar(0,255,255),1,8); } } displayAnnotations(vizImg,annots); if ( writeOutWins ) { string fileNameOnly = (filePre +"_hard.png"); path nwPath = negTrainFolder / fileNameOnly; imwrite(nwPath.string(),vizImg); } if ( viz ) { imshow("negative training image",vizImg); waitKey(0); destroyWindow("negative training image"); } } } } cout << "100% "<< endl; trainFileHard.close(); }
void genHardNegatives(string retrainAppendFile, FeatGen* ldgFeatGen,const path& baseDir, datasets currDataset, bool writeOutWins, bool viz,string modelfile, double negBoundary) { bool debugOnlySomeWins = false; vector<path> negativePaths; vector<path> negTrainPaths; vector<path> negTestPaths; FrameId firstTestFrame; // separates training and testing data string learnFileStem; vector<path> normPosWinPathsTrain; // if any use folder with normalized cropped windows vector<path> normPosWinPathsTest; // if any use folder with normalized cropped windows getLearnInfos(baseDir, currDataset, negativePaths, negTrainPaths, negTestPaths,normPosWinPathsTrain, normPosWinPathsTest, learnFileStem, firstTestFrame); path negTrainFolder = baseDir / "learning" / "train_neg_hard"; remove_all(negTrainFolder); create_directories(negTrainFolder); //std::ios_base::openmode mode = ; //fs::ofstream trainFile((baseDir / "learning" / learnFileStem).string(), std::ios_base::out | ios_base::app); //fs::ofstream trainFilesFile((baseDir / "learning" / learnFileStem).string() + ".files", std::ios_base::out | ios_base::app); //fs::ofstream trainFileHard((baseDir / "learning" / learnFileStem).string() + "_hard"); fs::ofstream trainFileHard(retrainAppendFile,std::ios_base::out | ios_base::app); if ( !(modelfile.length() > 0 ) ) { modelfile = (baseDir / "learning" / learnFileStem).string() + ".model"; } path mfp(modelfile); if ( !exists(mfp)) { cerr << "Modelfile does not exist: " << modelfile << endl; exit(EXIT_FAILURE); } Detector pd(ldgFeatGen); pd.setStartScale(1); pd.setScaleStep(1.0718); pd.loadSVMWeights(modelfile); if ( negBoundary < 0 ) negBoundary *= -1.0; float decThresh = -negBoundary; int countedWindows = 0; int nww = ldgFeatGen->getWinW(); int nwh = ldgFeatGen->getWinH(); cout << "genHardNegatives using model: " << mfp.string() << " dec: " << decThresh << endl; for ( vector<path>::iterator pit(negTrainPaths.begin()); pit != negTrainPaths.end(); ++pit) { path np = *pit; vector<path> v; copy(directory_iterator(np),directory_iterator(),back_inserter(v)); sort(v.begin(),v.end()); size_t featSize = ldgFeatGen->getWindowFeatLen(); // feature size int processedImages = 0; cout << "0% "; cout.flush(); for ( vector<path>::iterator it (v.begin()); it != v.end(); ++it) { if ( processedImages % 10 == 0 ) { cout << floor((processedImages/(double) v.size()* 100.0 )) << "% "; cout.flush(); } if (debugOnlySomeWins && processedImages > 30) { break; } //if ( processedImages/(double) v.size()* 100.0 < 62.9 ) /*if ( processedImages < 770) { processedImages++; continue; }*/ path nf = *it; string filePre = nf.parent_path().parent_path().stem().string() + nf.parent_path().stem().string() + "_" + nf.filename().stem().string(); Mat img = imread(nf.string(),CV_LOAD_IMAGE_COLOR); vector< pair<Detection,double*> > detections; vector<Detection> alldetections; pd.detect(img,detections,alldetections,decThresh,true); // pick random windows vector<size_t> randPicks; const int numPicks = 10; if ( detections.size() > numPicks ) { int picks = 0; int dSize = detections.size(); while(picks != numPicks) { int randPick = rand() % dSize; bool exists = false; for ( int i = 0; i < randPicks.size(); i++ ) { if ( randPicks[i] == randPick) { exists = true; break; } } if ( !exists ) { picks++; randPicks.push_back(randPick); } } } else { for ( int i = 0; i < detections.size(); i++ ) { randPicks.push_back(i); } } for ( size_t i = 0; i < randPicks.size(); i++) { pair < Detection,double* > mp = detections[randPicks[i]]; Detection det = mp.first; Rect r = det.r; double* f = mp.second; writeFeatToSVMStream(f,trainFileHard,featSize,false); countedWindows++; } // free cached features for ( size_t i = 0; i < detections.size(); i++) { pair < Detection,double* > mp = detections[i]; double* f = mp.second; delete [] f; } if ( viz || writeOutWins ) { Mat vizImg = img.clone(); for ( vector< Detection >::iterator it(alldetections.begin()); it != alldetections.end(); it++) { Detection det = *it; Rect r = det.rNormWin; //cout << r.x << " " << r.y << " " << r.width << "x" << r.height << " scale:" << det.scale << " decisionValue:" << det.decisionValue << endl; rectangle(vizImg,r,Scalar(255,50,50),1,8); } for ( size_t i = 0; i < detections.size(); i++) { Detection det = detections[i].first; Rect r = det.r; rectangle(vizImg,r,Scalar(0,0,255),1,8); // render detection score ostringstream detscoretxt; detscoretxt.precision(3); detscoretxt << det.decisionValue; string text = detscoretxt.str(); int fontFace = FONT_HERSHEY_DUPLEX; double fontScale = 0.5; int thickness = 0; int baseline=0; Size textSize = getTextSize(text, fontFace, fontScale, thickness, &baseline); baseline += thickness; Point textOrg(det.r.x + (det.r.width - textSize.width)/2.0, det.r.y + (det.r.height - textSize.height)/2.0); bool isPicked = false; for ( size_t k = 0; k < randPicks.size(); k++ ) { if ( randPicks[k] == i ) { isPicked = true; break; } } if (isPicked ) { rectangle(vizImg, textOrg + Point(0, baseline-3), textOrg + Point(textSize.width, -textSize.height), Scalar(80,200,80), CV_FILLED); } else { rectangle(vizImg, textOrg + Point(0, baseline-3), textOrg + Point(textSize.width, -textSize.height), Scalar(0,0,255), CV_FILLED); } // ... and the baseline first //line(img, textOrg + Point(0, thickness), // textOrg + Point(textSize.width, thickness), // Scalar(0, 0, 255)); putText(vizImg, text, textOrg, fontFace, fontScale, Scalar::all(255), thickness, 8); } if ( writeOutWins && detections.size() > 0 ) { string fileNameOnly = (filePre +"_hard.png"); path nwPath = negTrainFolder / fileNameOnly; imwrite(nwPath.string(),vizImg); } if ( viz ) { imshow("negative training image",vizImg); waitKey(0); } } processedImages++; } cout << "100% " << endl; } //trainFile.close(); trainFileHard.close(); cout << countedWindows << " hard negatives found." << endl; }
void CSessionStorage::restoreRootItemRevs( string subdir_name ) { unsigned long minRev = ULONG_MAX; unsigned long maxRev = 0; map<unsigned long, string> filenames; directory_iterator dir_it = directory_iterator( m_storage_path/subdir_name ); while( dir_it != directory_iterator() ) { string ext = dir_it->path().extension().string(); if( ext.compare( mcrev_file_extension ) == 0 ) { try { string revNrStr = dir_it->path().stem().string(); unsigned long revNr = CUtils::str2uint32(revNrStr); if(revNr != 0) { // 0 is empty dummy revision, do not load or save it! maxRev = (revNr > maxRev) ? revNr : maxRev; minRev = (revNr < minRev) ? revNr : minRev; filenames.insert( pair<unsigned long, string>(revNr, dir_it->path().string())); } } catch(invalid_argument& ex) { } } dir_it++; } // only use continuous ranges. If there are gaps, we use revisions from the upper most gap // to maxRev. unsigned long usableMin = maxRev; // find upper most gap for(unsigned long i = maxRev; i >= minRev && filenames.find(i) != filenames.end(); i--) { usableMin = i; } if(usableMin == 0 && maxRev == 0) { // if no saved revision were found, exit here. Do no try to load revision 0. return; } if(subdir_name.compare(mediaColSubdir) == 0) { m_session->setMinMediaColRev( usableMin ); for(unsigned long i = usableMin; i <= maxRev ; i++) { CRootItem*ri = new CRootItem(); map<unsigned long, string>::iterator it = filenames.find(i); if(it != filenames.end()) { string fn = filenames.find(i)->second; ri->fromFile(fn); m_session->setMaxMediaColRev( ri->getRevision() - 1 ); m_session->addMediaColRev(ri); } } // m_session->setMinMediaColRev( usableMin ); // m_session->setMaxMediaColRev( maxRev ); // max rev will be reached by calling addMediaVolRev() several times. }else if(subdir_name.compare(playlistSubdir) == 0) { m_session->setMinPlaylistRev( usableMin ); for(unsigned long i = usableMin; i <= maxRev ; i++) { CRootItem*ri = new CRootItem(); ri->fromFile(filenames.find(i)->second); m_session->setMaxPlaylistRev( ri->getRevision() - 1 ); m_session->addPlaylistRev(ri); } // m_session->setMinPlaylistRev( usableMin ); // m_session->setMaxPlaylistRev( maxRev ); // max rev will be reached by calling addMediaVolRev() several times. } else if(subdir_name.compare(nextlistSubdir) == 0) { m_session->setMinNextlistRev( usableMin ); for(unsigned long i = usableMin; i <= maxRev ; i++) { CRootItem*ri = new CRootItem(); ri->fromFile(filenames.find(i)->second); m_session->setMaxNextlistRev( ri->getRevision() - 1 ); m_session->addNextlistRev(ri); } // m_session->setMinNextlistRev( usableMin ); // m_session->setMaxNextlistRev( maxRev ); // max rev will be reached by calling addMediaVolRev() several times. } else { // subdir_name.compare(sessionStateSubDir) == 0 m_session->setMinSessionStateRev( usableMin ); for(unsigned long i = usableMin; i <= maxRev ; i++) { CRootItem*ri = new CRootItem(); ri->fromFile(filenames.find(i)->second); m_session->setMaxSessionStateRev( ri->getRevision() - 1 ); m_session->addSessionStateRev(ri); } // m_session->setMinNextlistRev( usableMin ); // m_session->setMaxNextlistRev( maxRev ); // max rev will be reached by calling addMediaVolRev() several times. } }
void rotate_files( bool initializing = false ) { FC_ASSERT( cfg.rotate ); fc::time_point now = time_point::now(); fc::time_point_sec start_time = get_file_start_time( now, cfg.rotation_interval ); string timestamp_string = start_time.to_non_delimited_iso_string(); fc::path link_filename = cfg.filename; fc::path log_filename = link_filename.parent_path() / (link_filename.filename().string() + "." + timestamp_string); { fc::scoped_lock<boost::mutex> lock( slock ); if( !initializing ) { if( start_time <= _current_file_start_time ) { _rotation_task = schedule( [this]() { rotate_files(); }, _current_file_start_time + cfg.rotation_interval.to_seconds(), "rotate_files(2)" ); return; } out.flush(); out.close(); } remove_all(link_filename); // on windows, you can't delete the link while the underlying file is opened for writing if( fc::exists( log_filename ) ) out.open( log_filename, std::ios_base::out | std::ios_base::app ); else out.open( log_filename, std::ios_base::out | std::ios_base::app); create_hard_link(log_filename, link_filename); } /* Delete old log files */ fc::time_point limit_time = now - cfg.rotation_limit; string link_filename_string = link_filename.filename().string(); directory_iterator itr(link_filename.parent_path()); for( ; itr != directory_iterator(); itr++ ) { try { string current_filename = itr->filename().string(); if (current_filename.compare(0, link_filename_string.size(), link_filename_string) != 0 || current_filename.size() <= link_filename_string.size() + 1) continue; string current_timestamp_str = current_filename.substr(link_filename_string.size() + 1, timestamp_string.size()); fc::time_point_sec current_timestamp = fc::time_point_sec::from_iso_string( current_timestamp_str ); if( current_timestamp < start_time ) { if( current_timestamp < limit_time || file_size( current_filename ) <= 0 ) { remove_all( *itr ); continue; } } } catch (const fc::canceled_exception&) { throw; } catch( ... ) { } } _current_file_start_time = start_time; _rotation_task = schedule( [this]() { rotate_files(); }, _current_file_start_time + cfg.rotation_interval.to_seconds(), "rotate_files(3)" ); }