Wednesday, September 3, 2014

Parse Command Line

 ParameterStereoSlic parseCommandline(int argc, char* argv[]) {  
      // Make command parser  
      cmdline::parser commandParser;  
      commandParser.add<std::string>("output", 'o', "output file", false, "");  
      commandParser.add<double>("factor", 'f', "disparity factor of input disparity image", false, 256.0);  
      commandParser.add<int>("superpixel", 's', "the number of superpixels", false, 2000);  
      commandParser.add("verbose", 'v', "verbose");  
      commandParser.add("help", 'h', "display this message");  
      commandParser.set_program_name("smoothfit");  
      commandParser.footer("imgL0 dispL0 motion");  
      // Parse command line  
      bool isCorrectCommandline = commandParser.parse(argc, argv);  
      // Check arguments  
      if (!isCorrectCommandline) {  
           std::cerr << commandParser.error() << std::endl;  
      }  
      if (!isCorrectCommandline || commandParser.exist("help") || commandParser.rest().size() < 3) {  
           std::cerr << commandParser.usage() << std::endl;  
           exit(1);  
      }  
      // Set program parameters  
      ParameterStereoSlic parameters;  
      // Verbose flag  
      parameters.verbose = commandParser.exist("verbose");  
      // Disparity factor  
      parameters.disparityFactor = commandParser.get<double>("factor");  
      // The number of superpixels  
      parameters.superpixelTotal = commandParser.get<int>("superpixel");  
      // Input files  
      parameters.firstLeftImageFilename = commandParser.rest()[0];  
      parameters.firstLeftDisparityImageFilename = commandParser.rest()[1];  
      parameters.cameraMotionFilename = commandParser.rest()[2];  
      // Output files  
      std::string outputSegmentImageFilename = commandParser.get<std::string>("output");  
      if (outputSegmentImageFilename == "") {  
           outputSegmentImageFilename = parameters.firstLeftImageFilename;  
           size_t dotPosition = outputSegmentImageFilename.rfind('.');  
           if (dotPosition != std::string::npos) outputSegmentImageFilename.erase(dotPosition);  
           outputSegmentImageFilename += "_seg.png";  
      }  
      parameters.outputSegmentImageFilename = outputSegmentImageFilename;  
      std::string outputBoundaryImageFilename = outputSegmentImageFilename;  
      size_t dotPosition = outputBoundaryImageFilename.rfind('.');  
      if (dotPosition != std::string::npos) outputBoundaryImageFilename.erase(dotPosition);  
      std::string outputDisparityImageFilename = outputBoundaryImageFilename;  
      std::string outputFlowImageFilename = outputBoundaryImageFilename;  
      std::string outputBoundaryLabelImageFilename = outputBoundaryImageFilename;  
      std::string outputBoundaryLabelFilename = outputBoundaryImageFilename;  
      //by harry  
      std::string outputDisparityPlaneFilename = outputBoundaryImageFilename;  
      outputBoundaryImageFilename += "_boundary.png";  
      outputDisparityImageFilename += "_disparity.png";  
      outputFlowImageFilename += "_flow.png";  
      outputBoundaryLabelImageFilename += "_label.png";  
      outputBoundaryLabelFilename += "_label.txt";  
      outputDisparityPlaneFilename += "_planes.txt";  
      parameters.outputBoundaryImageFilename = outputBoundaryImageFilename;  
      parameters.outputDisparityImageFilename = outputDisparityImageFilename;  
      parameters.outputFlowImageFilename = outputFlowImageFilename;  
      parameters.outputBoundaryLabelImageFilename = outputBoundaryLabelImageFilename;  
      parameters.outputBoundaryLabelFilename = outputBoundaryLabelFilename;  
   parameters.outputDisparityPlaneFilename = outputDisparityPlaneFilename;  
      return parameters;  
 }  

No comments:

Post a Comment