/** @file * @author Edouard DUPIN * @copyright 2016, Edouard DUPIN, all right reserved * @license APACHE v2.0 (see license file) */ #include #include #include #include #include #include #include void usage(const std::string& _progName) { TEST_PRINT("usage:"); TEST_PRINT(" " << _progName << " [option] reference_gesture corpus_path"); TEST_PRINT(" [option]"); TEST_PRINT(" -h --help Display this help"); TEST_PRINT(" parameters (must be here)"); TEST_PRINT(" reference_gesture Path of the reference gestures"); TEST_PRINT(" corpus_path Path of the corpus files"); } bool testCorpus(const std::string& _srcGesture, const std::string& _srcCorpus); int main(int _argc, const char *_argv[]) { // init etk log system and file interface: etk::init(_argc, _argv); std::string srcGesture; std::string srcCorpus; for (int32_t iii=1; iii<_argc; ++iii) { std::string arg = _argv[iii]; if ( arg == "-h" || arg == "--help") { usage(_argv[0]); return 0; } if( arg[0] == '-' && arg[1] == '-') { // subLibrary usage ... continue; } if (srcGesture == "") { srcGesture = arg; continue; } if (srcCorpus == "") { srcCorpus = arg; continue; } usage(_argv[0]); return -1; } if ( srcGesture == "" || srcCorpus == "") { TEST_ERROR("Missing input or output"); usage(_argv[0]); return -1; } return testCorpus(srcGesture, srcCorpus); } void generateFile(const std::string& _fileName, const std::vector& _list) { std::string data("\n"); data += "\n"; for (auto &itFile : _list) { std::vector> strokes = dollar::scaleToOne(dollar::loadPoints(itFile)); for (auto &itLines : strokes) { data += " >>& _result) { TEST_PRINT("Full results:"); for (auto &it : _result) { int32_t nbRecognise = 0; int32_t nbtested = 0; std::string label = etk::split(it.first, ' ')[0]; std::string type = etk::split(it.first, ' ')[1]; std::vector listFull; std::vector listWrong; std::map wrongValues; for (auto itRes : it.second) { nbtested ++; listFull.push_back(itRes.second); if (label == itRes.first.getName()) { nbRecognise++; } else { listWrong.push_back(itRes.second); if (wrongValues.find(itRes.first.getName()) != wrongValues.end()) { wrongValues[itRes.first.getName()]++; } else { wrongValues[itRes.first.getName()] = 1; } } } float ratio = float(nbRecognise) / float(nbtested) * 100.0f; if (ratio <= 50.0) { TEST_ERROR(" '" << label << " " << type << "': " << nbRecognise << " / " << nbtested << " ==> " << ratio << " %"); } else if (ratio <= 75.0) { TEST_WARNING(" '" << label << " " << type << "': " << nbRecognise << " / " << nbtested << " ==> " << ratio << " %"); } else { TEST_INFO(" '" << label << " " << type << "': " << nbRecognise << " / " << nbtested << " ==> " << ratio << " %"); } if (ratio != 100.0f) { for (auto &it : wrongValues) { TEST_WARNING(" " << it.first << " " << it.second << ""); } } generateFile("generate/OK/" + label + "_" + type + ".svg", listFull); if (listWrong.size() != 0) { generateFile("generate/ERROR/" + label + "_" + type + "_ERROR.svg", listWrong); } else { etk::FSNodeRemove("generate/ERROR/" + label + "_" + type + "_ERROR.svg"); } } } bool testCorpus(const std::string& _srcGesture, const std::string& _srcCorpus) { // declare a Gesture (internal API) dollar::Engine reco; TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("-- Load Gestures: " << _srcGesture); TEST_PRINT("---------------------------------------------------------------------------"); // Load gesture with his extention type: if (reco.loadPath(_srcGesture) == false) { TEST_ERROR("Error when loading the gestures"); return -1; } TEST_DEBUG("List all file in the corpus path"); etk::FSNode path(_srcCorpus); std::vector files = path.folderGetSub(false, true, "*.json"); TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("-- test gestures: "); TEST_PRINT("---------------------------------------------------------------------------"); // "label_type" ==> list of (result, file test name) std::map>> agregateResults; int32_t nbRecognise = 0; int32_t nbtested = 0; for (auto &it : files) { std::string label; std::string type; std::vector> listPoints = dollar::loadPoints(it, &label, &type); if (type == "hand") { //continue; // rejest for now ... } nbtested++; std::vector path = etk::split(it, '/'); std::string filename = path[path.size()-1]; TEST_PRINT("Test '" << label << "' type=" << type << " " << filename); dollar::Results res = reco.recognize(listPoints, "$P+"); agregateResults[label+" "+type].push_back(std::make_pair(res,it)); if (res.haveMath() == false) { TEST_INFO(" Recognise noting ..."); continue; } #if 0 TEST_INFO("Results : "); for (size_t iii=0; iii " << (float(nbRecognise) / float(nbtested) * 100.0f) << " %"); // All is done corectly return 0; }