本文整理汇总了C++中command_line_parser类的典型用法代码示例。如果您正苦于以下问题:C++ command_line_parser类的具体用法?C++ command_line_parser怎么用?C++ command_line_parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了command_line_parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: merge_metadata_files
void merge_metadata_files (
const command_line_parser& parser
)
{
image_dataset_metadata::dataset src, dest;
load_image_dataset_metadata(src, parser.option("add").argument(0));
load_image_dataset_metadata(dest, parser.option("add").argument(1));
std::map<string,image_dataset_metadata::image> merged_data;
for (unsigned long i = 0; i < dest.images.size(); ++i)
merged_data[dest.images[i].filename] = dest.images[i];
// now add in the src data and overwrite anything if there are duplicate entries.
for (unsigned long i = 0; i < src.images.size(); ++i)
merged_data[src.images[i].filename] = src.images[i];
// copy merged data into dest
dest.images.clear();
for (std::map<string,image_dataset_metadata::image>::const_iterator i = merged_data.begin();
i != merged_data.end(); ++i)
{
dest.images.push_back(i->second);
}
save_image_dataset_metadata(dest, "merged.xml");
}
示例2: tile_dataset
int tile_dataset(const command_line_parser& parser)
{
if (parser.number_of_arguments() != 1)
{
cerr << "The --tile option requires you to give one XML file on the command line." << endl;
return EXIT_FAILURE;
}
string out_image = parser.option("tile").argument();
string ext = right_substr(out_image,".");
if (ext != "png" && ext != "jpg")
{
cerr << "The output image file must have either .png or .jpg extension." << endl;
return EXIT_FAILURE;
}
const unsigned long chip_size = get_option(parser, "size", 8000);
dlib::image_dataset_metadata::dataset data;
load_image_dataset_metadata(data, parser[0]);
locally_change_current_dir chdir(get_parent_directory(file(parser[0])));
dlib::array<array2d<rgb_pixel> > images;
console_progress_indicator pbar(data.images.size());
for (unsigned long i = 0; i < data.images.size(); ++i)
{
// don't even bother loading images that don't have objects.
if (data.images[i].boxes.size() == 0)
continue;
pbar.print_status(i);
array2d<rgb_pixel> img;
load_image(img, data.images[i].filename);
// figure out what chips we want to take from this image
std::vector<chip_details> dets;
for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j)
{
if (data.images[i].boxes[j].ignore)
continue;
rectangle rect = data.images[i].boxes[j].rect;
dets.push_back(chip_details(rect, chip_size));
}
// Now grab all those chips at once.
dlib::array<array2d<rgb_pixel> > chips;
extract_image_chips(img, dets, chips);
// and put the chips into the output.
for (unsigned long j = 0; j < chips.size(); ++j)
images.push_back(chips[j]);
}
chdir.revert();
if (ext == "png")
save_png(tile_images(images), out_image);
else
save_jpeg(tile_images(images), out_image);
return EXIT_SUCCESS;
}
示例3: parse_options
void parse_options(const command_line_parser& parser)
{
using namespace mcrl2::lts;
ltsinfo_base::parse_options(parser);
if (0 < parser.arguments.size())
{
infilename = parser.arguments[0];
}
if (1 < parser.arguments.size())
{
throw parser.error("too many file arguments");
}
if (parser.options.count("in"))
{
if (1 < parser.options.count("in"))
{
throw parser.error("multiple input formats specified; can only use one");
}
intype = mcrl2::lts::detail::parse_format(parser.option_argument("in"));
if (intype == lts_none || intype == lts_dot)
{
throw parser.error("option -i/--in has illegal argument '" +
parser.option_argument("in") + "'");
}
}
}
示例4: parse_options
void parse_options(const command_line_parser& parser)
{
super::parse_options(parser);
m_rewrite = (parser.options.count("no-rewrite")==0);
m_sumelm = (parser.options.count("no-sumelm")==0);
m_pretty = (parser.options.count("pretty")!=0);
if (parser.options.count("end-phase")>0)
{
std::string phase = parser.option_argument("end-phase");
if (std::strncmp(phase.c_str(), "pa", 3) == 0)
{
m_end_phase = PH_PARSE;
}
else if (std::strncmp(phase.c_str(), "tc", 3) == 0)
{
m_end_phase = PH_TYPE_CHECK;
}
else
{
throw parser.error("option -p has illegal argument '" + phase + "'");
}
}
m_action_rename_filename = parser.option_argument("renamefile");
}
示例5: flip_dataset
void flip_dataset(const command_line_parser& parser)
{
image_dataset_metadata::dataset metadata, orig_metadata;
string datasource;
if (parser.option("flip"))
datasource = parser.option("flip").argument();
else
datasource = parser.option("flip-basic").argument();
load_image_dataset_metadata(metadata,datasource);
orig_metadata = metadata;
// Set the current directory to be the one that contains the
// metadata file. We do this because the file might contain
// file paths which are relative to this folder.
set_current_dir(get_parent_directory(file(datasource)));
const string metadata_filename = get_parent_directory(file(datasource)).full_name() +
directory::get_separator() + "flipped_" + file(datasource).name();
array2d<rgb_pixel> img, temp;
for (unsigned long i = 0; i < metadata.images.size(); ++i)
{
file f(metadata.images[i].filename);
string filename = get_parent_directory(f).full_name() + directory::get_separator() + "flipped_" + to_png_name(f.name());
load_image(img, metadata.images[i].filename);
flip_image_left_right(img, temp);
if (parser.option("jpg"))
{
filename = to_jpg_name(filename);
save_jpeg(temp, filename,JPEG_QUALITY);
}
else
{
save_png(temp, filename);
}
for (unsigned long j = 0; j < metadata.images[i].boxes.size(); ++j)
{
metadata.images[i].boxes[j].rect = impl::flip_rect_left_right(metadata.images[i].boxes[j].rect, get_rect(img));
// flip all the object parts
for (auto& part : metadata.images[i].boxes[j].parts)
{
part.second = impl::flip_rect_left_right(rectangle(part.second,part.second), get_rect(img)).tl_corner();
}
}
metadata.images[i].filename = filename;
}
if (!parser.option("flip-basic"))
make_part_labeling_match_target_dataset(orig_metadata, metadata);
save_image_dataset_metadata(metadata, metadata_filename);
}
示例6: parse_options
void parse_options(const command_line_parser& parser)
{
super::parse_options(parser);
if (parser.options.count("lps"))
{
lps_filename = parser.option_argument("lps");
}
if (parser.options.count("network"))
{
network_filename = parser.option_argument("network");
}
}
示例7: get_mlp_num_iterations
static double
get_mlp_num_iterations (
command_line_parser& parser,
std::vector<dense_sample_type>& dense_samples
)
{
int num_iterations = 5000;
if (parser.option ("mlp-num-iterations")) {
num_iterations = sa = parser.option("mlp-num-iterations").argument();
}
return num_iterations;
}
示例8: get_mlp_hidden_units
static double
get_mlp_hidden_units (
command_line_parser& parser,
std::vector<dense_sample_type>& dense_samples
)
{
int num_hidden = 5;
if (parser.option ("mlp-hidden-units")) {
num_hidden = sa = parser.option("mlp-hidden-units").argument();
}
return num_hidden;
}
示例9: krr_rbk_test
static void
krr_rbk_test (
command_line_parser& parser,
std::vector<dense_sample_type>& dense_samples,
std::vector<double>& labels
)
{
typedef radial_basis_kernel<dense_sample_type> kernel_type;
krr_trainer<kernel_type> trainer;
option_range gamma_range;
double best_gamma = DBL_MAX;
float best_loo = FLT_MAX;
get_rbk_gamma (parser, dense_samples, gamma_range);
for (float gamma = gamma_range.get_min_value();
gamma <= gamma_range.get_max_value();
gamma = gamma_range.get_next_value (gamma))
{
// LOO cross validation
std::vector<double> loo_values;
if (parser.option("verbose")) {
trainer.set_search_lambdas(logspace(-9, 4, 100));
trainer.be_verbose();
}
trainer.set_kernel (kernel_type (gamma));
trainer.train (dense_samples, labels, loo_values);
const double loo_error = mean_squared_error(loo_values, labels);
if (loo_error < best_loo) {
best_loo = loo_error;
best_gamma = gamma;
}
printf ("10^%f %9.6f\n", log10(gamma), loo_error);
}
printf ("Best result: gamma=10^%f (%g), loo_error=%9.6f\n",
log10(best_gamma), best_gamma, best_loo);
if (parser.option("train-best")) {
printf ("Training network with best parameters\n");
trainer.set_kernel (kernel_type (best_gamma));
decision_function<kernel_type> best_network =
trainer.train (dense_samples, labels);
std::ofstream fout (parser.option("train-best").argument().c_str(),
std::ios::binary);
serialize (best_network, fout);
fout.close();
}
}
示例10: make_train_test_splits
int make_train_test_splits (
const command_line_parser& parser
)
{
if (parser.number_of_arguments() != 1)
{
cerr << "The --split-train-test option requires you to give one XML file on the command line." << endl;
return EXIT_FAILURE;
}
const double train_frac = get_option(parser, "split-train-test", 0.5);
dlib::image_dataset_metadata::dataset data, data_train, data_test;
load_image_dataset_metadata(data, parser[0]);
data_train.name = data.name;
data_train.comment = data.comment;
data_test.name = data.name;
data_test.comment = data.comment;
const unsigned long num_train_images = static_cast<unsigned long>(std::round(train_frac*data.images.size()));
for (unsigned long i = 0; i < data.images.size(); ++i)
{
if (i < num_train_images)
data_train.images.push_back(data.images[i]);
else
data_test.images.push_back(data.images[i]);
}
save_image_dataset_metadata(data_train, left_substr(parser[0],".") + "_train.xml");
save_image_dataset_metadata(data_test, left_substr(parser[0],".") + "_test.xml");
return EXIT_SUCCESS;
}
示例11: convert_idl
void convert_idl(
const command_line_parser& parser
)
{
cout << "Convert from IDL annotation format..." << endl;
dlib::image_dataset_metadata::dataset dataset;
for (unsigned long i = 0; i < parser.number_of_arguments(); ++i)
{
parse_annotation_file(parser[i], dataset);
}
const std::string filename = parser.option("c").argument();
save_image_dataset_metadata(dataset, filename);
}
示例12: parse_options
/// Parse the non-default options.
void parse_options(const command_line_parser& parser)
{
super::parse_options(parser);
std::string s = parser.option_argument("option1");
std::cout << "option o: " << s << std::endl;
int i = parser.option_argument_as<int>("option2");
std::cout << "option i: " << i << std::endl;
bool b = parser.option_argument_as<bool>("option3");
std::cout << "option b: " << std::boolalpha << b << std::endl;
bool a = parser.options.count("option4") > 0;
std::cout << "option a: " << std::boolalpha << a << std::endl;
if (0 < parser.arguments.size())
{
std::string s = parser.arguments[0];
std::cout << "positional option 1: " << s << std::endl;
}
std::cout << "--- parser arguments ---" << std::endl;
for (command_line_parser::option_map::const_iterator i = parser.options.begin(); i != parser.options.end(); ++i)
{
std::cout << i->first << " -> " << i->second << std::endl;
}
}
示例13: split_dataset
int split_dataset (
const command_line_parser& parser
)
{
if (parser.number_of_arguments() != 1)
{
cerr << "The --split option requires you to give one XML file on the command line." << endl;
return EXIT_FAILURE;
}
const std::string label = parser.option("split").argument();
dlib::image_dataset_metadata::dataset data, data_with, data_without;
load_image_dataset_metadata(data, parser[0]);
data_with.name = data.name;
data_with.comment = data.comment;
data_without.name = data.name;
data_without.comment = data.comment;
for (unsigned long i = 0; i < data.images.size(); ++i)
{
auto&& temp = data.images[i];
bool has_the_label = false;
// check for the label we are looking for
for (unsigned long j = 0; j < temp.boxes.size(); ++j)
{
if (temp.boxes[j].label == label)
{
has_the_label = true;
break;
}
}
if (has_the_label)
data_with.images.push_back(temp);
else
data_without.images.push_back(temp);
}
save_image_dataset_metadata(data_with, left_substr(parser[0],".") + "_with_"+label + ".xml");
save_image_dataset_metadata(data_without, left_substr(parser[0],".") + "_without_"+label + ".xml");
return EXIT_SUCCESS;
}
示例14: parse_options
void parse_options(const command_line_parser& parser)
{
super::parse_options(parser);
m_strategy = parser.option_argument_as<absinthe_strategy>("strategy");
m_abstraction_file = parser.option_argument("abstraction-file");
m_print_used_function_symbols = parser.options.count("used-function-symbols") > 0;
m_enable_logging = parser.options.count("enable-logging") > 0;
}
示例15: create_new_dataset
void create_new_dataset (
const command_line_parser& parser
)
{
using namespace dlib::image_dataset_metadata;
const std::string filename = parser.option("c").argument();
// make sure the file exists so we can use the get_parent_directory() command to
// figure out it's parent directory.
make_empty_file(filename);
const std::string parent_dir = get_parent_directory(file(filename));
unsigned long depth = 0;
if (parser.option("r"))
depth = 30;
dataset meta;
meta.name = "imglab dataset";
meta.comment = "Created by imglab tool.";
for (unsigned long i = 0; i < parser.number_of_arguments(); ++i)
{
try
{
const string temp = strip_path(file(parser[i]), parent_dir);
meta.images.push_back(image(temp));
}
catch (dlib::file::file_not_found&)
{
// then parser[i] should be a directory
std::vector<file> files = get_files_in_directory_tree(parser[i],
match_endings(".png .PNG .jpeg .JPEG .jpg .JPG .bmp .BMP .dng .DNG"),
depth);
sort(files.begin(), files.end());
for (unsigned long j = 0; j < files.size(); ++j)
{
meta.images.push_back(image(strip_path(files[j], parent_dir)));
}
}
}
save_image_dataset_metadata(meta, filename);
}