Example #1
0
int add_global_opts(cargo_t cargo)
{
    int ret = 0;
    ret |= cargo_add_option(cargo, 0, "--opt1", "String used for global option 1", "s", &global_1);
    ret |= cargo_add_option(cargo, 0, "--opt2", "String used for global option 2", "s", &global_2);
    return ret;
}
Example #2
0
int main(int argc, char **argv)
{
	cargo_t cargo;
	int ret = 0;
	int *integers = NULL;
	size_t integer_count = 0;
	accumulator_f accumulator = max_ints;
	int sum_flag = 0;

	printf("cargo version v%s\n", cargo_get_version());

	if (cargo_init(&cargo, 0, "%s", argv[0]))
	{
		fprintf(stderr, "Failed to init command line parsing\n");
		return -1;
	}

	cargo_set_description(cargo, "Process some integers.");

	ret |= cargo_add_option(cargo, 0, "integers",
							"An integer for the accumulator",
							"[i]+", &integers, &integer_count);
	ret |= cargo_add_option(cargo, 0, "--sum -s",
							"Sum the integers (default: find the max)",
							"b", &sum_flag);
	assert(ret == 0);

	if (cargo_parse(cargo, 0, 1, argc, argv)) return -1;
	if (sum_flag) accumulator = sum_ints;
	printf("%d\n", accumulator(integers, integer_count));
	cargo_destroy(&cargo);
	free(integers);
	return 0;
}
Example #3
0
int add_module1_opts(cargo_t cargo)
{
    int ret = 0;
    ret |= cargo_add_group(cargo, 0, "module1", "Module 1 options", NULL);
    ret |= cargo_add_option(cargo, 0, "<module1> --og1_1", "String used for option 1 1", "s", &og1_1);
    return ret;
}
Example #4
0
int subcommand2(int start, int argc, char **argv)
{
    int ret = 0;
    cargo_t mod2;

    if (!argv) return -1;

    if (cargo_init(&mod2, 0,  "%s command2", argv[0]))
    {
        fprintf(stderr, "Failed to init command line parsing\n");
        return -1;
    }

    ret |= add_global_opts(mod2);

    // Module 1.
    ret |= add_module1_opts(mod2);

    // Module 2.
    ret |= cargo_add_group(mod2, 0, "module2", "Module 2 options", NULL);
    ret |= cargo_add_option(mod2, 0, "<module2> --og2_1", "String used for option 1 1", "s", &og1_1);
    assert(ret == 0);

    cargo_destroy(&mod2);

    return ret;
}
Example #5
0
int main(int argc, char **argv)
{
	int ret = 0;
	cargo_t cargo;
	debug_level_t debug_level = NONE;
	debug_level2_t debug_level2 = NONE2;

	if (cargo_init(&cargo, 0, "%s", argv[0]))
	{
		fprintf(stderr, "Failed to init command line parsing\n");
		return -1;
	}

	// Combine flags using OR.
	ret |= cargo_add_option(cargo, 0,
			"--verbose -v", "Verbosity level",
			"b|", &debug_level, 4, ERROR, WARN, INFO, DEBUG);

	// Store the flags and overwrite previous value.
	ret |= cargo_add_option(cargo, 0,
			"--loud -l", "Loudness level",
			"b_", &debug_level2, 4, ERROR2, WARN2, INFO2, DEBUG2);

	if (cargo_parse(cargo, 0, 1, argc, argv))
	{
		return -1;
	}

	printf("debug level: 0x%x\n", debug_level);
	if (debug_level & ERROR) printf("ERROR\n");
	if (debug_level & WARN)  printf("WARN\n");
	if (debug_level & INFO)  printf("INFO\n");
	if (debug_level & DEBUG) printf("DEBUG\n");

	printf("debug level2: %d\n", debug_level2);
	if (debug_level2 == ERROR2) printf("ERROR2\n");
	if (debug_level2 == WARN2)  printf("WARN2\n");
	if (debug_level2 == INFO2)  printf("INFO2\n");
	if (debug_level2 == DEBUG2) printf("DEBUG2\n");

	cargo_destroy(&cargo);

	return 0;
}
static int add_options(catcierge_args_t *args)
{
	int ret = 0;
	cargo_t cargo = args->cargo;

	ret |= cargo_add_group(cargo, 0, 
			"test", "Test Settings",
			"Settings for testing inputing a set of images to the catcierge matcher.");

	ret |= cargo_add_option(cargo, CARGO_OPT_REQUIRED,
			"<test> --images",
			"Input images that are passed to catcierge.",
			"[s]+", &ctx.img_paths, &ctx.img_count);

	ret |= cargo_add_option(cargo, 0,
			"<test> --test_save",
			"Save the match result images.",
			"b", &ctx.save);

	ctx.output_path = strdup("output");
	ret |= cargo_add_option(cargo, 0,
			"<test> --test_output",
			"Path were to save the output when using --save.",
			"s", &ctx.output_path);

	ret |= cargo_add_option(cargo, 0,
			"<test> --test_show",
			"Show the images being matched in a window.",
			"b", &ctx.show);

	ret |= cargo_add_option(cargo, 0,
			"<test> --test_obstructed",
			"Test if the image causes what catcierge considers to be an obstruction "
			"which is what catcierge uses to decide when to start to match.",
			"b", &ctx.test_matchable);

	ret |= cargo_add_option(cargo, 0,
			"<test> --debug",
			"Turn on internal debugging in the matcher.",
			"b", &ctx.debug);

	ret |= cargo_add_option(cargo, 0,
			"<test> --preload",
			"Preload the images before we start any tests, "
			"so the speed is not affected by disk IO at the time of the matching.",
			"b", &ctx.preload);

	return ret;
}
Example #7
0
int main(int argc, char **argv)
{
    cargo_t cargo;
    int ret = 0;
    int *integers = NULL;
    size_t i;
    size_t integer_count = 0;

    if (cargo_init(&cargo, 0, "%s", argv[0]))
    {
        fprintf(stderr, "Failed to init command line parsing\n");
        return -1;
    }

    ret |= cargo_add_option(cargo, 0, "--integers",
                        "A list of integers",
                        "[i]+", &integers, &integer_count);

    ret |= cargo_add_validation(cargo, 0, "--integers",
                                even_validate_int(20));

    assert(ret == 0);

    if (argc < 2)
    {
        cargo_print_usage(cargo, 0);
        return -1;
    }

    if (cargo_parse(cargo, 0, 1, argc, argv))
    {
        return -1;
    }

    for (i = 0; i < integer_count; i++)
    {
        printf("%2lu: %d\n", i+1, integers[i]);
    }

    cargo_destroy(&cargo);

    return 0;
}
int catcierge_haar_matcher_add_options(cargo_t cargo,
										catcierge_haar_matcher_args_t *args)
{
	int ret = 0;
	assert(cargo);
	assert(args);

	ret |= cargo_add_group(cargo, 0,
			"haar", "Haar cascade matcher settings",
			"Settings for when --haar_matcher is used.\n"
			"This is the recommended matcher type.");

	ret |= cargo_add_option(cargo, 0,
			"<haar> --cascade",
			"Path to the haar cascade xml generated by opencv_traincascade.",
			"s", &args->cascade);

	ret |= cargo_add_option(cargo, 0,
			"<haar> --in_direction",
			"The direction which is considered going inside.",
			"c", parse_in_direction, &args->in_direction);
	ret |= cargo_set_metavar(cargo,
			"--in_direction",
			"LEFT|RIGHT");

	ret |= cargo_add_option(cargo, 0,
			"<haar> --min_size",
			"The size of the minimum sized box that fits the matched cat head.",
			"c", parse_width_height, args);

	ret |= cargo_add_option(cargo, 0,
			"<haar> --no_match_is_fail",
			"If no cat head is found in the picture, consider this a failure. "
			"The default is to only consider found prey a failure.",
			"b", &args->no_match_is_fail);

	ret |= cargo_add_option(cargo, 0,
			"<haar> --equalize_histogram --eqhist",
			"Equalize the histogram of the image before doing. "
			"the haar cascade detection step.",
			"b", &args->eq_histogram);

	ret |= cargo_add_option(cargo, 0,
			"<haar> --prey_steps",
			"Only applicable for normal prey mode. 2 means a secondary "
			"search should be made if no prey is found initially.",
			"i", &args->prey_steps);
	ret |= cargo_set_metavar(cargo,
			"--prey_steps",
			"1|2");
	ret |= cargo_add_validation(cargo, 0, "--prey_steps",
								cargo_validate_int_range(1, 2));

	ret |= cargo_add_option(cargo, 0,
			"<haar> --prey_method",
			"Sets the prey matching method. Adaptive combines the result "
			"of both a global and adaptive thresholding to be better able to "
			"find prey parts otherwise blended into the background. "
			"Normal is simpler and doesn't catch such corner cases as well.",
			"c", parse_prey_method, &args->prey_method);
	ret |= cargo_set_metavar(cargo,
			"--prey_method",
			"ADAPTIVE|NORMAL");

	return ret;
}
Example #9
0
int main(int argc, char **argv)
{
    cargo_t cargo;
    int ret = 0;
    size_t i;
    char **args = NULL;
    size_t args_count = 0;
    int verbose = 0;
    int help = 0;
    int stop_index = 0;
    cmd_t cmd = INVALID_COMMAND;

    if (cargo_init(&cargo, CARGO_AUTOCLEAN | CARGO_NO_AUTOHELP, "%s", argv[0]))
    {
        fprintf(stderr, "Failed to init command line parsing\n");
        return -1;
    }

    //
    // Commands, one required, but only one at a time.
    //
    ret |= cargo_add_mutex_group(cargo,
            CARGO_MUTEXGRP_ONE_REQUIRED |
            CARGO_MUTEXGRP_GROUP_USAGE,
            "cmds", "Commands", NULL);
    ret |= cargo_mutex_group_set_metavar(cargo, "cmds", "COMMAND");

    // This option will stop the parsing.
    ret |= cargo_add_option(cargo, CARGO_OPT_NOT_REQUIRED | CARGO_OPT_STOP,
            "<!cmds> command1",
            "Silly example command", "c", parse_command_cb, &cmd);

    // This is just a dummy, it will not parse anything that is left to command1
    // but still show up in usage and so on.
    ret |= cargo_add_option(cargo, CARGO_OPT_NOT_REQUIRED,
            "<!cmds> command2",
            "Another silly example command", "c0", NULL, NULL);

    ret |= cargo_add_option(cargo, CARGO_OPT_NOT_REQUIRED,
            "<!cmds> command3",
            "The third silly command", "D");

    //
    // Some other arguments.
    //

    ret |= cargo_add_option(cargo, 0, "--help --usage -h", NULL, "b", &help);
    ret |= cargo_set_option_description(cargo, "--help",
            "Show this help.                         \n"
            "To get help for any of the commands:\n"
            " %s COMMAND --help", argv[0]);

    // Allow -vvv or multiple --verbosity and -v are counted to raise the count.
    ret |= cargo_add_option(cargo, 0, "--verbose -v",
            "Verbosity", "b!", &verbose);

    ret |= cargo_add_option(cargo, CARGO_OPT_NOT_REQUIRED, "args",
            "Some more args", "D", &args, &args_count);
    ret |= cargo_set_metavar(cargo, "args", "ARGS ...");

    assert(ret == 0);

    if (cargo_parse(cargo, CARGO_NOERR_OUTPUT,
                    1, argc, argv))
    {
        if (help)
        {
            cargo_print_usage(cargo, 0);
            return 0;
        }

        fprintf(stderr, "%s\n", cargo_get_error(cargo));
        return -1;
    }

    if (help)
    {
        cargo_print_usage(cargo, 0);
        return 0;
    }

    stop_index = cargo_get_stop_index(cargo);
    printf("Stop index: %d\n", stop_index);

    switch (cmd)
    {
        default:
        case INVALID_COMMAND: printf("Invalid command\n"); break;
        case COMMAND1: printf("Command 1\n"); subcommand1(stop_index, argc, argv); break;
        case COMMAND2: printf("Command 2\n"); subcommand2(stop_index, argc, argv); break;
        case COMMAND3: printf("Command 3\n"); break;
    }

    if (verbose)
    {
        printf("Got %lu extra arguments\n", args_count);
    }

    if (verbose >= 2)
    {
        for (i = 0; i < args_count; i++)
        {
            printf("%s\n", args[i]);
        }
    }

    cargo_destroy(&cargo);
    return 0;
}
Example #10
0
int main(int argc, char **argv)
{
    int ret = 0;
    cargo_t cargo;
    size_t i;
    const char **args = NULL;
    size_t args_count = 0;
    rect_t rect;
    rect_t *rects = NULL;
    size_t rect_count = 0;
    rect_t squares[4];
    size_t squares_count = 0;
    memset(&rect, 0, sizeof(rect));

    if (cargo_init(&cargo, 0, "%s", argv[0]))
    {
        fprintf(stderr, "Failed to init command line parsing\n");
        return -1;
    }

    ret |= cargo_add_option(cargo, 0, "--rect","The rect",
                            "c", parse_rect_cb, &rect);

    // Allocated array with "unlimited" count.
    ret |= cargo_add_option(cargo, 0, "--rectangles --rects -r", "Rectangles",
                            "[c]+", parse_rect_list_cb, &rects, &rect_count);

    // Fixed size array.
    ret |= cargo_add_option(cargo, 0, "--squares --sq -s", "Squares",
                            "[c]#", parse_rect_static_list_cb,
                            &squares, &squares_count,
                            sizeof(squares) / sizeof(squares[0])); // Max elements.
    assert(ret == 0);

    if (cargo_parse(cargo, 0, 1, argc, argv))
    {
        return -1;
    }

    args = cargo_get_args(cargo, &args_count);

    // Print remaining commandline arguments.
    for (i = 0; i < args_count; i++)
    {
        printf("Extra argument: %s\n", args[i]);
    }

    printf("Lone Rectangle: %d x %d\n", rect.width, rect.height);

    for (i = 0; i < rect_count; i++)
    {
        printf("Rectangle %lu: %d x %d\n",
              (i + 1), rects[i].width, rects[i].height);
    }

    for (i = 0; i < squares_count; i++)
    {
        printf("Square %lu: %d x %d\n",
              (i + 1), squares[i].width, squares[i].height);
    }


    cargo_destroy(&cargo);

    return 0;
}