diff --git a/dollar/Engine.cpp b/dollar/Engine.cpp index 714578e..b6a7516 100644 --- a/dollar/Engine.cpp +++ b/dollar/Engine.cpp @@ -55,6 +55,7 @@ static float pathDistance(const std::vector& _path1, const std::vector16, "NB element in a path must be > 16 ..."); @@ -78,19 +79,29 @@ size_t dollar::Engine::getNumberPointInGesture() { } void dollar::Engine::setPPlusDistance(float _value) { - if (_value == m_PPlusDistance) { + if (_value*_value == m_PPlusDistance*) { return; } - m_PPlusDistance = _value; + m_PPlusDistance = _value*_value; for (auto &it: m_gestures) { it.configure(m_numPointsInGesture/RATIO_START_VECTOR, m_numPointsInGesture, m_paramterIgnoreRotation, m_PPlusDistance, m_scaleKeepRatio); } } float dollar::Engine::getPPlusDistance() { - return m_PPlusDistance; + return std::sqrt(m_PPlusDistance); } +void dollar::Engine::setPPlusExcludeDistance(float _value) { + if (_value == m_PPlusExcludeDistance) { + return; + } + m_PPlusExcludeDistance = _value; +} + +float dollar::Engine::getPPlusExcludeDistance() { + return m_PPlusExcludeDistance; +} void dollar::Engine::setScaleKeepRatio(bool _value) { if (_value == m_scaleKeepRatio) { return; @@ -207,7 +218,7 @@ static float calculatePPlusDistance(const std::vector& _points, } if (kkkBest != -1) { // reject the distance ... if too big ... - if (bestDistance <= 0.2*0.2) { + if (bestDistance <= m_PPlusExcludeDistance) { int32_t previous = usedId[kkkBest]; usedId[kkkBest] = iii; distance[iii] = bestDistance; @@ -560,7 +571,7 @@ dollar::Results dollar::Engine::recognizePPlus(const std::vector dollar::translateBariCenterToZero(std::vector _points) { static std::vector discretize(std::vector _points, float _interval) { std::vector out; + if (_points.size() == 0) { + return out; + } // same first point ==> no change out.push_back(_points.front()); float distance = 0.0f; @@ -137,6 +140,9 @@ static std::vector discretize(std::vector _points, float _interval) std::vector dollar::resample(std::vector _points, int32_t _nbPoints) { std::vector out; + if (_points.size() == 0) { + return out; + } // calculate the interval between every points ... float interval = pathLength(_points) / (_nbPoints - 1); out = discretize(_points, interval); @@ -191,6 +197,9 @@ std::vector dollar::combineStrokes(const std::vector>& _ vec2 dollar::getStartVector(const std::vector& _points, float _index) { DOLLAR_ASSERT(_index > 0, "index must be != of 0"); + if (_points.size() <= _index) { + return vec2(1.0, 0.0); + } vec2 vect = _points[_index] - _points[0]; float len = vect.length(); return vect / len; diff --git a/tool/generate-form/main.cpp b/tool/generate-form/main.cpp index 14fa097..b2fe26b 100644 --- a/tool/generate-form/main.cpp +++ b/tool/generate-form/main.cpp @@ -24,10 +24,20 @@ void usage(const std::string& _progName) { bool testCorpus(const std::string& _srcCorpus); +static bool keepAspectRatio = false; +static float distanceReference; // distance of the gesture reference [0.02, 0.3] +static float distanceCheck; // distance of the test points [0.02, 0.3] +static float distanceExclude; // distance of the exclusion point [0.1, 1.0] + +setScaleKeepRatio(keepAspectRatio); +setPPlusDistance(distanceReference); // to generate reference gesture +setPPlusDistance(distanceCheck); // to generate test gesture +setPPlusExcludeDistance(distanceExclude); 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" @@ -35,8 +45,27 @@ int main(int _argc, const char *_argv[]) { usage(_argv[0]); return 0; } - if( arg[0] == '-' - && arg[1] == '-') { + if (arg == "--keep_ratio") { + keepAspectRatio = true; + continue; + } + if (etk::start_with(arg,"--dist-ref=") == true) { + std::string val(&arg[11]); + distanceReference = etk::string_to_float(val); + continue; + } + if (etk::start_with(arg,"--dist-check=") == true) { + std::string val(&arg[13]); + distanceCheck = etk::string_to_float(val); + continue; + } + if (etk::start_with(arg,"--dist-excl=") == true) { + std::string val(&arg[12]); + distanceExclude = etk::string_to_float(val); + continue; + } + if ( arg[0] == '-' + && arg[1] == '-') { // subLibrary usage ... continue; } @@ -118,13 +147,14 @@ bool testCorpus(const std::string& _srcCorpus) { } } //listOfElementInCorpus.clear(); -//listOfElementInCorpus.push_back("z"); +//listOfElementInCorpus.push_back("slash"); // Value to stop grouping in the same element ... float groupSize = 1.0; groupSize = 1.0; bool keepAspectRatio = false; TEST_PRINT(" will done for: " << listOfElementInCorpus); + int32_t nbElementGenerated = 0; for (auto &itTypeOfCorpus : listOfElementInCorpus) { TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("-- Generate FOR: '" << itTypeOfCorpus << "'"); @@ -134,7 +164,7 @@ bool keepAspectRatio = false; 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) { + if (etk::start_with(filename, itTypeOfCorpus + "_") == true) { fileFiltered.push_back(it); } } @@ -321,8 +351,12 @@ bool keepAspectRatio = false; // Increment subId... subId++; + nbElementGenerated++; } } + TEST_PRINT("==========================================================================="); + TEST_PRINT("== Gererate Done: " << nbElementGenerated); + TEST_PRINT("==========================================================================="); return 0; }