Skip to content

Commit

Permalink
stereo: Tweaks in parsing options for multiview
Browse files Browse the repository at this point in the history
stereo: Minor tweak to display the usage all the time

stereo: Minor tweak to display the usage all the time

More tweaks for parsing options
  • Loading branch information
oleg-alexandrov committed Aug 21, 2014
1 parent 8f29b2c commit 47180fa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/asp/Sessions/StereoSession.cc
Expand Up @@ -117,7 +117,9 @@ namespace asp {
actual_session_type = "pinhole";
}
if ( boost::iends_with(boost::to_lower_copy(left_image_file), ".cub") ||
boost::iends_with(boost::to_lower_copy(right_image_file), ".cub") ) {
boost::iends_with(boost::to_lower_copy(right_image_file), ".cub") ||
boost::iends_with(boost::to_lower_copy(left_camera_file), ".cub") ||
boost::iends_with(boost::to_lower_copy(right_camera_file), ".cub") ) {
actual_session_type = "isis";
}
if (boost::iends_with(boost::to_lower_copy(left_camera_file), ".xml") ||
Expand Down
40 changes: 23 additions & 17 deletions src/asp/Tools/stereo.cc
Expand Up @@ -98,8 +98,9 @@ namespace asp {
vector<string> files;
bool allow_unregistered = true;
Options opt;
std::string usage;
handle_arguments(argc, argv, opt, additional_options,
allow_unregistered, files);
allow_unregistered, files, usage);

// Store the elements in argv which are not files or output prefix.
// Note that argv[0] is the program name.
Expand All @@ -116,7 +117,8 @@ namespace asp {
vector<string> cameras = asp::extract_cameras( files );

if (files.size() < 3)
vw_throw( ArgumentErr() << "Missing all of the correct input files.\n" );
vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n"
<< usage );

// Find the input DEM, if any
string input_dem;
Expand All @@ -142,7 +144,8 @@ namespace asp {
<< ". Perhaps this was not intended." << endl;

if (files.size() != cameras.size() && !cameras.empty())
vw_throw( ArgumentErr() << "Expecting the number of images and cameras to agree.\n" );
vw_throw( ArgumentErr() << "Expecting the number of images and "
<< "cameras to agree.\n" );

int num_pairs = (int)files.size() - 1;
if (num_pairs <= 0)
Expand Down Expand Up @@ -231,9 +234,8 @@ namespace asp {
Options opt;
bool allow_unregistered = false;
vector<string> unregistered;
handle_arguments( largc, &largv[0], opt,
additional_options,
allow_unregistered, unregistered);
handle_arguments( largc, &largv[0], opt, additional_options,
allow_unregistered, unregistered, usage);
opt_vec.push_back(opt);

if (verbose){
Expand All @@ -260,9 +262,8 @@ namespace asp {
void handle_arguments( int argc, char *argv[], Options& opt,
boost::program_options::options_description const&
additional_options,
bool allow_unregistered,
vector<string> & unregistered
) {
bool allow_unregistered, vector<string> & unregistered,
std::string & usage ){

po::options_description general_options_sub("");
general_options_sub.add_options()
Expand Down Expand Up @@ -301,20 +302,13 @@ namespace asp {
positional_desc.add("output-prefix", 1);
positional_desc.add("input-dem", 1);

string usage("[options] <images> [<cameras>] <output_file_prefix> [DEM]\n Extensions are automaticaly added to the output files.\n Camera model arguments may be optional for some stereo session types (e.g., isis).\n Stereo parameters should be set in the stereo.default file.");
usage = "[options] <images> [<cameras>] <output_file_prefix> [DEM]\n Extensions are automaticaly added to the output files.\n Camera model arguments may be optional for some stereo session types (e.g., isis).\n Stereo parameters should be set in the stereo.default file.";
po::variables_map vm =
asp::check_command_line( argc, argv, opt, general_options,
all_general_options, positional_options,
positional_desc, usage,
allow_unregistered, unregistered );

// If we allow unregistered options, the logic below won't apply correctly.
if (allow_unregistered) return;

if ( opt.in_file1.empty() || opt.in_file2.empty() || opt.cam_file1.empty() )
vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n"
<< usage << general_options );

// Read the config file
try {
po::options_description cfg_options;
Expand All @@ -335,6 +329,18 @@ namespace asp {
}
asp::stereo_settings().validate();

// Add the options to the usage
std::ostringstream os;
os << usage << general_options;
usage = os.str();

// If we allow unregistered options, the logic below won't apply correctly.
if (allow_unregistered) return;

if ( opt.in_file1.empty() || opt.in_file2.empty() || opt.cam_file1.empty() )
vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n"
<< usage );

/// There are 3 valid methods of input into this application
/// 1.) <image1> <image2> <cam1> <cam2> <prefix> <dem>
/// 2.) <image1> <image2> <cam1> <cam2> <prefix>
Expand Down
3 changes: 2 additions & 1 deletion src/asp/Tools/stereo.h
Expand Up @@ -81,7 +81,8 @@ namespace asp {
boost::program_options::options_description const&
additional_options,
bool allow_unregistered,
std::vector<std::string> & unregistered);
std::vector<std::string> & unregistered,
std::string & usage);

// Register Session types
void stereo_register_sessions();
Expand Down
4 changes: 1 addition & 3 deletions src/asp/Tools/stereo_fltr.cc
Expand Up @@ -18,8 +18,6 @@

/// \file stereo_fltr.cc
///
//#define USE_GRAPHICS

#include <asp/Tools/stereo.h>
#include <vw/Stereo/DisparityMap.h>

Expand Down Expand Up @@ -267,7 +265,7 @@ void stereo_filtering( Options& opt ) {
}

// This is only turned on for apollo. Blob detection doesn't
// work to great when tracking a whole lot of spots. HiRISE
// work too great when tracking a whole lot of spots. HiRISE
// seems to keep breaking this so I've keep it turned off.
//
// The crash happens inside Boost Graph when dealing with
Expand Down
15 changes: 6 additions & 9 deletions src/asp/Tools/stereo_pprc.cc
Expand Up @@ -18,8 +18,6 @@

/// \file stereo_pprc.cc
///
//#define USE_GRAPHICS

#include <asp/Tools/stereo.h>
#include <asp/Core/ThreadedEdgeMask.h>
#include <asp/Core/InpaintView.h>
Expand Down Expand Up @@ -194,9 +192,7 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) {
// skipped image normalization, so we are still using the original
// input images, and the user wants to use a custom no-data value,
// this is the time to apply it.
if (skip_img_norm &&
!isnan(stereo_settings().nodata_value)
){
if (skip_img_norm && !isnan(stereo_settings().nodata_value)){
left_nodata_value = stereo_settings().nodata_value;
right_nodata_value = stereo_settings().nodata_value;
}
Expand Down Expand Up @@ -232,7 +228,8 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) {
}
if ( !isnan(nodata_fraction) ){
// Declare a fixed proportion of low-value pixels to be no-data.
math::CDFAccumulator< PixelGray<float> > left_cdf(1024, 1024), right_cdf(1024, 1024);
math::CDFAccumulator< PixelGray<float> > left_cdf(1024, 1024),
right_cdf(1024, 1024);
for_each_pixel( left_image, left_cdf );
for_each_pixel( right_image, right_cdf );
left_threshold = left_cdf.quantile(nodata_fraction);
Expand Down Expand Up @@ -307,8 +304,8 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) {
DiskImageView<uint8> testrm(rmsub);
vw_out() << "\t--> Using cached subsampled images.\n";
} catch (vw::Exception const& e) {
// Produce subsampled images, these will be used later for Auto
// search range. They're also a handy debug tool.
// Produce subsampled images, these will be used later for auto
// search range detection.
double s = 1500.0;
float sub_scale =
sqrt(s * s / (float(left_image.cols()) * float(left_image.rows())));
Expand All @@ -333,7 +330,7 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) {
sub_tile_size = vw_settings().default_tile_size();

vw_out() << "\t--> Creating previews. Subsampling by " << sub_scale
<< " by using " << sub_tile_size << " tile size and "
<< " by using a tile of size " << sub_tile_size << " and "
<< sub_threads << " threads.\n";

// Resample the images and the masks. We must use the masks when
Expand Down
1 change: 0 additions & 1 deletion src/asp/Tools/stereo_rfne.cc
Expand Up @@ -18,7 +18,6 @@

/// \file stereo_rfne.cc
///
//#define USE_GRAPHICS

#include <asp/Tools/stereo.h>
#include <vw/Stereo/PreFilter.h>
Expand Down
4 changes: 4 additions & 0 deletions src/asp/Tools/stereo_utils.py.in
Expand Up @@ -97,6 +97,10 @@ def run_and_parse_output(cmd, args, sep, verbose, **kw ):
raise Exception('Failed executing: ' + " ".join(call))
data = {}
for line in stdout.split('\n'):

# Print warning messages to stdout
if re.match("^Warning", line): print(line)

if sep in line:
keywords = line.split(sep)
for index, item in enumerate(keywords):
Expand Down

0 comments on commit 47180fa

Please sign in to comment.