Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages

Class List for drwnVision

drwnVision API Examples

The following code shows an example of learning and then executing a pixel classifier based on RGB features. For more sophisticated pixel labeling see drwnSegImageInstance and drwnPixelSegModel.

// load image and labels
cv::Mat img = cv::imread("image.png", CV_LOAD_IMAGE_COLOR);
MatrixXi labels;
drwnLoadPixelLabels(labels, "labels.txt");
// build a training dataset
dataset.reserve(img.size());
for (int y = 0; y < img.rows; y++) {
for (int x = 0; x < img.cols; x++) {
if (labels(y, x) < 0) continue;
vector<double> features(3);
features[0] = img.at<Vec3b>(y, x)[0];
features[1] = img.at<Vec3b>(y, x)[1];
features[2] = img.at<Vec3b>(y, x)[2];
dataset.append(features, labels(y, x));
}
}
DRWN_LOG_MESSAGE("dataset contains " << dataset.size() << " training samples");
dataset.subSample(2, true);
DRWN_LOG_MESSAGE("subsampled to " << dataset.size() << " training samples");
// train a decision tree classifier to depth of 10
const int nClasses = dataset.maxTarget() + 1;
drwnDecisionTree classifier(dataset.numFeatures(), nClasses);
classifier.train(dataset);
// display classification results (on training set)
drwnConfusionMatrix results(nClasses);
results.accumulate(dataset, &classifier);
results.printCounts();

The following code shows an example of drawing bounding boxes for a list of objects.

// load objects
objects.read(OBJECTS_FILENAME);
// load image
cv::Mat img = cv::imread(IMAGE_FILENAME, CV_LOAD_IMAGE_COLOR);
// draw objects
for (drwnObjectList::const_iterator it = objects.begin(); it != objects.end(); it++) {
drwnDrawBoundingBox(img, it->extent, CV_RGB(255, 0, 0), CV_RGB(0, 0, 0), 2);
}
// show image with objects
drwnShowDebuggingImage(img, "objects", true);