コード例 #1
0
int main(int argc, char *argv[])
{
    br_initialize(argc, argv);

    // Equivalent to 'Globals->algorithm = "FaceRecognion";' in C++ API
    br_set_property("algorithm", "FaceRecognition");

    // Equivalent to 'Globals->path = "../data/MEDS/img/";' in C++ API
    br_set_property("path", "../data/MEDS/img/");

    // Enroll galleries, don't re-enroll if they already exist (cache)
    br_enroll("../data/MEDS/sigset/MEDS_frontal_target.xml", "target.gal[cache]");
    br_enroll("../data/MEDS/sigset/MEDS_frontal_query.xml", "query.gal[cache]");

    // Compare galleries and store result in a binary similarity matrix
    br_compare("target.gal", "query.gal", "FaceRecognition_MEDS.mtx");

    // Make a ground truth "mask" matrix from the sigsets.
    br_make_mask("../data/MEDS/sigset/MEDS_frontal_target.xml", "../data/MEDS/sigset/MEDS_frontal_query.xml", "MEDS.mask");

    // Evaluate the performance of OpenBR's FaceRecognition and a COTS face recognition system.
    br_eval("FaceRecognition_MEDS.mtx", "MEDS.mask", "Algorithm_Dataset/FaceRecognition_MEDS.csv");

    // The '_' character has special significance and is used to populate plot legends.
    // Requires R installation, see documentation of br_plot for details.
    const char *files[1];
    files[0] = "Algorithm_Dataset/FaceRecognition_MEDS.csv";
    br_plot(1, files, "MEDS", true);

    br_finalize();
    return 0;
}
コード例 #2
0
ファイル: br.cpp プロジェクト: ThunderPower/openbr
    void run()
    {
        // Remove program name
        argv = &argv[1];
        argc--;

        if (argc == 0) printf("%s\nTry running 'br -help'\n", br_about());

        bool daemon = false;
        const char *daemon_pipe = NULL;
        while (daemon || (argc > 0)) {
            const char *fun;
            int parc;
            const char **parv;
            if (argc == 0)
                br_read_pipe(daemon_pipe, &argc, &argv);

            fun = argv[0];
            if (fun[0] == '-') fun++;
            parc = 0; while ((parc+1 < argc) && (argv[parc+1][0] != '-')) parc++;
            parv = (const char **)&argv[1];
            argc = argc - (parc+1);
            argv = &argv[parc+1];

            // Core Tasks
            if (!strcmp(fun, "train")) {
                check(parc >= 1, "Insufficient parameter count for 'train'.");
                br_train_n(parc == 1 ? 1 : parc-1, parv, parc == 1 ? "" : parv[parc-1]);
            } else if (!strcmp(fun, "enroll")) {
                check(parc >= 1, "Insufficient parameter count for 'enroll'.");
                if (parc == 1) br_enroll(parv[0]);
                else           br_enroll_n(parc-1, parv, parv[parc-1]);
            } else if (!strcmp(fun, "compare")) {
                check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'compare'.");
                br_compare(parv[0], parv[1], parc == 3 ? parv[2] : "");
            } else if (!strcmp(fun, "pairwiseCompare")) {
                check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'pairwiseCompare'.");
                br_pairwise_compare(parv[0], parv[1], parc == 3 ? parv[2] : "");
            } else if (!strcmp(fun, "eval")) {
                check((parc >= 1) && (parc <= 3), "Incorrect parameter count for 'eval'.");
                if (parc == 1) {
                    br_eval(parv[0], "", "");
                } else if (parc == 2) {
                    if (br::File(parv[1]).suffix() == "csv") br_eval(parv[0], "", parv[1]);
                    else                                     br_eval(parv[0], parv[1], "");
                } else {
                    br_eval(parv[0], parv[1], parv[2]);
                }
            } else if (!strcmp(fun, "plot")) {
                check(parc >= 2, "Incorrect parameter count for 'plot'.");
                br_plot(parc-1, parv, parv[parc-1], true);
            }

            // Secondary Tasks
            else if (!strcmp(fun, "fuse")) {
                check(parc >= 4, "Insufficient parameter count for 'fuse'.");
                br_fuse(parc-3, parv, parv[parc-3], parv[parc-2], parv[parc-1]);
            } else if (!strcmp(fun, "cluster")) {
                check(parc >= 3, "Insufficient parameter count for 'cluster'.");
                br_cluster(parc-2, parv, atof(parv[parc-2]), parv[parc-1]);
            } else if (!strcmp(fun, "makeMask")) {
                check(parc == 3, "Incorrect parameter count for 'makeMask'.");
                br_make_mask(parv[0], parv[1], parv[2]);
            } else if (!strcmp(fun, "makePairwiseMask")) {
                check(parc == 3, "Incorrect parameter count for 'makePairwiseMask'.");
                br_make_pairwise_mask(parv[0], parv[1], parv[2]);
            } else if (!strcmp(fun, "combineMasks")) {
                check(parc >= 4, "Insufficient parameter count for 'combineMasks'.");
                br_combine_masks(parc-2, parv, parv[parc-2], parv[parc-1]);
            } else if (!strcmp(fun, "cat")) {
                check(parc >= 2, "Insufficient parameter count for 'cat'.");
                br_cat(parc-1, parv, parv[parc-1]);
            } else if (!strcmp(fun, "convert")) {
                check(parc == 3, "Incorrect parameter count for 'convert'.");
                br_convert(parv[0], parv[1], parv[2]);
            } else if (!strcmp(fun, "evalClassification")) {
                check(parc >= 2 && parc <= 4, "Incorrect parameter count for 'evalClassification'.");
                br_eval_classification(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? parv[3] : "");
            } else if (!strcmp(fun, "evalClustering")) {
                check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalClustering'.");
                br_eval_clustering(parv[0], parv[1], parc == 3 ? parv[2] : "");
            } else if (!strcmp(fun, "evalDetection")) {
                check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalDetection'.");
                br_eval_detection(parv[0], parv[1], parc == 3 ? parv[2] : "");
            } else if (!strcmp(fun, "evalLandmarking")) {
                check((parc >= 2) && (parc <= 5), "Incorrect parameter count for 'evalLandmarking'.");
                br_eval_landmarking(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? atoi(parv[3]) : 0, parc >= 5 ? atoi(parv[4]) : 1);
            } else if (!strcmp(fun, "evalRegression")) {
                check(parc >= 2 && parc <= 4, "Incorrect parameter count for 'evalRegression'.");
                br_eval_regression(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? parv[3] : "");
            } else if (!strcmp(fun, "plotDetection")) {
                check(parc >= 2, "Incorrect parameter count for 'plotDetection'.");
                br_plot_detection(parc-1, parv, parv[parc-1], true);
            } else if (!strcmp(fun, "plotLandmarking")) {
                check(parc >= 2, "Incorrect parameter count for 'plotLandmarking'.");
                br_plot_landmarking(parc-1, parv, parv[parc-1], true);
            } else if (!strcmp(fun, "plotMetadata")) {
                check(parc >= 2, "Incorrect parameter count for 'plotMetadata'.");
                br_plot_metadata(parc-1, parv, parv[parc-1], true);
            } else if (!strcmp(fun, "deduplicate")) {
                check(parc == 3, "Incorrect parameter count for 'deduplicate'.");
                br_deduplicate(parv[0], parv[1], parv[2]);
            }

            // Miscellaneous
            else if (!strcmp(fun, "help")) {
                check(parc == 0, "No parameters expected for 'help'.");
                help();
            } else if (!strcmp(fun, "gui")) {
                // Do nothing because we checked for this flag prior to initialization
            } else if (!strcmp(fun, "objects")) {
                check(parc <= 2, "Incorrect parameter count for 'objects'.");
                int size = br_objects(NULL, 0, parc >= 1 ? parv[0] : ".*", parc >= 2 ? parv[1] : ".*");
                char * temp = new char[size];
                br_objects(temp, size, parc >= 1 ? parv[0] : ".*", parc >= 2 ? parv[1] : ".*");
                printf("%s\n", temp);
                delete [] temp;
            } else if (!strcmp(fun, "about")) {
                check(parc == 0, "No parameters expected for 'about'.");
                printf("%s\n", br_about());
            } else if (!strcmp(fun, "version")) {
                check(parc == 0, "No parameters expected for 'version'.");
                printf("%s\n", br_version());
            } else if (!strcmp(fun, "daemon")) {
                check(parc == 1, "Incorrect parameter count for 'daemon'.");
                daemon = true;
                daemon_pipe = parv[0];
            } else if (!strcmp(fun, "slave")) {
                check(parc == 1, "Incorrect parameter count for 'slave'");
                br_slave_process(parv[0]);
            } else if (!strcmp(fun, "exit")) {
                check(parc == 0, "No parameters expected for 'exit'.");
                daemon = false;
            } else if (!strcmp(fun, "getHeader")) {
                check(parc == 1, "Incorrect parameter count for 'getHeader'.");
                const char *target_gallery, *query_gallery;
                br_get_header(parv[0], &target_gallery, &query_gallery);
                printf("%s\n%s\n", target_gallery, query_gallery);
            } else if (!strcmp(fun, "setHeader")) {
                check(parc == 3, "Incorrect parameter count for 'setHeader'.");
                br_set_header(parv[0], parv[1], parv[2]);
            } else if (!strcmp(fun, "br")) {
                printf("That's me!\n");
            } else if (parc <= 1) {
                br_set_property(fun, parc >=1 ? parv[0] : "");
            } else {
                printf("Unrecognized function '%s'\n", fun);
            }
        }

        QCoreApplication::exit();
    }