[DEV] add penality of keep aspect ratio
This commit is contained in:
parent
9f21d607d3
commit
d5a06b49f6
11
README.md
11
README.md
@ -71,6 +71,17 @@ We check directly on the corpus reference
|
||||
lutin -cclang -mdebug dollar-bench-corpus?build?run:--keep_ratio:out_dollar/generate-form/corpus:appl_private/dollar/data/corpus/
|
||||
|
||||
|
||||
Bench result auto corpus test ...
|
||||
---------------------------------
|
||||
|
||||
Test with a keep ratio: 81.62%
|
||||
Test with a No keep ratio: 75.63%
|
||||
Test with a keep ratio <75%: 80.80%
|
||||
Automatic detect keep ratio: 54% ==> remove code duplication
|
||||
Test keep ratio with a panality of distance: 81.92%
|
||||
idem previous + check the number of points
|
||||
|
||||
|
||||
License (APACHE v2.0)
|
||||
=====================
|
||||
Copyright dollar Edouard DUPIN
|
||||
|
@ -145,7 +145,9 @@ float dollar::EnginePPlus::calculatePPlusDistanceSimple(const std::vector<vec2>&
|
||||
|
||||
float dollar::EnginePPlus::calculatePPlusDistance(const std::vector<vec2>& _points,
|
||||
const std::vector<vec2>& _reference,
|
||||
std::vector<std::pair<int32_t, int32_t>>& _dataDebug) {
|
||||
std::vector<std::pair<int32_t, int32_t>>& _dataDebug,
|
||||
float _inputAspectRatio,
|
||||
float _referenceAspectRatio) {
|
||||
std::vector<float> 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.
|
||||
@ -208,6 +210,8 @@ float dollar::EnginePPlus::calculatePPlusDistance(const std::vector<vec2>& _poin
|
||||
// now we add panality:
|
||||
fullDistance += float(nbTestNotUsed)* m_penalityNotLinkSample;
|
||||
fullDistance += float(nbReferenceNotUsed)* m_penalityNotLinkRef;
|
||||
fullDistance += std::abs(_inputAspectRatio - _referenceAspectRatio)*m_penalityNotLinkRef;
|
||||
|
||||
|
||||
for (size_t kkk=0; kkk<usedId.size(); ++kkk) {
|
||||
if (usedId[kkk] != -1) {
|
||||
@ -297,8 +301,8 @@ static void storeSVG(const std::string& _fileName,
|
||||
|
||||
|
||||
dollar::Results dollar::EnginePPlus::recognize2(const std::vector<std::vector<vec2>>& _strokes) {
|
||||
std::vector<vec2> points = dollar::normalizePathToPoints(_strokes, m_PPlusDistance, false);
|
||||
std::vector<vec2> pointsKeep = dollar::normalizePathToPoints(_strokes, m_PPlusDistance, true);
|
||||
std::vector<vec2> points = dollar::normalizePathToPoints(_strokes, m_PPlusDistance, m_scaleKeepRatio);
|
||||
float inputAspectRatio = dollar::getAspectRatio(_strokes);
|
||||
// Keep maximum 5 results ...
|
||||
float bestDistance[m_nbResult];
|
||||
int32_t indexOfBestMatch[m_nbResult];
|
||||
@ -323,11 +327,7 @@ dollar::Results dollar::EnginePPlus::recognize2(const std::vector<std::vector<ve
|
||||
*/
|
||||
float distance = MAX_FLOAT;
|
||||
std::vector<std::pair<int32_t, int32_t>> dataPair;
|
||||
if (gesture->getKeepAspectRatio() == true) {
|
||||
distance = calculatePPlusDistance(pointsKeep, gesture->getEnginePoints(), dataPair);
|
||||
} else {
|
||||
distance = calculatePPlusDistance(points, gesture->getEnginePoints(), dataPair);
|
||||
}
|
||||
distance = calculatePPlusDistance(points, gesture->getEnginePoints(), dataPair, inputAspectRatio, gesture->getAspectRatio());
|
||||
//distance = calculatePPlusDistanceSimple(points, gesture->getEnginePoints(), dataPair);
|
||||
if (nbStrokeRef != nbStrokeSample) {
|
||||
distance += 0.1f*float(std::abs(nbStrokeRef-nbStrokeSample));
|
||||
|
@ -51,7 +51,9 @@ namespace dollar {
|
||||
protected:
|
||||
float calculatePPlusDistance(const std::vector<vec2>& _points,
|
||||
const std::vector<vec2>& _reference,
|
||||
std::vector<std::pair<int32_t, int32_t>>& _dataDebug);
|
||||
std::vector<std::pair<int32_t, int32_t>>& _dataDebug,
|
||||
float _inputAspectRatio,
|
||||
float _referenceAspectRatio);
|
||||
float calculatePPlusDistanceSimple(const std::vector<vec2>& _points,
|
||||
const std::vector<vec2>& _reference,
|
||||
std::vector<std::pair<int32_t, int32_t>>& _dataDebug);
|
||||
|
@ -65,7 +65,7 @@ std::vector<std::vector<vec2>> dollar::loadPoints(const std::string& _fileName,
|
||||
dollar::Gesture::Gesture():
|
||||
m_name(""),
|
||||
m_subId(0),
|
||||
m_keepAspectRatio(false),
|
||||
m_aspectRatio(0.0f),
|
||||
m_path(){
|
||||
|
||||
}
|
||||
@ -90,7 +90,7 @@ bool dollar::Gesture::loadJSON(const std::string& _fileName) {
|
||||
}
|
||||
m_name = doc["value"].toString().get();
|
||||
m_subId = doc["sub-id"].toNumber().getU64(),
|
||||
m_keepAspectRatio = doc["keep-aspect-ratio"].toBoolean().get(),
|
||||
m_aspectRatio = doc["aspect-ratio"].toNumber().get(),
|
||||
m_path = loadPointsJson(doc);
|
||||
DOLLAR_DEBUG("Load gesture : " << m_name << " id=" << m_subId << " nb_elem=" << m_path.size());
|
||||
return true;
|
||||
@ -135,7 +135,7 @@ void dollar::Gesture::storeJSON(const std::string& _fileName) {
|
||||
doc.add("type", ejson::String("REFERENCE"));
|
||||
doc.add("value", ejson::String(m_name));
|
||||
doc.add("sub-id", ejson::Number(m_subId));
|
||||
doc.add("keep-aspect-ratio", ejson::Boolean(m_keepAspectRatio));
|
||||
doc.add("aspect-ratio", ejson::Number(m_aspectRatio));
|
||||
ejson::Array data;
|
||||
doc.add("data", data);
|
||||
for (auto &it : m_path) {
|
||||
|
@ -15,16 +15,16 @@ namespace dollar {
|
||||
protected:
|
||||
std::string m_name;
|
||||
uint32_t m_subId;
|
||||
bool m_keepAspectRatio;
|
||||
float m_aspectRatio;
|
||||
std::vector<std::vector<vec2>> m_path;
|
||||
public:
|
||||
Gesture();
|
||||
virtual ~Gesture() = default;
|
||||
void setKeepAspectRatio(bool _value) {
|
||||
m_keepAspectRatio = _value;
|
||||
void setAspectRatio(float _value) {
|
||||
m_aspectRatio = _value;
|
||||
}
|
||||
bool getKeepAspectRatio() {
|
||||
return m_keepAspectRatio;
|
||||
float getKeepAspectRatio() {
|
||||
return m_aspectRatio;
|
||||
}
|
||||
bool load(const std::string& _filename);
|
||||
bool store(const std::string& _filename);
|
||||
@ -42,5 +42,9 @@ namespace dollar {
|
||||
return m_subId;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Load all point from a specific file
|
||||
*
|
||||
*/
|
||||
std::vector<std::vector<vec2>> loadPoints(const std::string& _fileName, std::string* _label=nullptr, std::string* _type=nullptr);
|
||||
}
|
||||
|
@ -20,5 +20,6 @@ void dollar::GesturePPlus::configure(float _distance, bool _keepAspectRatio) {
|
||||
m_enginePoints.clear();
|
||||
// Generates dots:
|
||||
m_enginePoints = dollar::normalizePathToPoints(m_path, _distance, _keepAspectRatio);
|
||||
m_aspectRatio = dollar::getAspectRatio(m_path);
|
||||
DOLLAR_VERBOSE("create " << m_enginePoints.size() << " points");
|
||||
}
|
@ -16,6 +16,7 @@ namespace dollar {
|
||||
GesturePPlus();
|
||||
protected:
|
||||
std::vector<vec2> m_enginePoints;
|
||||
float m_aspectRatio; // original aspect ratio
|
||||
public:
|
||||
// Configure the reference gesture for recognition...
|
||||
void configure(float _distance, bool _keepAspectRatio);
|
||||
@ -28,5 +29,8 @@ namespace dollar {
|
||||
std::vector<std::vector<vec2>>& getPath() {
|
||||
return m_path;
|
||||
}
|
||||
const float& getAspectRatio() const {
|
||||
return m_aspectRatio;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -241,6 +241,14 @@ std::vector<vec2> dollar::normalizePath(std::vector<vec2> _points, size_t _nbSam
|
||||
return translateBariCenterToZero(_points);
|
||||
}
|
||||
|
||||
float dollar::getAspectRatio(std::vector<std::vector<vec2>> _points) {
|
||||
dollar::Rectangle box(_points);
|
||||
if (box.getSize().x() < box.getSize().y()) {
|
||||
return 1.0f - box.getSize().x() / box.getSize().y();
|
||||
} else {
|
||||
return -(1.0f - box.getSize().y() / box.getSize().x());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<vec2> dollar::normalizePathToPoints(std::vector<std::vector<vec2>> _points, float _distance, bool _keepAspectRatio) {
|
||||
// Scale point to (0.0,0.0) position and (1.0,1.0) size
|
||||
|
@ -112,6 +112,12 @@ namespace dollar {
|
||||
* @return new list of points
|
||||
*/
|
||||
std::vector<vec2> normalizePathToPoints(std::vector<std::vector<vec2>> _points, float _distance, bool _keepAspectRatio);
|
||||
/**
|
||||
* @brief get the aspect ratio of a list of points
|
||||
* @param[in] _points List of points
|
||||
* @return the aspect ratio
|
||||
*/
|
||||
float getAspectRatio(std::vector<std::vector<vec2>> _points);
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,19 +21,21 @@ static float distanceExclude = 0.2f; // distance of the exclusion point [0.1
|
||||
static float distanceGroupLimiting = 1.0f; // square distance of the grouping genereation
|
||||
static float penalityRef = 0.1;
|
||||
static float penalitySample = 0.1;
|
||||
static float penalityAspectRatio = 0.2; //!< ==> result += delta aspect ratio * penality
|
||||
|
||||
void usage(const std::string& _progName) {
|
||||
TEST_PRINT("usage:");
|
||||
TEST_PRINT(" " << _progName << " [option] corpus_path");
|
||||
TEST_PRINT(" ");
|
||||
TEST_PRINT(" [option]");
|
||||
TEST_PRINT(" -h --help Display this help");
|
||||
TEST_PRINT(" --keep_ratio Keep aspect ratio for the form recognition (default:" + etk::to_string(keepAspectRatio) + ")");
|
||||
TEST_PRINT(" --dist-check=flaot distance between points in the system recognition (default:" + etk::to_string(distanceReference) + ")");
|
||||
TEST_PRINT(" --dist-excl=flaot distance to exclude a point in a pathern matching ... (default:" + etk::to_string(distanceExclude) + ")");
|
||||
TEST_PRINT(" --group-size=flaot size of the distance between point to stop grouping in one form (default:" + etk::to_string(distanceGroupLimiting) + ")");
|
||||
TEST_PRINT(" --penal-ref=float Penality for reference when not connected (default:" + etk::to_string(penalityRef) + ")");
|
||||
TEST_PRINT(" --penal-sample=float Penality for sample when not connected (default:" + etk::to_string(penalitySample) + ")");
|
||||
TEST_PRINT(" -h --help Display this help");
|
||||
TEST_PRINT(" --keep_ratio Keep aspect ratio for the form recognition (default:" + etk::to_string(keepAspectRatio) + ")");
|
||||
TEST_PRINT(" --dist-check=flaot Distance between points in the system recognition (default:" + etk::to_string(distanceReference) + ")");
|
||||
TEST_PRINT(" --dist-excl=flaot Distance to exclude a point in a pathern matching ... (default:" + etk::to_string(distanceExclude) + ")");
|
||||
TEST_PRINT(" --group-size=flaot Size of the distance between point to stop grouping in one form (default:" + etk::to_string(distanceGroupLimiting) + ")");
|
||||
TEST_PRINT(" --penal-ref=float Penality for reference when not connected (default:" + etk::to_string(penalityRef) + ")");
|
||||
TEST_PRINT(" --penal-sample=float Penality for sample when not connected (default:" + etk::to_string(penalitySample) + ")");
|
||||
TEST_PRINT(" --penal-aspect-ratio=float Penality for the distance of aspect ratio (default:" + etk::to_string(penalityAspectRatio) + ")");
|
||||
TEST_PRINT(" ");
|
||||
TEST_PRINT(" parameters (must be here)");
|
||||
TEST_PRINT(" corpus_path Path of the corpus files");
|
||||
@ -91,6 +93,12 @@ int main(int _argc, const char *_argv[]) {
|
||||
TEST_PRINT("configure penalitySample=" << penalitySample);
|
||||
continue;
|
||||
}
|
||||
if (etk::start_with(arg,"--penal-aspect-ratio=") == true) {
|
||||
std::string val(&arg[20]);
|
||||
penalityAspectRatio = etk::string_to_float(val);
|
||||
TEST_PRINT("configure penalityAspectRatio=" << penalityAspectRatio);
|
||||
continue;
|
||||
}
|
||||
if ( arg[0] == '-'
|
||||
&& arg[1] == '-') {
|
||||
// subLibrary usage ...
|
||||
@ -118,6 +126,9 @@ void generateFile(const std::string& _fileName, const std::vector<std::string>&
|
||||
for (auto &itFile : _list) {
|
||||
std::vector<std::vector<vec2>> strokes = dollar::scaleToOne(dollar::loadPoints(itFile), keepAspectRatio);
|
||||
for (auto &itLines : strokes) {
|
||||
if (itLines.size() == 1) {
|
||||
// TODO: This is a line ....
|
||||
}
|
||||
data += " <polyline fill=\"none\" stroke=\"black\" stroke-opacity=\"0.5\" stroke-width=\"1\"\n";
|
||||
data += " points=\"";
|
||||
bool first = true;
|
||||
@ -135,6 +146,9 @@ void generateFile(const std::string& _fileName, const std::vector<std::string>&
|
||||
if (_refName != "") {
|
||||
std::vector<std::vector<vec2>> strokes = dollar::scaleToOne(dollar::loadPoints(_refName), keepAspectRatio);
|
||||
for (auto &itLines : strokes) {
|
||||
if (itLines.size() == 1) {
|
||||
// TODO: This is a line ....
|
||||
}
|
||||
data += " <polyline fill=\"none\" stroke=\"red\" stroke-opacity=\"1.0\" stroke-width=\"2\"\n";
|
||||
data += " points=\"";
|
||||
bool first = true;
|
||||
@ -207,6 +221,11 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
}
|
||||
}
|
||||
TEST_PRINT("correlation of " << fileFiltered.size() << " files");
|
||||
std::vector<std::vector<float>> results;
|
||||
results.resize(fileFiltered.size());
|
||||
for (auto &it : results) {
|
||||
it.resize(fileFiltered.size(), OUT_OF_RANGE);
|
||||
}
|
||||
// Generate Full Files:
|
||||
std::string itTypeOfCorpusFileName = itTypeOfCorpus;
|
||||
if (itTypeOfCorpusFileName == "/") {
|
||||
@ -223,21 +242,12 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
}
|
||||
generateFile("out_dollar/generate-form/pre_generate/" + itTypeOfCorpusFileName + "_FULL.svg", listPath, "");
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test without keep Aspect ratio NO:
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Set empty results:
|
||||
std::vector<std::vector<float>> results;
|
||||
results.resize(fileFiltered.size());
|
||||
for (auto &it : results) {
|
||||
it.resize(fileFiltered.size(), OUT_OF_RANGE);
|
||||
}
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
ememory::SharedPtr<dollar::GesturePPlus> gest = ememory::makeShared<dollar::GesturePPlus>();
|
||||
std::vector<std::vector<vec2>> listPoints = dollar::loadPoints(fileFiltered[iii]);
|
||||
gest->set(itTypeOfCorpus, 0, listPoints);
|
||||
dollar::EnginePPlus reco;
|
||||
reco.setScaleKeepRatio(false);//keepAspectRatio);
|
||||
reco.setScaleKeepRatio(keepAspectRatio);
|
||||
reco.setPPlusDistance(distanceReference);
|
||||
reco.setPPlusExcludeDistance(distanceExclude);
|
||||
reco.setPenalityNotLinkRef(penalityRef);
|
||||
@ -260,45 +270,6 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
TEST_DEBUG(" " << res.getConfidence() << " " << filename2);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test with keep Aspect ratio YES:
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::vector<std::vector<float>> resultsKeepAspectRatio;
|
||||
resultsKeepAspectRatio.resize(fileFiltered.size());
|
||||
for (auto &it : resultsKeepAspectRatio) {
|
||||
it.resize(fileFiltered.size(), OUT_OF_RANGE);
|
||||
}
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
ememory::SharedPtr<dollar::GesturePPlus> gest = ememory::makeShared<dollar::GesturePPlus>();
|
||||
std::vector<std::vector<vec2>> listPoints = dollar::loadPoints(fileFiltered[iii]);
|
||||
gest->set(itTypeOfCorpus, 0, listPoints);
|
||||
dollar::EnginePPlus reco;
|
||||
reco.setScaleKeepRatio(true);//keepAspectRatio);
|
||||
reco.setPPlusDistance(distanceReference);
|
||||
reco.setPPlusExcludeDistance(distanceExclude);
|
||||
reco.setPenalityNotLinkRef(penalityRef);
|
||||
reco.setPenalityNotLinkSample(penalitySample);
|
||||
reco.addGesture(gest);
|
||||
std::vector<std::string> path = etk::split(fileFiltered[iii], '/');
|
||||
std::string filename = path[path.size()-1];
|
||||
TEST_DEBUG("Test : " << fileFiltered[iii]);
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (iii >= jjj) {
|
||||
// same element to compare ... result will be 0 ...
|
||||
continue;
|
||||
}
|
||||
listPoints = dollar::loadPoints(fileFiltered[jjj]);
|
||||
dollar::Results res = reco.recognize(listPoints);
|
||||
resultsKeepAspectRatio[iii][jjj] = res.getConfidence();
|
||||
resultsKeepAspectRatio[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("---------------------------------------------------------------------------");
|
||||
@ -306,205 +277,101 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
int32_t subId = 1;
|
||||
|
||||
while (residualValues > 0) {
|
||||
int32_t bestId = -1;
|
||||
int32_t bestIdKeep = -1;
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test without keep Aspect ratio NO:
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::vector<int32_t> countMinimum;
|
||||
{
|
||||
countMinimum.resize(fileFiltered.size(), 0);
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (results[iii][jjj] < distanceGroupLimiting) {
|
||||
countMinimum[iii] ++;
|
||||
}
|
||||
countMinimum.resize(fileFiltered.size(), 0);
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (results[iii][jjj] < distanceGroupLimiting) {
|
||||
countMinimum[iii] ++;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t bestCount = 0;
|
||||
for (size_t iii=0; iii<countMinimum.size(); ++iii) {
|
||||
if (countMinimum[iii] > bestCount) {
|
||||
bestCount = countMinimum[iii];
|
||||
bestId = iii;
|
||||
}
|
||||
}
|
||||
if (bestId != -1) {
|
||||
TEST_INFO("find NB element : " << countMinimum[bestId] << " for ID=" << bestId);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test with keep Aspect ratio YES:
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::vector<int32_t> countMinimumKeep;
|
||||
{
|
||||
countMinimumKeep.resize(fileFiltered.size(), 0);
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (resultsKeepAspectRatio[iii][jjj] < distanceGroupLimiting) {
|
||||
countMinimumKeep[iii] ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
int32_t bestCount = 0;
|
||||
for (size_t iii=0; iii<countMinimumKeep.size(); ++iii) {
|
||||
if (countMinimumKeep[iii] > bestCount) {
|
||||
bestCount = countMinimumKeep[iii];
|
||||
bestIdKeep = iii;
|
||||
}
|
||||
}
|
||||
if (bestIdKeep != -1) {
|
||||
TEST_INFO("find NB element : " << countMinimumKeep[bestId] << " for ID=" << bestId << " KEEP" );
|
||||
|
||||
int32_t bestCount = 0;
|
||||
int32_t bestId = -1;
|
||||
for (size_t iii=0; iii<countMinimum.size(); ++iii) {
|
||||
if (countMinimum[iii] > bestCount) {
|
||||
bestCount = countMinimum[iii];
|
||||
bestId = iii;
|
||||
}
|
||||
}
|
||||
// Exit main loop if needed:
|
||||
if ( bestId == -1
|
||||
&& bestIdKeep == -1) {
|
||||
if (bestId == -1) {
|
||||
TEST_ERROR("No more elements ... residualValues=" << residualValues);
|
||||
|
||||
// TODO : Add the rest of the elements ...
|
||||
|
||||
|
||||
//==> 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<int32_t> linkIds;
|
||||
if (countMinimum[bestId] >= countMinimumKeep[bestIdKeep]) {
|
||||
TEST_WARNING(" ==> select No aspect ratio");
|
||||
} else {
|
||||
TEST_WARNING(" ==> select KEEP aspect ratio");
|
||||
}
|
||||
if (countMinimum[bestId] >= countMinimumKeep[bestIdKeep]) {
|
||||
// Order the result for the bestID ==> permit to show if it is possible to do a better case ...
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (results[bestId][jjj] < distanceGroupLimiting) {
|
||||
linkIds.push_back(jjj);
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbEle(tmp) " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
{
|
||||
std::vector<std::pair<float, size_t>> ordered;
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
float val = results[bestId][jjj];
|
||||
if (val >= 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 ...
|
||||
// TODO : Check if it is possible ...
|
||||
if (false) {
|
||||
float lastValue = 0.0;
|
||||
linkIds.clear();
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
if (ordered[jjj].first < distanceGroupLimiting) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
// auto find a separation in the group ...
|
||||
if (ordered[jjj].first <= (lastValue + 0.15)) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastValue = ordered[jjj].first;
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
TEST_INFO(" values : " << linkIds);
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
std::vector<std::string> path = etk::split(fileFiltered[ordered[jjj].second], '/');
|
||||
std::string filename = path[path.size()-1];
|
||||
std::string tmppp = " ";
|
||||
if (jjj<linkIds.size()) {
|
||||
tmppp = "*";
|
||||
}
|
||||
TEST_INFO(" " << tmppp << " values : " << ordered[jjj].first << " " << ordered[jjj].second << " " << filename);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Order the result for the bestIdKeep ==> permit to show if it is possible to do a better case ...
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (resultsKeepAspectRatio[bestIdKeep][jjj] < distanceGroupLimiting) {
|
||||
linkIds.push_back(jjj);
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbEle(tmp) " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
{
|
||||
std::vector<std::pair<float, size_t>> ordered;
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
float val = resultsKeepAspectRatio[bestIdKeep][jjj];
|
||||
if (val >= 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 ...
|
||||
// TODO : Check if it is possible ...
|
||||
if (false) {
|
||||
float lastValue = 0.0;
|
||||
linkIds.clear();
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
if (ordered[jjj].first < distanceGroupLimiting) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
// auto find a separation in the group ...
|
||||
if (ordered[jjj].first <= (lastValue + 0.15)) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastValue = ordered[jjj].first;
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
TEST_INFO(" values : " << linkIds);
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
std::vector<std::string> path = etk::split(fileFiltered[ordered[jjj].second], '/');
|
||||
std::string filename = path[path.size()-1];
|
||||
std::string tmppp = " ";
|
||||
if (jjj<linkIds.size()) {
|
||||
tmppp = "*";
|
||||
}
|
||||
TEST_INFO(" " << tmppp << " values : " << ordered[jjj].first << " " << ordered[jjj].second << " " << filename);
|
||||
}
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (results[bestId][jjj] < distanceGroupLimiting) {
|
||||
linkIds.push_back(jjj);
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbEle(tmp) " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
{
|
||||
std::vector<std::pair<float, size_t>> ordered;
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
float val = results[bestId][jjj];
|
||||
if (val >= 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 ...
|
||||
// TODO : Check if it is possible ...
|
||||
if (false) {
|
||||
float lastValue = 0.0;
|
||||
linkIds.clear();
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
if (ordered[jjj].first < distanceGroupLimiting) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
// auto find a separation in the group ...
|
||||
if (ordered[jjj].first <= (lastValue + 0.15)) {
|
||||
linkIds.push_back(ordered[jjj].second);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastValue = ordered[jjj].first;
|
||||
}
|
||||
}
|
||||
TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
TEST_INFO(" values : " << linkIds);
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
std::vector<std::string> path = etk::split(fileFiltered[ordered[jjj].second], '/');
|
||||
std::string filename = path[path.size()-1];
|
||||
std::string tmppp = " ";
|
||||
if (jjj<linkIds.size()) {
|
||||
tmppp = "*";
|
||||
}
|
||||
TEST_INFO(" " << tmppp << " values : " << ordered[jjj].first << " " << ordered[jjj].second << " " << filename);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean Best ID line
|
||||
bool removeId = bestIdKeep;
|
||||
if (countMinimum[bestId] >= countMinimumKeep[bestIdKeep]) {
|
||||
removeId = bestId;
|
||||
}
|
||||
for (size_t jjj=0; jjj<results.size(); ++jjj) {
|
||||
results[removeId][jjj] = OUT_OF_RANGE;
|
||||
results[jjj][removeId] = OUT_OF_RANGE;
|
||||
}
|
||||
for (size_t jjj=0; jjj<resultsKeepAspectRatio.size(); ++jjj) {
|
||||
resultsKeepAspectRatio[removeId][jjj] = OUT_OF_RANGE;
|
||||
resultsKeepAspectRatio[jjj][removeId] = OUT_OF_RANGE;
|
||||
results[bestId][jjj] = OUT_OF_RANGE;
|
||||
results[jjj][bestId] = OUT_OF_RANGE;
|
||||
}
|
||||
// clean used line by the Best ID...
|
||||
for (size_t iii=0; iii<linkIds.size(); ++iii) {
|
||||
@ -513,12 +380,6 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
results[jjj][linkIds[iii]] = OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
for (size_t iii=0; iii<linkIds.size(); ++iii) {
|
||||
for (size_t jjj=0; jjj<resultsKeepAspectRatio.size(); ++jjj) {
|
||||
resultsKeepAspectRatio[linkIds[iii]][jjj] = OUT_OF_RANGE;
|
||||
resultsKeepAspectRatio[jjj][linkIds[iii]] = OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
if (linkIds.size() <= 3) {
|
||||
TEST_ERROR("Group is too small ... residualValues=" << residualValues);
|
||||
// TODO : Add the rest of the elements ...
|
||||
@ -537,11 +398,6 @@ bool testCorpus(const std::string& _srcCorpus) {
|
||||
TEST_DEBUG("Generate output file (corpus ...)");
|
||||
// declare a Gesture (internal API)
|
||||
dollar::Gesture ref;
|
||||
if (countMinimum[bestId] >= countMinimumKeep[bestIdKeep]) {
|
||||
ref.setKeepAspectRatio(false);
|
||||
} else {
|
||||
ref.setKeepAspectRatio(true);
|
||||
}
|
||||
ref.set(itTypeOfCorpus, subId, dollar::loadPoints(fileFiltered[bestId]));
|
||||
// Store gesture with his extention type:
|
||||
ref.store("out_dollar/generate-form/corpus/" + itTypeOfCorpusFileName + "_" + etk::to_string(subId) + ".json");
|
||||
|
Loading…
x
Reference in New Issue
Block a user