SampleMarkerlessCreator.cpp
Go to the documentation of this file.
00001 #include "FernImageDetector.h"
00002 using namespace std;
00003 using namespace alvar;
00004 
00005 int main(int argc, char *argv[])
00006 {
00007     try {
00008         // Output usage message
00009         std::string filename(argv[0]);
00010         filename = filename.substr(filename.find_last_of('\\') + 1);
00011         std::cout << "SampleMarkerlessCreator" << std::endl;
00012         std::cout << "=======================" << std::endl;
00013         std::cout << std::endl;
00014         std::cout << "Description:" << std::endl;
00015         std::cout << "  This is an example of how to use the 'FernImageDetector' class" << std::endl;
00016         std::cout << "  to train a Fern classifier for markerless image-based tracking." << std::endl;
00017         std::cout << "  The image should contain many unique features and be in the range" << std::endl;
00018         std::cout << "  of 200x200 to 500x500 pixels. A '.dat' file will be saved in the" << std::endl;
00019         std::cout << "  same directory as the image and can be used with the" << std::endl;
00020         std::cout << "  SampleMarkerlessDetector sample." << std::endl;
00021         std::cout << std::endl;
00022         std::cout << "Usage:" << std::endl;
00023         std::cout << "  " << filename << " filename" << std::endl;
00024         std::cout << std::endl;
00025         std::cout << "    filename filename of image to train" << std::endl;
00026         std::cout << std::endl;
00027 
00028         if (argc < 2) {
00029             std::cout << "Filename not specified." << std::endl;
00030             return 0;
00031         }
00032 
00033         std::cout << "Training classifier." << std::endl;
00034         FernImageDetector fernDetector(true);
00035         std::string imageFilename(argv[1]);
00036         fernDetector.train(imageFilename);
00037 
00038         std::cout << "Writing classifier." << std::endl;
00039         std::string classifierFilename = imageFilename + ".dat";
00040         if (!fernDetector.write(classifierFilename)) {
00041             std::cout << "Writing classifier failed." << std::endl;
00042             return 1;
00043         }
00044 
00045         return 0;
00046     }
00047     catch (const std::exception &e) {
00048         std::cout << "Exception: " << e.what() << endl;
00049     }
00050     catch (...) {
00051         std::cout << "Exception: unknown" << std::endl;
00052     }
00053 }


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Jun 6 2019 21:12:54