Skip to content
Benedikt Waldvogel edited this page Jul 16, 2013 · 5 revisions

The following code shows an example of how to use CURFIL as C++ library.

The example assumes that you already trained a random forest with three trees which are located in the current folder.

#include <iostream>
#include <vector>

#include <curfil/random_forest_image.h>
#include <curfil/predict.h>

int main(void) {

    std::vector<std::string> treeFiles;
    treeFiles.push_back("tree0.json.gz");
    treeFiles.push_back("tree1.json.gz");
    treeFiles.push_back("tree2.json.gz");

    // load a random forest with three decision trees
    curfil::RandomForestImage forest(treeFiles);

    // load a RGB-D image from disk for prediction
    curfil::RGBDImage image("01234_colors.png", "01234_depth.png");

    // execute the actual prediction
    curfil::LabelImage prediction = forest.predict(image);

    // store the prediction result
    prediction.save("prediction.png");

    // load the ground truth labeling
    curfil::LabelImage groundTruth("01234_ground_truth.png");

    // calculate pixel accuracy and the confusion matrix
    curfil::ConfusionMatrix confusionMatrix;
    bool includeVoid = false;
    double accuracy = curfil::calculatePixelAccuracy(prediction, groundTruth, includeVoid, &confusionMatrix);
    std::cout << "pixel accuracy without void: " << accuracy << std::endl;

    // print the confusion matrix
    std::cout << confusionMatrix << std::endl;

    return 0;
}

Make sure to link your code to libcurfil (eg. -lcurfil).

Clone this wiki locally