Exemple #1
0
/** Transforms a list of light curve names on the command line to a list of 
 *	light curves parseable by the rest of the program.
 *
 * @param[in] argList a multi-value argument containing the light curve names
 * @param[out] lcNameList a vector of the valid light curve names
 * @param[out] lcList a vector of light curve types
 *
 * @post @p lcNameList.size() &le; <tt>argList.getValue().size()</tt>
 * @post @p lcList = @p std::for_each(@p lcNameList, &@ref lcmc::parse::parseLightCurve() "parseLightCurve")
 *
 * @exception std::bad_alloc Thrown if there is not enough memory to 
 *	represent the light curve list.
 * @exception lcmc::parse::except::NoLightCurves thrown if no valid light 
 *	curves given
 *
 * @exceptsafe The arguments are unchanged in the event of an exception.
 */
void parseLcList(UnlabeledMultiArg<string>& argList, 
		std::vector<string>& lcNameList, 
		std::vector<LightCurveType>& lcList) {
	using std::swap;

	std::vector<string> fullLcList(argList.getValue());

	// Iterate over the argument list, preserving the user-requested execution order
	std::vector<string        > tempNameList;
	std::vector<LightCurveType> tempLcList;

	for(std::vector<string>::const_iterator it=fullLcList.begin(); 
			it != fullLcList.end(); it++) {
		try {
			const LightCurveType curLc = parseLightCurve(*it);
			// Don't count light curves multiple times
			if (find(tempLcList.begin(), tempLcList.end(), curLc) 
					== tempLcList.end()) {
				tempNameList.push_back(*it);
				tempLcList.push_back(curLc);
			}
		} catch(std::domain_error e) {
			// If there's an invalid light curve, print a warning but keep going
			fprintf(stderr, "WARNING: %s\n", e.what());
		}
	}
	if (tempLcList.size() <= 0) {
		throw except::NoLightCurves("No valid light curves given.");
			// Type " + progName + " -h for a list of choices.");
	}
	
	// IMPORTANT: no exceptions past this point
	// swap<vector> is guaranteed not to throw for equal allocators
	//	Since all vectors here use the default allocator, 
	//	this condition is satisfied
	swap(tempNameList, lcNameList);
	swap(  tempLcList,     lcList);
}
void parseOptions ( int argc, char** argv )
{
    try
    {

        CmdLine cmd ( "keypoints", ' ', kVersion );

        MyOutput my;
        cmd.setOutput ( &my );

        SwitchArg aArgFullScale ( "","fullscale", "Uses full scale image to detect keypoints    (default:false)\n", false );
        // SURF has a better performance than the other descriptors, use it by default, if it is enabled
        ValueArg<int> aArgSurfScoreThreshold ( "","surfscore", "Detection score threshold    (default : 1000)\n", false, 1000, "int" );
        ValueArg<int> aArgSieve1Width ( "","sievewidth", "Interest point sieve: Number of buckets on width    (default : 10)", false, 10, "int" );
        ValueArg<int> aArgSieve1Height ( "","sieveheight",  "Interest point sieve : Number of buckets on height    (default : 10)", false, 10, "int" );
        ValueArg<int> aArgSieve1Size ( "","sievesize",	"Interest point sieve : Max points per bucket    (default : 10)\n", false, 10, "int" );
        ValueArg<std::string> aArgOutputFormat ( "","format", "Output format (text, autopano-xml, descperf), default text\n", false, "text", "string" );
        ValueArg<std::string> aArgOutputFile ( "o","output", "Output file. If not specified, print to standard out\n", false, "", "string" );
        SwitchArg aArgInterestPoints ( "","interestpoints", "output only the interest points and the scale (default:false)\n", false );
        ValueArg<std::string> aArgFixedInterestPoint ( "","ip", "Compute descriptor at x,y,scale,ori \n", false, "", "string" );

        cmd.add ( aArgSurfScoreThreshold );
        cmd.add ( aArgFullScale );
        cmd.add ( aArgSieve1Width );
        cmd.add ( aArgSieve1Height );
        cmd.add ( aArgSieve1Size );
        cmd.add ( aArgOutputFormat );
        cmd.add ( aArgOutputFile );
        cmd.add ( aArgInterestPoints );
        cmd.add ( aArgFixedInterestPoint );

        /*
        	SwitchArg aArgTest("t","test", "Enables test mode\n", false);
        	cmd.add( aArgTest );
        */

        UnlabeledMultiArg<string> aArgFiles ( "fileName", "Image files", true, "string" );
        cmd.add ( aArgFiles );

        cmd.parse ( argc,argv );

        //
        // Set variables
        //
        vector<string> aFiles = aArgFiles.getValue();
        if ( aFiles.size() != 1 )
        {
            exit ( 1 );
        }

        double surfScoreThreshold=1000;
        if ( aArgSurfScoreThreshold.isSet() )
        {
            surfScoreThreshold = ( aArgSurfScoreThreshold.getValue() );
        }

        bool downscale = true;
        if ( aArgFullScale.isSet() )
        {
            downscale = false;
        }

        int sieveWidth = 10;
        if ( aArgSieve1Width.isSet() )
        {
            sieveWidth = aArgSieve1Width.getValue();
        }
        int sieveHeight = 10;
        if ( aArgSieve1Height.isSet() )
        {
            sieveHeight = aArgSieve1Height.getValue();
        }
        int sieveSize = 10;
        if ( aArgSieve1Size.isSet() )
        {
            sieveSize = aArgSieve1Size.getValue();
        }

        bool onlyInterestPoints = false;
        if ( aArgInterestPoints.isSet() )
        {
            onlyInterestPoints = true;
        }

        std::ostream* outstream;
        if ( aArgOutputFile.isSet() )
        {
            outstream = new std::ofstream(aArgOutputFile.getValue().c_str());
        }
        else
        {
            outstream = & std::cout;
        }

        KeypointWriter* writer = 0;
        std::string outputformat = "text";
        if ( aArgOutputFormat.isSet() )
        {
            outputformat = aArgOutputFormat.getValue();
        }
        if (outputformat == "text")
        {
            writer = new SIFTFormatWriter(*outstream);
        }
        else if (outputformat == "autopano-sift-xml")
        {
            writer = new AutopanoSIFTWriter(*outstream);
        }
        else if (outputformat == "descperf")
        {
            writer = new DescPerfFormatWriter(*outstream);
        }
        else
        {
            std::cerr << "Unknown output format, valid values are text, autopano-sift-xml, descperf" << std::endl;
            exit(1);
        }


        KeyPointPtr preKPPtr;
        if ( aArgFixedInterestPoint.isSet() )
        {
            preKPPtr = KeyPointPtr(new KeyPoint());
            preKPPtr->_x = -10001;
            preKPPtr->_ori = -10001;
            int nf = sscanf(aArgFixedInterestPoint.getValue().c_str(), "%lf:%lf:%lf:%lf",
                            &(preKPPtr->_x), &(preKPPtr->_y), &(preKPPtr->_scale), &(preKPPtr->_ori));
            std::cerr << "passed orientation: " << preKPPtr->_ori << std::endl;
            if (nf < 3)
            {
                std::cerr << "Invalid value for --ip option, expected --ip x:y:scale:ori" << std::endl;
                exit(1);
            }
        }

        DetectKeypoints ( aFiles[0], downscale, surfScoreThreshold, preKPPtr, onlyInterestPoints, sieveWidth, sieveHeight, sieveSize, *writer );

        if ( aArgOutputFile.isSet() )
        {
            delete outstream;
        }

    }
    catch ( ArgException& e )
    {
        cout << "ERROR: " << e.error() << " " << e.argId() << endl;
    }
}