#include #include #include using std::string; #include using std::vector; #include using std::ifstream; using std::getline; #include using std::stringstream; #include using std::cerr; using std::endl; #include using cv::Rect; using cv::Size; #include using cv::imread; #include using cv::CommandLineParser; using cv::FileStorage; #include using cv::xobjdetect::ICFDetectorParams; using cv::xobjdetect::ICFDetector; using cv::xobjdetect::WaldBoost; using cv::xobjdetect::WaldBoostParams; using cv::Mat; static bool read_model_size(const char *str, int *rows, int *cols) { int pos = 0; if( sscanf(str, "%dx%d%n", rows, cols, &pos) != 2 || str[pos] != '\0' || *rows <= 0 || *cols <= 0) { return false; } return true; } int main(int argc, char *argv[]) { const string keys = "{help | | print this message}" "{pos_path | pos | path to training object samples}" "{bg_path | bg | path to background images}" "{feature_count | 10000 | number of features to generate}" "{weak_count | 100 | number of weak classifiers in cascade}" "{model_size | 40x40 | model size in pixels}" "{model_filename | model.xml | filename for saving model}" ; CommandLineParser parser(argc, argv, keys); parser.about("FCW trainer"); if( parser.has("help") || argc == 1) { parser.printMessage(); return 0; } string pos_path = parser.get("pos_path"); string bg_path = parser.get("bg_path"); string model_filename = parser.get("model_filename"); cerr << pos_path << endl; cerr << bg_path << endl; ICFDetectorParams params; params.feature_count = parser.get("feature_count"); params.weak_count = parser.get("weak_count"); string model_size = parser.get("model_size"); if( !read_model_size(model_size.c_str(), ¶ms.model_n_rows, ¶ms.model_n_cols) ) { cerr << "Error reading model size from `" << model_size << "`" << endl; return 1; } if( !parser.check() ) { parser.printErrors(); return 1; } ICFDetector detector; detector.train(pos_path, bg_path, params); FileStorage fs(model_filename, FileStorage::WRITE); fs << "icfdetector" << detector; fs.release(); }