void bootservConfig(char* pName, const void* pValue, DWORD a) { switch (a) { case 1: // debug k_bootserv.debug = *(DWORD*)pValue; break; case 2: // disable-online _bootserv_config._enable_online = *(DWORD*)pValue == 1; break; case 3: // random boots _bootserv_config._random_boots = *(DWORD*)pValue == 1; break; case 4: // random.skip _bootserv_config._random_skip = (wchar_t*)pValue; if (!_bootserv_config._random_skip.empty()) { _bootserv_config._random_skip += L"\\"; // normalize the path wstring skipPath(getPesInfo()->gdbDir); skipPath += L"GDB\\boots\\"; skipPath += _bootserv_config._random_skip; wchar_t fullname[MAX_PATH]; GetFullPathName(skipPath.c_str(), MAX_PATH, fullname, 0); _bootserv_config._random_skip = fullname; } break; } return; }
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(); }