Compare commits
2 Commits
ecc7bf08f3
...
63ecc46b10
Author | SHA1 | Date | |
---|---|---|---|
63ecc46b10 | |||
1a522e2813 |
@ -8,10 +8,10 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/Rectangle.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <dollar/EngineN.hpp>
|
||||
#include <dollar/EngineP.hpp>
|
||||
#include <dollar/EnginePPlus.hpp>
|
||||
#include <etk/path/fileSystem.hpp>
|
||||
|
||||
|
||||
dollar::Engine::Engine():
|
||||
@ -28,12 +28,14 @@ size_t dollar::Engine::getNumberResult() {
|
||||
}
|
||||
|
||||
|
||||
bool dollar::Engine::loadPath(const etk::String& _path) {
|
||||
DOLLAR_INFO("Load Path: " << _path);
|
||||
etk::FSNode path(_path);
|
||||
etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
|
||||
bool dollar::Engine::loadPath(const etk::Uri& _uri) {
|
||||
DOLLAR_INFO("Load Path: " << _uri);
|
||||
etk::Vector<etk::Uri> files = etk::uri::list(_uri);
|
||||
for (auto &it : files) {
|
||||
if (etk::end_with(it, ".json") == true) {
|
||||
if (etk::uri::isFile(it) == false) {
|
||||
continue;
|
||||
}
|
||||
if (it.getPath().getExtention().toLower() == "json") {
|
||||
loadGesture(it);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ namespace dollar {
|
||||
protected:
|
||||
virtual dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) = 0;
|
||||
public:
|
||||
virtual bool loadPath(const etk::String& _path);
|
||||
virtual bool loadGesture(const etk::String& _filename) = 0;
|
||||
virtual bool loadPath(const etk::Uri& _uri);
|
||||
virtual bool loadGesture(const etk::Uri& _uri) = 0;
|
||||
virtual void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) = 0;
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/Rectangle.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
@ -138,10 +137,10 @@ void dollar::EngineN::setRotationInvariance(bool _ignoreRotation) {
|
||||
}
|
||||
}
|
||||
|
||||
bool dollar::EngineN::loadGesture(const etk::String& _filename) {
|
||||
bool dollar::EngineN::loadGesture(const etk::Uri& _uri) {
|
||||
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureN>();
|
||||
DOLLAR_DEBUG("Load Gesture: " << _filename);
|
||||
if (ref->load(_filename) == true) {
|
||||
DOLLAR_DEBUG("Load Gesture: " << _uri);
|
||||
if (ref->load(_uri) == true) {
|
||||
addGesture(ref);
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace dollar {
|
||||
public:
|
||||
EngineN(bool _protractor);
|
||||
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _points) override;
|
||||
bool loadGesture(const etk::String& _filename) override;
|
||||
bool loadGesture(const etk::Uri& _uri) override;
|
||||
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
|
||||
protected:
|
||||
float distanceAtBestAngle(const etk::Vector<vec2>& _points, const etk::Vector<vec2>& _reference);
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/Rectangle.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#define MAX_FLOAT std::numeric_limits<float>::max()
|
||||
@ -101,10 +100,10 @@ static float calculateBestDistance(const etk::Vector<vec2>& _points, const etk::
|
||||
}
|
||||
|
||||
|
||||
bool dollar::EngineP::loadGesture(const etk::String& _filename) {
|
||||
bool dollar::EngineP::loadGesture(const etk::Uri& _uri) {
|
||||
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureP>();
|
||||
DOLLAR_DEBUG("Load Gesture: " << _filename);
|
||||
if (ref->load(_filename) == true) {
|
||||
DOLLAR_DEBUG("Load Gesture: " << _uri);
|
||||
if (ref->load(_uri) == true) {
|
||||
addGesture(ref);
|
||||
return true;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace dollar {
|
||||
public:
|
||||
EngineP();
|
||||
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override;
|
||||
bool loadGesture(const etk::String& _filename) override;
|
||||
bool loadGesture(const etk::Uri& _uri) override;
|
||||
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
|
||||
};
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/Rectangle.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
@ -233,10 +232,10 @@ float dollar::EnginePPlus::calculatePPlusDistance(const etk::Vector<vec2>& _poin
|
||||
|
||||
|
||||
|
||||
bool dollar::EnginePPlus::loadGesture(const etk::String& _filename) {
|
||||
bool dollar::EnginePPlus::loadGesture(const etk::Uri& _uri) {
|
||||
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GesturePPlus>();
|
||||
DOLLAR_DEBUG("Load Gesture: " << _filename);
|
||||
if (ref->load(_filename) == true) {
|
||||
DOLLAR_DEBUG("Load Gesture: " << _uri);
|
||||
if (ref->load(_uri) == true) {
|
||||
addGesture(ref);
|
||||
return true;
|
||||
}
|
||||
@ -251,7 +250,7 @@ void dollar::EnginePPlus::addGesture(ememory::SharedPtr<dollar::Gesture> _gestur
|
||||
}
|
||||
}
|
||||
|
||||
static void storeSVG(const etk::String& _fileName,
|
||||
static void storeSVG(const etk::Uri& _fileName,
|
||||
const ememory::SharedPtr<dollar::GesturePPlus>& _gesture,
|
||||
const etk::Vector<etk::Vector<vec2>>& _strokes,
|
||||
const etk::Vector<vec2>& _points,
|
||||
@ -305,7 +304,14 @@ static void storeSVG(const etk::String& _fileName,
|
||||
data += " />\n";
|
||||
}
|
||||
data += "</svg>\n";
|
||||
etk::FSNodeWriteAllData(_fileName, data);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_fileName);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == false) {
|
||||
return;
|
||||
}
|
||||
fileIO->writeAll(data);
|
||||
fileIO->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace dollar {
|
||||
public:
|
||||
EnginePPlus();
|
||||
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override;
|
||||
bool loadGesture(const etk::String& _filename) override;
|
||||
bool loadGesture(const etk::Uri& _uri) override;
|
||||
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
|
||||
protected:
|
||||
float calculatePPlusDistance(const etk::Vector<vec2>& _points,
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/Gesture.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <esvg/esvg.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
@ -35,7 +35,7 @@ static etk::Vector<etk::Vector<vec2>> loadPointsJson(const ejson::Document& _doc
|
||||
return out;
|
||||
}
|
||||
|
||||
etk::Vector<etk::Vector<vec2>> dollar::loadPoints(const etk::String& _fileName, etk::String* _label, etk::String* _type) {
|
||||
etk::Vector<etk::Vector<vec2>> dollar::loadPoints(const etk::Uri& _fileName, etk::String* _label, etk::String* _type) {
|
||||
ejson::Document doc;
|
||||
doc.load(_fileName);
|
||||
if (_label != null) {
|
||||
@ -70,11 +70,11 @@ dollar::Gesture::Gesture():
|
||||
|
||||
}
|
||||
|
||||
bool dollar::Gesture::load(const etk::String& _fileName) {
|
||||
etk::String tmpName = etk::toLower(_fileName);
|
||||
if (etk::end_with(tmpName, ".json") == true) {
|
||||
bool dollar::Gesture::load(const etk::Uri& _fileName) {
|
||||
etk::String extention = etk::toLower(_fileName.getPath().getExtention());
|
||||
if (extention == "json") {
|
||||
return loadJSON(_fileName);
|
||||
} else if (etk::end_with(tmpName, ".svg") == true) {
|
||||
} else if (extention == "svg") {
|
||||
return loadSVG(_fileName);
|
||||
}
|
||||
DOLLAR_ERROR("Un-sopported LOAD extention : " << _fileName);
|
||||
@ -82,7 +82,7 @@ bool dollar::Gesture::load(const etk::String& _fileName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool dollar::Gesture::loadJSON(const etk::String& _fileName) {
|
||||
bool dollar::Gesture::loadJSON(const etk::Uri& _fileName) {
|
||||
ejson::Document doc;
|
||||
doc.load(_fileName);
|
||||
if (doc["type"].toString().get() != "REFERENCE") {
|
||||
@ -96,12 +96,10 @@ bool dollar::Gesture::loadJSON(const etk::String& _fileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dollar::Gesture::loadSVG(const etk::String& _fileName) {
|
||||
bool dollar::Gesture::loadSVG(const etk::Uri& _fileName) {
|
||||
esvg::Document doc;
|
||||
doc.load(_fileName);
|
||||
etk::Vector<etk::String> plop = etk::split(_fileName, '.');
|
||||
plop = etk::split(plop[plop.size() -2], '/');
|
||||
plop = etk::split(plop[plop.size() -1], '_');
|
||||
etk::Vector<etk::String> plop = etk::split(_fileName.getPath().getFileName(), '_');
|
||||
m_name = plop[0];
|
||||
m_subId = etk::string_to_int32_t(plop[1]);
|
||||
m_path = doc.getLines();
|
||||
@ -116,12 +114,12 @@ bool dollar::Gesture::loadSVG(const etk::String& _fileName) {
|
||||
}
|
||||
|
||||
|
||||
bool dollar::Gesture::store(const etk::String& _fileName) {
|
||||
etk::String tmpName = etk::toLower(_fileName);
|
||||
if (etk::end_with(tmpName, ".json") == true) {
|
||||
bool dollar::Gesture::store(const etk::Uri& _fileName) {
|
||||
etk::String extention = etk::toLower(_fileName.getPath().getExtention());
|
||||
if (extention == "json") {
|
||||
storeJSON(_fileName);
|
||||
return true;
|
||||
} else if (etk::end_with(tmpName, ".svg") == true) {
|
||||
} else if (extention == "svg") {
|
||||
storeSVG(_fileName);
|
||||
return true;
|
||||
}
|
||||
@ -130,7 +128,7 @@ bool dollar::Gesture::store(const etk::String& _fileName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void dollar::Gesture::storeJSON(const etk::String& _fileName) {
|
||||
void dollar::Gesture::storeJSON(const etk::Uri& _fileName) {
|
||||
ejson::Document doc;
|
||||
doc.add("type", ejson::String("REFERENCE"));
|
||||
doc.add("value", ejson::String(m_name));
|
||||
@ -151,7 +149,7 @@ void dollar::Gesture::storeJSON(const etk::String& _fileName) {
|
||||
doc.store(_fileName);
|
||||
}
|
||||
|
||||
void dollar::Gesture::storeSVG(const etk::String& _fileName, bool _storeDot) {
|
||||
void dollar::Gesture::storeSVG(const etk::Uri& _fileName, bool _storeDot) {
|
||||
etk::Vector<etk::Vector<vec2>> strokes = dollar::scaleToOne(m_path, true);
|
||||
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
||||
data += "<svg height=\"100\" width=\"100\">\n";
|
||||
@ -177,7 +175,14 @@ void dollar::Gesture::storeSVG(const etk::String& _fileName, bool _storeDot) {
|
||||
*/
|
||||
}
|
||||
data += "</svg>\n";
|
||||
etk::FSNodeWriteAllData(_fileName, data);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_fileName);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == false) {
|
||||
return;
|
||||
}
|
||||
fileIO->writeAll(data);
|
||||
fileIO->close();
|
||||
}
|
||||
}
|
||||
|
||||
void dollar::Gesture::set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/String.hpp>
|
||||
|
||||
namespace dollar {
|
||||
@ -26,14 +27,14 @@ namespace dollar {
|
||||
float getKeepAspectRatio() {
|
||||
return m_aspectRatio;
|
||||
}
|
||||
bool load(const etk::String& _filename);
|
||||
bool store(const etk::String& _filename);
|
||||
bool load(const etk::Uri& _filename);
|
||||
bool store(const etk::Uri& _filename);
|
||||
void set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path);
|
||||
protected:
|
||||
bool loadJSON(const etk::String& _filename);
|
||||
bool loadSVG(const etk::String& _filename);
|
||||
void storeJSON(const etk::String& _filename);
|
||||
void storeSVG(const etk::String& _filename, bool _storeDot=false);
|
||||
bool loadJSON(const etk::Uri& _filename);
|
||||
bool loadSVG(const etk::Uri& _filename);
|
||||
void storeJSON(const etk::Uri& _filename);
|
||||
void storeSVG(const etk::Uri& _filename, bool _storeDot=false);
|
||||
public:
|
||||
const etk::String& getName() {
|
||||
return m_name;
|
||||
@ -46,5 +47,5 @@ namespace dollar {
|
||||
* @brief Load all point from a specific file
|
||||
*
|
||||
*/
|
||||
etk::Vector<etk::Vector<vec2>> loadPoints(const etk::String& _fileName, etk::String* _label=null, etk::String* _type=null);
|
||||
etk::Vector<etk::Vector<vec2>> loadPoints(const etk::Uri& _fileName, etk::String* _label=null, etk::String* _type=null);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/GestureN.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <esvg/esvg.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/GestureP.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <esvg/esvg.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <dollar/debug.hpp>
|
||||
#include <dollar/GesturePPlus.hpp>
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <esvg/esvg.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
TEST(TestAll, plop) {
|
||||
/*
|
||||
dollar::Gesture gest;
|
||||
gest.set("test", 55, dollar::loadPoints("DATA:test/P.json"));
|
||||
gest.set("test", 55, dollar::loadPoints("DATA:///test/P.json"));
|
||||
gest.configure(0.1, 64, false, 0.1f);
|
||||
*/
|
||||
}
|
||||
@ -30,8 +30,8 @@ TEST(TestAll, plop) {
|
||||
*/
|
||||
TEST(TestAll, singleStroke_normal) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
|
||||
reco->loadPath("DATA:figure");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json"));
|
||||
reco->loadPath("DATA:///figure");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/arrow.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
@ -46,8 +46,8 @@ TEST(TestAll, singleStroke_normal) {
|
||||
|
||||
TEST(TestAll, singleStroke_protractor) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
|
||||
reco->loadPath("DATA:figure");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json"));
|
||||
reco->loadPath("DATA:///figure");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/arrow.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
@ -66,8 +66,8 @@ TEST(TestAll, singleStroke_protractor) {
|
||||
*/
|
||||
TEST(TestAll, multiStroke_normal) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
|
||||
reco->loadPath("DATA:text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
|
||||
reco->loadPath("DATA:///text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
@ -82,8 +82,8 @@ TEST(TestAll, multiStroke_normal) {
|
||||
|
||||
TEST(TestAll, multiStroke_protractor) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N-protractor");
|
||||
reco->loadPath("DATA:text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
|
||||
reco->loadPath("DATA:///text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
@ -100,8 +100,8 @@ TEST(TestAll, multiStroke_protractor) {
|
||||
*/
|
||||
TEST(TestAll, multiStroke_point) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P");
|
||||
reco->loadPath("DATA:text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
|
||||
reco->loadPath("DATA:///text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
@ -118,8 +118,8 @@ TEST(TestAll, multiStroke_point) {
|
||||
*/
|
||||
TEST(TestAll, multiStroke_pointPlus) {
|
||||
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P+");
|
||||
reco->loadPath("DATA:text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
|
||||
reco->loadPath("DATA:///text");
|
||||
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json"));
|
||||
EXPECT_EQ(res.haveMatch(), true);
|
||||
if (res.haveMatch() == false) {
|
||||
TEST_INFO(" Recognise noting ...");
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include <etk/etk.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/Map.hpp>
|
||||
|
||||
static bool keepAspectRatio = false;
|
||||
@ -36,14 +35,14 @@ void usage(const etk::String& _progName) {
|
||||
TEST_PRINT(" corpus_path Path of the corpus files");
|
||||
}
|
||||
|
||||
bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus);
|
||||
bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus);
|
||||
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
// init etk log system and file interface:
|
||||
etk::init(_argc, _argv);
|
||||
etk::String srcGesture;
|
||||
etk::String srcCorpus;
|
||||
etk::Path srcGesture;
|
||||
etk::Path srcCorpus;
|
||||
for (int32_t iii=1; iii<_argc; ++iii) {
|
||||
etk::String arg = _argv[iii];
|
||||
if ( arg == "-h"
|
||||
@ -110,7 +109,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
return testCorpus(srcGesture, srcCorpus);
|
||||
}
|
||||
|
||||
void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>& _list) {
|
||||
void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list) {
|
||||
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
||||
data += "<svg height=\"100\" width=\"100\">\n";
|
||||
for (auto &itFile : _list) {
|
||||
@ -131,10 +130,17 @@ void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>&
|
||||
}
|
||||
}
|
||||
data += "</svg>\n";
|
||||
etk::FSNodeWriteAllData(_fileName, data);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_fileName);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == false) {
|
||||
return;
|
||||
}
|
||||
fileIO->writeAll(data);
|
||||
fileIO->close();
|
||||
}
|
||||
}
|
||||
|
||||
void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::String>>>& _result) {
|
||||
void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::Uri>>>& _result) {
|
||||
TEST_PRINT("Full results:");
|
||||
for (auto &it : _result) {
|
||||
int32_t nbRecognise = 0;
|
||||
@ -144,8 +150,8 @@ void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results,
|
||||
if (etk::split(it.first, ' ').size() > 1) {
|
||||
type = etk::split(it.first, ' ')[1];
|
||||
}
|
||||
etk::Vector<etk::String> listFull;
|
||||
etk::Vector<etk::String> listWrong;
|
||||
etk::Vector<etk::Uri> listFull;
|
||||
etk::Vector<etk::Uri> listWrong;
|
||||
etk::Map<etk::String, int32_t> wrongValues;
|
||||
for (auto itRes : it.second) {
|
||||
nbtested ++;
|
||||
@ -174,16 +180,16 @@ void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results,
|
||||
TEST_WARNING(" " << it.first << " " << it.second << "");
|
||||
}
|
||||
}
|
||||
generateFile("out_dollar/bench-corpus/OK/" + label + "_" + type + ".svg", listFull);
|
||||
generateFile(etk::Path("out_dollar") / "bench-corpus" / "OK" / label + "_" + type + ".svg", listFull);
|
||||
if (listWrong.size() != 0) {
|
||||
generateFile("out_dollar/bench-corpus/ERROR/" + label + "_" + type + "_ERROR.svg", listWrong);
|
||||
generateFile(etk::Path("out_dollar") / "bench-corpus" / "ERROR" / label + "_" + type + "_ERROR.svg", listWrong);
|
||||
} else {
|
||||
etk::FSNodeRemove("out_dollar/bench-corpus/ERROR/" + label + "_" + type + "_ERROR.svg");
|
||||
etk::uri::remove(etk::Path("out_dollar") / "bench-corpus" / "ERROR" / label + "_" + type + "_ERROR.svg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus) {
|
||||
bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus) {
|
||||
// declare a Gesture (internal API)
|
||||
dollar::EnginePPlus reco;
|
||||
reco.setScaleKeepRatio(keepAspectRatio);
|
||||
@ -201,14 +207,22 @@ bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus) {
|
||||
return -1;
|
||||
}
|
||||
TEST_DEBUG("List all file in the corpus path");
|
||||
etk::FSNode path(_srcCorpus);
|
||||
etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
|
||||
etk::Vector<etk::Uri> filesTmp = etk::uri::list(_srcCorpus);
|
||||
etk::Vector<etk::Uri> files;
|
||||
for (auto &it: filesTmp) {
|
||||
if (etk::uri::isFile(it) == false) {
|
||||
continue;
|
||||
}
|
||||
if (it.getPath().getExtention().toLower() == "json") {
|
||||
files.pushBack(it);
|
||||
}
|
||||
}
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
TEST_PRINT("-- test gestures: ");
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
|
||||
// "label_type" ==> list of (result, file test name)
|
||||
etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::String>>> agregateResults;
|
||||
etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::Uri>>> agregateResults;
|
||||
int32_t nbRecognise = 0;
|
||||
int32_t nbRecognise2 = 0;
|
||||
int32_t nbtested = 0;
|
||||
@ -220,8 +234,7 @@ bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus) {
|
||||
//continue; // rejest for now ...
|
||||
}
|
||||
nbtested++;
|
||||
etk::Vector<etk::String> path = etk::split(it, '/');
|
||||
etk::String filename = path[path.size()-1];
|
||||
etk::String filename = it.getPath().getFileName();
|
||||
TEST_PRINT("Test '" << label << "' type=" << type << " " << filename);
|
||||
dollar::Results res = reco.recognize(listPoints);
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <dollar/tools.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <etk/Map.hpp>
|
||||
@ -44,13 +43,13 @@ void usage(const etk::String& _progName) {
|
||||
TEST_PRINT(" example:");
|
||||
}
|
||||
|
||||
bool testCorpus(const etk::String& _srcCorpus);
|
||||
bool testCorpus(const etk::Uri& _srcCorpus);
|
||||
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
// init etk log system and file interface:
|
||||
etk::init(_argc, _argv);
|
||||
etk::String srcCorpus;
|
||||
etk::Path srcCorpus;
|
||||
|
||||
for (int32_t iii=1; iii<_argc; ++iii) {
|
||||
etk::String arg = _argv[iii];
|
||||
@ -119,7 +118,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
return testCorpus(srcCorpus);
|
||||
}
|
||||
|
||||
void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>& _list, const etk::String& _refName) {
|
||||
void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list, const etk::Uri& _refName) {
|
||||
TEST_PRINT(" " << _fileName);
|
||||
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
||||
data += "<svg height=\"100\" width=\"100\">\n";
|
||||
@ -164,24 +163,38 @@ void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>&
|
||||
}
|
||||
}
|
||||
data += "</svg>\n";
|
||||
etk::FSNodeWriteAllData(_fileName, data);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_fileName);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == false) {
|
||||
return;
|
||||
}
|
||||
fileIO->writeAll(data);
|
||||
fileIO->close();
|
||||
}
|
||||
}
|
||||
|
||||
#define OUT_OF_RANGE (999999.0f)
|
||||
|
||||
bool testCorpus(const etk::String& _srcCorpus) {
|
||||
bool testCorpus(const etk::Uri& _srcCorpus) {
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
TEST_PRINT("-- Create list of files: " << _srcCorpus);
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
etk::FSNode path(_srcCorpus);
|
||||
etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
|
||||
etk::Vector<etk::Uri> filesTmp = etk::uri::list(_srcCorpus);
|
||||
etk::Vector<etk::Uri> files;
|
||||
for (auto &it: filesTmp) {
|
||||
if (etk::uri::isFile(it) == false) {
|
||||
continue;
|
||||
}
|
||||
if (it.getPath().getExtention().toLower() == "json") {
|
||||
files.pushBack(it);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_PRINT("corpus have " << files.size() << " files");
|
||||
etk::Vector<etk::String> listOfElementInCorpus;
|
||||
for (auto &it : files) {
|
||||
if (etk::end_with(it, ".json") == true) {
|
||||
etk::Vector<etk::String> path = etk::split(it, '/');
|
||||
etk::String elemName = etk::split(path[path.size()-1],'_')[0];
|
||||
if (it.getPath().getExtention().toLower() == "json") {
|
||||
etk::String elemName = etk::split(it.getPath().getFileName(),'_')[0];
|
||||
if (elemName == "slash") {
|
||||
elemName = "/";
|
||||
}if (elemName == "back-slash") {
|
||||
@ -196,7 +209,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
}
|
||||
}
|
||||
// remove generation path ...
|
||||
etk::FSNodeRemove("out_dollar/generate-form");
|
||||
etk::uri::remove(etk::Path("out_dollar/generate-form"));
|
||||
//listOfElementInCorpus.clear();
|
||||
//listOfElementInCorpus.pushBack("slash");
|
||||
|
||||
@ -207,7 +220,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
TEST_PRINT("-- Generate FOR: '" << itTypeOfCorpus << "'");
|
||||
TEST_PRINT("---------------------------------------------------------------------------");
|
||||
etk::Vector<etk::String> fileFiltered;
|
||||
etk::Vector<etk::Uri> fileFiltered;
|
||||
etk::String fileNameIt = itTypeOfCorpus;
|
||||
if (fileNameIt == "/") {
|
||||
fileNameIt = "slash";
|
||||
@ -215,9 +228,8 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
fileNameIt = "back-slash";
|
||||
}
|
||||
for (auto &it : files) {
|
||||
if (etk::end_with(it, ".json") == true) {
|
||||
etk::Vector<etk::String> path = etk::split(it, '/');
|
||||
etk::String filename = path[path.size()-1];
|
||||
if (it.getPath().getExtention().toLower() == "json") {
|
||||
etk::String filename = it.getPath().getFileName();
|
||||
if (etk::start_with(filename, fileNameIt + "_") == true) {
|
||||
fileFiltered.pushBack(it);
|
||||
}
|
||||
@ -239,11 +251,11 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
itTypeOfCorpusFileName = "question";
|
||||
}
|
||||
{
|
||||
etk::Vector<etk::String> listPath;
|
||||
etk::Vector<etk::Uri> listPath;
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
listPath.pushBack(fileFiltered[iii]);
|
||||
}
|
||||
generateFile("out_dollar/generate-form/pre_generate/" + itTypeOfCorpusFileName + "_FULL.svg", listPath, "");
|
||||
generateFile(etk::Path("out_dollar") / "generate-form" / "pre_generate" / itTypeOfCorpusFileName + "_FULL.svg", listPath, "");
|
||||
}
|
||||
for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
|
||||
ememory::SharedPtr<dollar::GesturePPlus> gest = ememory::makeShared<dollar::GesturePPlus>();
|
||||
@ -257,8 +269,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
reco.setPenalityNotLinkSample(penalitySample);
|
||||
reco.setPenalityAspectRatio(penalityAspectRatio);
|
||||
reco.addGesture(gest);
|
||||
etk::Vector<etk::String> path = etk::split(fileFiltered[iii], '/');
|
||||
etk::String filename = path[path.size()-1];
|
||||
etk::String filename = fileFiltered[iii].getPath().getFileName();
|
||||
TEST_DEBUG("Test : " << fileFiltered[iii]);
|
||||
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
|
||||
if (iii >= jjj) {
|
||||
@ -269,8 +280,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
dollar::Results res = reco.recognize(listPoints);
|
||||
results[iii][jjj] = res.getConfidence();
|
||||
results[jjj][iii] = res.getConfidence();
|
||||
path = etk::split(fileFiltered[jjj], '/');
|
||||
etk::String filename2 = path[path.size()-1];
|
||||
etk::String filename2 = fileFiltered[jjj].getPath().getFileName();
|
||||
TEST_DEBUG(" " << res.getConfidence() << " " << filename2);
|
||||
}
|
||||
}
|
||||
@ -362,8 +372,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
|
||||
TEST_INFO(" values : " << linkIds);
|
||||
for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
|
||||
etk::Vector<etk::String> path = etk::split(fileFiltered[ordered[jjj].second], '/');
|
||||
etk::String filename = path[path.size()-1];
|
||||
etk::String filename = fileFiltered[ordered[jjj].second].getPath().getFileName();;
|
||||
etk::String tmppp = " ";
|
||||
if (jjj<linkIds.size()) {
|
||||
tmppp = "*";
|
||||
@ -394,7 +403,7 @@ bool testCorpus(const etk::String& _srcCorpus) {
|
||||
residualValues -= (linkIds.size() +1);
|
||||
TEST_DEBUG("Generate output files (SVG with all added path in one file)");
|
||||
// Generate Files:
|
||||
etk::Vector<etk::String> listPath;
|
||||
etk::Vector<etk::Uri> listPath;
|
||||
for (size_t iii=0; iii<linkIds.size(); ++iii) {
|
||||
listPath.pushBack(fileFiltered[linkIds[iii]]);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <etk/tool.hpp>
|
||||
#include <ejson/ejson.hpp>
|
||||
#include <esvg/esvg.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
|
||||
appl::widget::TextAreaRecognition::TextAreaRecognition() {
|
||||
addObjectType("appl::widget::TextAreaRecognition");
|
||||
@ -20,9 +19,9 @@ void appl::widget::TextAreaRecognition::init() {
|
||||
ewol::Widget::init();
|
||||
m_updateDone = false;
|
||||
|
||||
//m_dollarEngine.loadPath("DATA:text");
|
||||
//m_dollarEngine.loadPath("DATA:///text");
|
||||
m_dollarEngine = dollar::createEngine("$P+");
|
||||
m_dollarEngine->loadPath("DATA:reference");
|
||||
m_dollarEngine->loadPath("DATA:///reference");
|
||||
// TODO: m_dollarEngine->setScaleKeepRatio(true);
|
||||
markToRedraw();
|
||||
// connect a periodic update ...
|
||||
@ -81,14 +80,13 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons
|
||||
list.add(obj);
|
||||
}
|
||||
etk::String streamOut = doc.generateMachineString();
|
||||
etk::String fileName;
|
||||
fileName = "HOME:DOLLAR/corpus/";
|
||||
etk::Path fileName = "~/DOLLAR/corpus";
|
||||
if (_value == "/") {
|
||||
fileName += "slash";
|
||||
fileName /= "slash";
|
||||
} else if (_value == "\\") {
|
||||
fileName += "back-slash";
|
||||
fileName /= "back-slash";
|
||||
} else {
|
||||
fileName += _value;
|
||||
fileName /= _value;
|
||||
}
|
||||
fileName += "_";
|
||||
fileName += _type;
|
||||
@ -97,7 +95,14 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons
|
||||
fileName += "_";
|
||||
fileName += etk::toString(m_time.get());
|
||||
fileName += ".json";
|
||||
etk::FSNodeWriteAllData(fileName, streamOut);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(fileName);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == false) {
|
||||
return;
|
||||
}
|
||||
fileIO->writeAll(streamOut);
|
||||
fileIO->close();
|
||||
}
|
||||
APPL_WARNING("store: " << fileName);
|
||||
}
|
||||
|
||||
@ -137,7 +142,7 @@ etk::Vector<etk::Vector<vec2>> scalePoints(etk::Vector<etk::Vector<vec2>> _list,
|
||||
return _list;
|
||||
}
|
||||
|
||||
etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec2>>& _list, int32_t _objectSize, const etk::String& _filename) {
|
||||
etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec2>>& _list, int32_t _objectSize, const etk::Uri& _filename) {
|
||||
// generate SVG to render:
|
||||
esvg::Document docSvg;
|
||||
etk::String data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n");
|
||||
@ -163,7 +168,13 @@ etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec
|
||||
data += "</svg>\n";
|
||||
docSvg.parse(data);
|
||||
//docSvg.store(list[index]->getName()+ ".svg");
|
||||
etk::FSNodeWriteAllData(_filename, data);
|
||||
{
|
||||
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_filename);
|
||||
if (fileIO->open(etk::io::OpenMode::Write) == true) {
|
||||
fileIO->writeAll(data);
|
||||
fileIO->close();
|
||||
}
|
||||
}
|
||||
|
||||
// generate SVG output ...
|
||||
ivec2 renderSize = ivec2(_objectSize,_objectSize);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
import os
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user