eq::Strings Application::_parseArguments( const int argc, char** argv ) { TCLAP::CmdLine command( "seqPly - Sequel polygonal rendering example", ' ', eq::Version::getString( )); TCLAP::ValueArg<std::string> modelArg( "m", "model", "ply model file name", false, "", "string", command ); TCLAP::VariableSwitchArg ignoreEqArgs( "eq", "Ignored Equalizer options", command ); TCLAP::UnlabeledMultiArg< std::string > ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any", command ); command.parse( argc, argv ); eq::Strings filenames; #ifdef EQ_RELEASE # ifdef _WIN32 // final INSTALL_DIR is not known at compile time filenames.push_back( "../share/Equalizer/data" ); # else filenames.push_back( std::string( EQ_INSTALL_DIR ) + std::string( "share/Equalizer/data" )); filenames.push_back( std::string( "/usr/share/Equalizer/data" )); # endif #else filenames.push_back( std::string( EQ_SOURCE_DIR ) + std::string( "examples/eqPly" )); #endif if( modelArg.isSet( )) { filenames.clear(); filenames.push_back( modelArg.getValue( )); } return filenames; }
void LocalInitData::parseArguments( const int argc, char** argv ) { try { std::string wsHelp = "Window System API ( one of: "; #ifdef AGL wsHelp += "AGL "; #endif #ifdef GLX wsHelp += "glX "; #endif #ifdef WGL wsHelp += "WGL "; #endif wsHelp += ")"; const std::string& desc = EqPly::getHelp(); TCLAP::CmdLine command( desc, ' ', eq::Version::getString( )); TCLAP::MultiArg<std::string> modelArg( "m", "model", "ply model file name or directory", false, "string", command ); TCLAP::ValueArg<std::string> portArg( "p", "port", "tracking device port", false, "/dev/ttyS0", "string", command ); TCLAP::SwitchArg colorArg( "b", "blackAndWhite", "Don't use colors from ply file", command, false ); TCLAP::SwitchArg residentArg( "r", "resident", "Keep client resident (see resident node documentation on website)", command, false ); TCLAP::ValueArg<uint32_t> framesArg( "n", "numFrames", "Maximum number of rendered frames", false, 0xffffffffu, "unsigned", command ); TCLAP::ValueArg<std::string> wsArg( "w", "windowSystem", wsHelp, false, "auto", "string", command ); TCLAP::ValueArg<std::string> modeArg( "c", "renderMode", "Rendering Mode (immediate, displayList, VBO)", false, "auto", "string", command ); TCLAP::SwitchArg glslArg( "g", "glsl", "Enable GLSL shaders", command, false ); TCLAP::SwitchArg invFacesArg( "i", "invertFaces", "Invert faces (valid during binary file creation)", command, false ); TCLAP::ValueArg<std::string> pathArg( "a", "cameraPath", "File containing camera path animation", false, "", "string", command ); TCLAP::SwitchArg overlayArg( "o", "noOverlay", "Disable overlay logo", command, false ); TCLAP::VariableSwitchArg ignoreEqArgs( "eq", "Ignored Equalizer options", command ); TCLAP::UnlabeledMultiArg< std::string > ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any", command ); TCLAP::SwitchArg roiArg( "d", "disableROI", "Disable ROI", command, false ); command.parse( argc, argv ); if( modelArg.isSet( )) { _filenames.clear(); _filenames = modelArg.getValue(); } if( portArg.isSet( )) _trackerPort = portArg.getValue(); if( wsArg.isSet( )) { std::string windowSystem = wsArg.getValue(); transform( windowSystem.begin(), windowSystem.end(), windowSystem.begin(), (int(*)(int))std::toupper ); setWindowSystem( windowSystem ); } _color = !colorArg.isSet(); if( framesArg.isSet( )) _maxFrames = framesArg.getValue(); if( residentArg.isSet( )) _isResident = true; if( modeArg.isSet() ) { std::string mode = modeArg.getValue(); transform( mode.begin(), mode.end(), mode.begin(), (int(*)(int))std::tolower ); if( mode == "immediate" ) setRenderMode( mesh::RENDER_MODE_IMMEDIATE ); else if( mode == "displaylist" ) setRenderMode( mesh::RENDER_MODE_DISPLAY_LIST ); else if( mode == "vbo" ) setRenderMode( mesh::RENDER_MODE_BUFFER_OBJECT ); } if( pathArg.isSet( )) _pathFilename = pathArg.getValue(); if( glslArg.isSet() ) enableGLSL(); if( invFacesArg.isSet() ) enableInvertedFaces(); if( overlayArg.isSet( )) disableLogo(); if( roiArg.isSet( )) disableROI(); } catch( const TCLAP::ArgException& exception ) { LBERROR << "Command line parse error: " << exception.error() << " for argument " << exception.argId() << std::endl; ::exit( EXIT_FAILURE ); } }
int main(int argc, char** argv) { //VL_PRINT ("Hello world!") ; try { TCLAP::CmdLine cmd("EmbAttSpotter tester", ' ', "0.1"); TCLAP::SwitchArg evalF("e","eval","Evaluate against dataset", cmd, false); TCLAP::SwitchArg evalSubF("s","evalSubwordSpotting","Evaluate subword spotting results", cmd, false); TCLAP::SwitchArg evalSubCombF("a","evalSubwordSpottingCombine","Evaluate subword spotting results when combining exemplars", cmd, false); TCLAP::ValueArg<int> primeSubwordArg("p","primeSubword","save the cca att for the given string length", false, -1,"int"); cmd.add( primeSubwordArg ); TCLAP::ValueArg<string> modelArg("l","location","load/save prefix", false,"model/evalGW","string"); cmd.add( modelArg ); TCLAP::SwitchArg testF("t","test","Run unit tests", cmd, false); TCLAP::ValueArg<int> imageArg("i","image","show visual result", false,-1,"int"); cmd.add( imageArg ); TCLAP::ValueArg<int> image2Arg("c","image2","compare images", false,-1,"int"); cmd.add( image2Arg ); TCLAP::ValueArg<string> compare1Arg("1","compare1","1st image for comparison", false,"","string"); cmd.add( compare1Arg ); TCLAP::ValueArg<string> compare2Arg("2","compare2","2nd image for comparison", false,"","string"); cmd.add( compare2Arg ); TCLAP::SwitchArg retrainAttReprTrF("6","attReprTr","Retrain attReprTr", cmd, false); TCLAP::SwitchArg retrainEmbeddingF("5","embedding","Retrain embedding", cmd, false); TCLAP::ValueArg<string> trainFileArg("9","trainfile","training file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/queries_train.gtp","string"); cmd.add( trainFileArg ); TCLAP::ValueArg<string> testFileArg("8","testfile","testing file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/queries_test.gtp","string"); cmd.add( testFileArg ); TCLAP::ValueArg<string> exemplarFileArg("7","exemplars","exemplar file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/exemplars.txt","string"); cmd.add( exemplarFileArg ); //TCLAP::ValueArg<string> exemplarLocArg("7","exemplar_locations","exemplar locations file", false,"test/exemplars.txt","string"); //cmd.add( exemplarLocArg ); TCLAP::ValueArg<string> imageDirArg("d","images","directory containing images", false,"/home/brian/intel_index/brian_handwriting/EmbeddedAtt_Almazan/datasets/GW/images/","string"); cmd.add( imageDirArg ); TCLAP::ValueArg<string> exemplarDirArg("x","exemplarsDir","directory containing exemplar images", false,"/home/brian/intel_index/data/gw_20p_wannot/bigrams_clean_deslant/","string"); cmd.add( exemplarDirArg ); TCLAP::ValueArg<string> fullFileArg("f","full","do a full sliding window subword spotting on this image", false,"","string"); cmd.add( fullFileArg ); TCLAP::ValueArg<float> hyarg("y","hybridalpha","hybrid alpha, 0 text only, 1 image only", false,-1,"float"); cmd.add( hyarg ); TCLAP::ValueArg<string> charSegCSVArg("3","charSeg","char seg csv file: 'word,pageId,x1,y1,x2,y2,char1start,char1end,char2start,...'", false,"","string"); cmd.add( charSegCSVArg ); cmd.parse( argc, argv ); if ( testF.getValue() ) { EmbAttSpotter spotter("testing",false,true,1); spotter.test(); } if ( evalF.getValue() ) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); if ( retrainAttReprTrF.getValue() ) spotter.attReprTr(true); if ( retrainEmbeddingF.getValue() ) spotter.embedding(true); spotter.eval(&test); } if (primeSubwordArg.getValue()>=0) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); spotter.setCorpus_dataset(&test); spotter.primeSubwordSpotting(primeSubwordArg.getValue()); } if ( evalSubF.getValue() || evalSubCombF.getValue()) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); GWDataset exemplars(exemplarFileArg.getValue(),exemplarDirArg.getValue()); spotter.setTraining_dataset(&train); if ( retrainAttReprTrF.getValue() ) spotter.attReprTr(true); if ( retrainEmbeddingF.getValue() ) spotter.embedding(true); if (charSegCSVArg.getValue().length()>0) { vector< vector<int> > corpusXLetterStartBoundsRel; vector< vector<int> > corpusXLetterEndBoundsRel; ifstream in (charSegCSVArg.getValue()); string line; //getline(in,line);//header while (getline(in,line)) { string s; std::stringstream ss(line); getline(ss,s,','); getline(ss,s,','); getline(ss,s,',');//x1 int x1=stoi(s); getline(ss,s,','); getline(ss,s,',');//x2 getline(ss,s,','); vector<int> lettersStartRel, lettersEndRel; while (getline(ss,s,',')) { lettersStartRel.push_back(stoi(s)-x1); getline(ss,s,','); lettersEndRel.push_back(stoi(s)-x1); //getline(ss,s,',');//conf } corpusXLetterStartBoundsRel.push_back(lettersStartRel); corpusXLetterEndBoundsRel.push_back(lettersEndRel); } in.close(); spotter.evalSubwordSpottingWithCharBounds(&exemplars, &test, &corpusXLetterStartBoundsRel, &corpusXLetterEndBoundsRel, hyarg.getValue()); } else if ( evalSubF.getValue() ) spotter.evalSubwordSpotting(&exemplars, &test, hyarg.getValue()); else spotter.evalSubwordSpottingCombine(&exemplars, &test, hyarg.getValue()); } if ( imageArg.getValue()>=0 ) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); spotter.setCorpus_dataset(&test); int ex=imageArg.getValue(); if ( image2Arg.getValue()>=0 ) { int ex2= image2Arg.getValue(); double score = spotter.compare(test.image(ex),test.image(ex2)); cout <<"score: "<<score<<endl; } else { cout <<"test word "<<test.labels()[ex]<<endl; imshow("test word",test.image(ex)); vector<float> scores = spotter.spot(test.image(ex), "", 1); multimap<float, int> ranked; for (int i=0; i<scores.size(); i++) ranked.emplace(scores[i],i); auto iter = ranked.end(); for (int i=1; i<=5; i++) { iter--; cout<<"I rank "<<i<<" is "<<iter->second<<" with score "<<iter->first<<endl; imshow("I "+to_string(i),test.image(iter->second)); } scores = spotter.spot(test.image(ex), test.labels()[ex], 0); ranked.clear(); for (int i=0; i<scores.size(); i++) ranked.emplace(scores[i],i); iter = ranked.end(); for (int i=1; i<=5; i++) { iter--; cout<<"T rank "<<i<<" is "<<iter->second<<" with score "<<iter->first<<endl; imshow("T "+to_string(i),test.image(iter->second)); } waitKey(); } } if (compare1Arg.getValue().length()>0 && compare2Arg.getValue().length()>0) { EmbAttSpotter spotter(modelArg.getValue()); Mat im1 = imread(compare1Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); Mat im2 = imread(compare2Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); //im1 = GWDataset::preprocess(im1); //im2 = GWDataset::preprocess(im2); cout<<spotter.compare(im1,im2)<<endl;; } if (fullFileArg.getValue().length()>0) { assert(compare1Arg.getValue().length()>0); EmbAttSpotter spotter(modelArg.getValue()); StrideDataset im(fullFileArg.getValue()); spotter.setCorpus_dataset_fullSub(&im); Mat ex = imread(compare1Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); clock_t start = clock(); time_t start2 = time(0); vector< SubwordSpottingResult > res = spotter.subwordSpot_full(ex,"",1); clock_t end = clock(); time_t end2 = time(0); double time = (double) (end-start) / CLOCKS_PER_SEC; double time2 = difftime(end2, start2) * 1000.0; cout<<"Took "<<time<<" secs."<<endl; cout<<"Took "<<time2<<" secs."<<endl; Mat img = imread(fullFileArg.getValue()); Mat orig = img.clone(); int top=100; float maxS = res[0].score; float minS = res[top].score; for (int i=0; i<top; i++) { float s = 1-((res[i].score-minS)/(maxS-minS)); //cout <<res[i].score<<": "<<s<<endl; for (int x=res[i].startX; x<=res[i].endX; x++) for (int y=res[i].imIdx*3; y<res[i].imIdx*3 +65; y++) { Vec3b& p = img.at<Vec3b>(y,x); Vec3b o = orig.at<Vec3b>(y,x); p[0] = min(p[0],(unsigned char)(o[0]*s)); } } imwrite("spotting.png",img); imshow("spotting",img); waitKey(); } } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } }
void LocalInitData::parseArguments( const int argc, char** argv ) { try { std::string wsHelp = "Window System API ( one of: "; #ifdef AGL wsHelp += "AGL "; #endif #ifdef GLX wsHelp += "glX "; #endif #ifdef WGL wsHelp += "WGL "; #endif wsHelp += ")"; std::string desc = EVolve::getHelp(); TCLAP::CmdLine command( desc ); TCLAP::ValueArg<std::string> modelArg( "m", "model", "raw model file name", false, "Bucky32x32x32.raw", "string", command ); TCLAP::SwitchArg residentArg( "r", "resident", "Keep client resident (see resident node documentation on website)", command, false ); TCLAP::ValueArg<uint32_t> framesArg( "n", "numFrames", "Maximum number of rendered frames", false, 0xffffffffu, "unsigned", command ); TCLAP::ValueArg<uint32_t> precisionArg( "p", "precision", "Rendering precision (default 2, bigger is better and slower)", false, 2, "unsigned", command ); TCLAP::ValueArg<float> brightnessArg( "b", "brightness", "brightness factor", false, 1.0f, "float", command ); TCLAP::ValueArg<float> alphaArg( "a", "alpha", "alpha attenuation", false, 1.0f, "float", command ); TCLAP::SwitchArg orthoArg( "o", "ortho", "use orthographic projection", command, false ); TCLAP::ValueArg<std::string> wsArg( "w", "windowSystem", wsHelp, false, "auto", "string", command ); TCLAP::VariableSwitchArg ignoreEqArgs( "eq", "Ignored Equalizer options", command ); TCLAP::UnlabeledMultiArg< std::string > ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any", command ); command.parse( argc, argv ); if( modelArg.isSet( )) setFilename( modelArg.getValue( )); if( wsArg.isSet( )) { std::string windowSystem = wsArg.getValue(); transform( windowSystem.begin(), windowSystem.end(), windowSystem.begin(), (int(*)(int))std::toupper ); setWindowSystem( windowSystem ); } if( framesArg.isSet( )) _maxFrames = framesArg.getValue(); if( precisionArg.isSet( )) setPrecision( precisionArg.getValue( )); if( brightnessArg.isSet( )) setBrightness( brightnessArg.getValue( )); if( alphaArg.isSet( )) setAlpha( alphaArg.getValue( )); if( residentArg.isSet( )) _isResident = true; if( orthoArg.isSet( )) _ortho = true; } catch( const TCLAP::ArgException& exception ) { LBERROR << "Command line parse error: " << exception.error() << " for argument " << exception.argId() << std::endl; ::exit( EXIT_FAILURE ); } }