diff --git a/dollar/Engine.cpp b/dollar/Engine.cpp index 4c856b5..92af993 100644 --- a/dollar/Engine.cpp +++ b/dollar/Engine.cpp @@ -177,6 +177,9 @@ static float calculatePPlusDistance(const std::vector& _points, } } if (kkkBest != -1) { + if (bestDistance > 0.2*0.2) { + // reject the distance ... + } int32_t previous = usedId[kkkBest]; usedId[kkkBest] = iii; distance[iii] = bestDistance; @@ -533,7 +536,7 @@ dollar::Results dollar::Engine::recognizePPlus(const std::vector> dataPair; distance = calculatePPlusDistance(points, gesture.getEnginePoints(), dataPair); - storeSVG("out/KKK_" + gesture.getName() + "_" + etk::to_string(gesture.getId()) + ".svg", gesture, _strokes, points, dataPair); + storeSVG("out_dollar/lib/recognizePPlus/" + gesture.getName() + "_" + etk::to_string(gesture.getId()) + ".svg", gesture, _strokes, points, dataPair); for (size_t kkk=0; kkk> uniPath = dollar::makeReferenceStrokes(m_path); // normalize paths diff --git a/lutin_dollar-generate-form.py b/lutin_dollar-generate-form.py new file mode 100644 index 0000000..6aa3b6e --- /dev/null +++ b/lutin_dollar-generate-form.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +import lutin.module as module +import lutin.tools as tools + + +def get_type(): + return "BINARY" + +def get_sub_type(): + return "TOOL" + +def get_desc(): + return "Dollar converter svg to json and json to SVG" + +def get_licence(): + return "APACHE-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def create(target, module_name): + my_module = module.Module(__file__, module_name, get_type()) + my_module.add_src_file([ + 'tool/generate-form/main.cpp' + ]) + my_module.add_module_depend([ + 'dollar', + 'test-debug', + ]) + return my_module + diff --git a/tool/bench-corpus/main.cpp b/tool/bench-corpus/main.cpp index a5db3fe..c63b012 100644 --- a/tool/bench-corpus/main.cpp +++ b/tool/bench-corpus/main.cpp @@ -123,11 +123,11 @@ void annalyseResult(std::map +#include +#include + +#include +#include +#include +#include + +void usage(const std::string& _progName) { + TEST_PRINT("usage:"); + TEST_PRINT(" " << _progName << " [option] corpus_path"); + TEST_PRINT(" [option]"); + TEST_PRINT(" -h --help Display this help"); + TEST_PRINT(" parameters (must be here)"); + TEST_PRINT(" corpus_path Path of the corpus files"); +} + +bool testCorpus(const std::string& _srcCorpus); + +int main(int _argc, const char *_argv[]) { + // init etk log system and file interface: + etk::init(_argc, _argv); + 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 (srcCorpus == "") { + srcCorpus = arg; + continue; + } + usage(_argv[0]); + return -1; + } + if (srcCorpus == "") { + TEST_ERROR("Missing input or output"); + usage(_argv[0]); + return -1; + } + return testCorpus(srcCorpus); +} + +void generateFile(const std::string& _fileName, const std::vector& _list, const std::string& _refName) { + TEST_PRINT(" " << _fileName); + std::string data("\n"); + data += "\n"; + for (auto &itFile : _list) { + std::vector> strokes = dollar::scaleToOne(dollar::loadPoints(itFile)); + for (auto &itLines : strokes) { + data += " > strokes = dollar::scaleToOne(dollar::loadPoints(_refName)); + for (auto &itLines : strokes) { + data += " files = path.folderGetSub(false, true, "*.json"); + + TEST_PRINT("corpus have " << files.size() << " files"); + std::vector listOfElementInCorpus; + for (auto &it : files) { + if (etk::end_with(it, ".json") == true) { + std::vector path = etk::split(it, '/'); + std::string elemName = etk::split(path[path.size()-1],'_')[0]; + if (std::find(listOfElementInCorpus.begin(), listOfElementInCorpus.end(), elemName) == listOfElementInCorpus.end()) { + listOfElementInCorpus.push_back(elemName); + } + } + } +//listOfElementInCorpus.clear(); +//listOfElementInCorpus.push_back("z"); + TEST_PRINT(" will done for: " << listOfElementInCorpus); + for (auto &itTypeOfCorpus : listOfElementInCorpus) { + TEST_PRINT("---------------------------------------------------------------------------"); + TEST_PRINT("-- Generate FOR: '" << itTypeOfCorpus << "'"); + TEST_PRINT("---------------------------------------------------------------------------"); + std::vector fileFiltered; + for (auto &it : files) { + if (etk::end_with(it, ".json") == true) { + std::vector path = etk::split(it, '/'); + std::string filename = path[path.size()-1]; + if (etk::start_with(filename, itTypeOfCorpus) == true) { + fileFiltered.push_back(it); + } + } + } + TEST_PRINT("correlation of " << fileFiltered.size() << " files"); + std::vector> results; + results.resize(fileFiltered.size()); + for (auto &it : results) { + it.resize(fileFiltered.size(), OUT_OF_RANGE); + } + // Generate Full Files: + { + std::vector listPath; + for (size_t iii=0; iii> listPoints = dollar::loadPoints(fileFiltered[iii]); + gest.set(itTypeOfCorpus, 0, listPoints); + gest.configure(10, 8, false, 0.1); + dollar::Engine reco; + reco.addGesture(gest); + std::vector path = etk::split(fileFiltered[iii], '/'); + std::string filename = path[path.size()-1]; + TEST_DEBUG("Test : " << fileFiltered[iii]); + for (size_t jjj=0; jjj= jjj) { + // same element to compare ... result will be 0 ... + continue; + } + listPoints = dollar::loadPoints(fileFiltered[jjj]); + dollar::Results res = reco.recognize(listPoints, "$P+"); + results[iii][jjj] = res.getConfidence(); + results[jjj][iii] = res.getConfidence(); + path = etk::split(fileFiltered[jjj], '/'); + std::string filename2 = path[path.size()-1]; + TEST_DEBUG(" " << res.getConfidence() << " " << filename2); + } + } + TEST_PRINT("---------------------------------------------------------------------------"); + TEST_PRINT("-- annalyse result to create groups: " << fileFiltered.size()); + TEST_PRINT("---------------------------------------------------------------------------"); + int32_t residualValues = fileFiltered.size(); + int32_t subId = 1; + // Value to stop grouping in the same element ... + float groupSize = 1.0; + groupSize = 1.0; + while (residualValues > 0) { + std::vector countMinimum; + countMinimum.resize(fileFiltered.size(), 0); + for (size_t iii=0; iii bestCount) { + bestCount = countMinimum[iii]; + bestId = iii; + } + } + if (bestId == -1) { + TEST_ERROR("No more elements ... residualValues=" << residualValues); + //==> Exit loop + residualValues = 0; + continue; + } else { + TEST_INFO("find NB element : " << countMinimum[bestId] << " for ID=" << bestId); + } + // Order the result for the bestID ==> permit to show if it is possible to do a better case ... + std::vector linkIds; + for (size_t jjj=0; jjj> ordered; + for (size_t jjj=0; jjj= OUT_OF_RANGE) { + continue; + } + auto it = ordered.begin(); + bool added = false; + while (it != ordered.end()) { + if (it->first > val) { + ordered.insert(it, std::make_pair(val, jjj)); + added = true; + break; + } + ++it; + } + if (added == false) { + ordered.push_back(std::make_pair(val, jjj)); + } + } + // enable/disable grouping auto ... + if (false) { + float lastValue = 0.0; + linkIds.clear(); + for (size_t jjj=0; jjj path = etk::split(fileFiltered[ordered[jjj].second], '/'); + std::string filename = path[path.size()-1]; + std::string tmppp = " "; + if (jjj listPath; + for (size_t iii=0; iii