SampleMarkerlessCreator.cpp
Go to the documentation of this file.
1 #include "FernImageDetector.h"
2 using namespace std;
3 using namespace alvar;
4 
5 int main(int argc, char *argv[])
6 {
7  try {
8  // Output usage message
9  std::string filename(argv[0]);
10  filename = filename.substr(filename.find_last_of('\\') + 1);
11  std::cout << "SampleMarkerlessCreator" << std::endl;
12  std::cout << "=======================" << std::endl;
13  std::cout << std::endl;
14  std::cout << "Description:" << std::endl;
15  std::cout << " This is an example of how to use the 'FernImageDetector' class" << std::endl;
16  std::cout << " to train a Fern classifier for markerless image-based tracking." << std::endl;
17  std::cout << " The image should contain many unique features and be in the range" << std::endl;
18  std::cout << " of 200x200 to 500x500 pixels. A '.dat' file will be saved in the" << std::endl;
19  std::cout << " same directory as the image and can be used with the" << std::endl;
20  std::cout << " SampleMarkerlessDetector sample." << std::endl;
21  std::cout << std::endl;
22  std::cout << "Usage:" << std::endl;
23  std::cout << " " << filename << " filename" << std::endl;
24  std::cout << std::endl;
25  std::cout << " filename filename of image to train" << std::endl;
26  std::cout << std::endl;
27 
28  if (argc < 2) {
29  std::cout << "Filename not specified." << std::endl;
30  return 0;
31  }
32 
33  std::cout << "Training classifier." << std::endl;
35  std::string imageFilename(argv[1]);
36  fernDetector.train(imageFilename);
37 
38  std::cout << "Writing classifier." << std::endl;
39  std::string classifierFilename = imageFilename + ".dat";
40  if (!fernDetector.write(classifierFilename)) {
41  std::cout << "Writing classifier failed." << std::endl;
42  return 1;
43  }
44 
45  return 0;
46  }
47  catch (const std::exception &e) {
48  std::cout << "Exception: " << e.what() << endl;
49  }
50  catch (...) {
51  std::cout << "Exception: unknown" << std::endl;
52  }
53 }
Main ALVAR namespace.
Definition: Alvar.h:174
This file implements a Fern-based image detector.
filename
FernImageDetector fernDetector(true)
Image detector based on a Fern classifier.
int main(int argc, char *argv[])
bool write(const std::string &filename, const bool binary=true)
void train(const std::string &filename)


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04