From 53cd0512926dd5bafa696abf9fb15cae54c4b504 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 24 Aug 2016 00:45:42 +0200 Subject: [PATCH] [DEBUG] correct + algorithm --- dollar/Engine.cpp | 107 +++++++++++++++++++++++++++++++++++++++++----- dollar/Gesture.h | 3 ++ dollar/tools.cpp | 3 +- 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/dollar/Engine.cpp b/dollar/Engine.cpp index 321896f..e5bdcfd 100644 --- a/dollar/Engine.cpp +++ b/dollar/Engine.cpp @@ -146,13 +146,18 @@ static float calculateBestDistance(const std::vector& _points, const std:: } -static float calculatePPlusDistance(const std::vector& _points, const std::vector& _reference, std::vector& _dataDebug) { +static float calculatePPlusDistance(const std::vector& _points, + const std::vector& _reference, + std::vector>& _dataDebug) { std::vector distance; // note: use square distance (faster, we does not use std::sqrt()) distance.resize(_points.size(), MAX_FLOAT); // point Id that is link on the reference. std::vector usedId; usedId.resize(_reference.size(), -1); - + #ifdef PLOPPPPPPPPPP + std::vector usedId2; + usedId2.resize(_points.size(), -1); + #endif for (int32_t iii=0; iii<_points.size(); iii++) { if (distance[iii] < 100.0) { continue; @@ -161,6 +166,7 @@ static float calculatePPlusDistance(const std::vector& _points, const std: int32_t kkkBest = -1; for (int32_t kkk=0; kkk<_reference.size(); ++kkk) { float dist = (_points[iii]-_reference[kkk]).length2(); + #ifndef PLOPPPPPPPPPP if (usedId[kkk] != -1) { if (dist < distance[usedId[kkk]]) { if (dist < bestDistance) { @@ -168,7 +174,9 @@ static float calculatePPlusDistance(const std::vector& _points, const std: kkkBest = kkk; } } - } else { + } else + #endif + { if (dist < bestDistance) { bestDistance = dist; kkkBest = kkk; @@ -176,13 +184,21 @@ static float calculatePPlusDistance(const std::vector& _points, const std: } } if (kkkBest != -1) { + #ifndef PLOPPPPPPPPPP int32_t previous = usedId[kkkBest]; + #endif usedId[kkkBest] = iii; distance[iii] = bestDistance; + //DOLLAR_INFO("set new link: " << iii << " with " << kkkBest << " d=" << bestDistance); + #ifndef PLOPPPPPPPPPP if (previous != -1) { + //DOLLAR_INFO(" Reject : " << previous); distance[previous] = MAX_FLOAT; iii = previous-1; } + #else + usedId2[iii] = kkkBest; + #endif } } double fullDistance = 0; @@ -191,25 +207,35 @@ static float calculatePPlusDistance(const std::vector& _points, const std: // now we count the full distance use and the number of local gesture not use for (auto &it : distance) { if (it < 100.0) { - fullDistance = it; + fullDistance += it; } else { - // TODO : Only for debug nbTestNotUsed++; } } - // TODO : Only for debug // we count the number of point in the gesture reference not used: for (auto &it : usedId) { if (it == -1) { nbReferenceNotUsed++; } } + // now we add panality: + fullDistance += float(nbTestNotUsed)* 0.1f; + fullDistance += float(nbReferenceNotUsed)* 0.1f; + // TODO : Only for debug - for (int32_t kkk=0; kkk<_reference.size(); ++kkk) { - if (it != -1) { - _dataDebug.push_back(std::make_pair(it, kkk)); + #ifndef PLOPPPPPPPPPP + for (int32_t kkk=0; kkk\n"); + data += "\n"; + for (auto &itLines : gesture.getPath()) { + data += " refListPoint = gesture.getEnginePoints(); + for (auto &it : refListPoint) { + data += " \n"; + } + std::vector testListPoint = _points; + for (auto &it : testListPoint) { + data += " \n"; + } + for (auto &it : _links) { + data += " >& _strokes) { std::vector points = dollar::normalizePathToPoints(_strokes, m_PPlusDistance); // Keep maximum 5 results ... @@ -469,8 +553,9 @@ dollar::Results dollar::Engine::recognizePPlus(const std::vector dataPair; + std::vector> dataPair; distance = calculatePPlusDistance(points, gesture.getEnginePoints(), dataPair); + storeSVG("out/KKK_" + gesture.getName() + "_" + etk::to_string(gesture.getId()) + ".svg", gesture, _strokes, points, dataPair); for (size_t kkk=0; kkk>& getPath() const { return m_path; } diff --git a/dollar/tools.cpp b/dollar/tools.cpp index 2702ce6..12f9f09 100644 --- a/dollar/tools.cpp +++ b/dollar/tools.cpp @@ -234,5 +234,6 @@ std::vector dollar::normalizePathToPoints(std::vector> _ out.push_back(it[it.size()-1]); } } - return translateBariCenterToZero(out); + return out; + // NOTE: this is a bad idea ... return translateBariCenterToZero(out); } \ No newline at end of file