Compare commits

..

No commits in common. "63ecc46b10dcfb9e9949bee0765abdb693cbfa3b" and "ecc7bf08f3afa797a0aa7ffa08d7d50698b0172d" have entirely different histories.

24 changed files with 127 additions and 169 deletions

View File

@ -8,10 +8,10 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/Rectangle.hpp> #include <dollar/Rectangle.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <dollar/EngineN.hpp> #include <dollar/EngineN.hpp>
#include <dollar/EngineP.hpp> #include <dollar/EngineP.hpp>
#include <dollar/EnginePPlus.hpp> #include <dollar/EnginePPlus.hpp>
#include <etk/path/fileSystem.hpp>
dollar::Engine::Engine(): dollar::Engine::Engine():
@ -28,14 +28,12 @@ size_t dollar::Engine::getNumberResult() {
} }
bool dollar::Engine::loadPath(const etk::Uri& _uri) { bool dollar::Engine::loadPath(const etk::String& _path) {
DOLLAR_INFO("Load Path: " << _uri); DOLLAR_INFO("Load Path: " << _path);
etk::Vector<etk::Uri> files = etk::uri::list(_uri); etk::FSNode path(_path);
etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
for (auto &it : files) { for (auto &it : files) {
if (etk::uri::isFile(it) == false) { if (etk::end_with(it, ".json") == true) {
continue;
}
if (it.getPath().getExtention().toLower() == "json") {
loadGesture(it); loadGesture(it);
} }
} }

View File

@ -32,8 +32,8 @@ namespace dollar {
protected: protected:
virtual dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) = 0; virtual dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) = 0;
public: public:
virtual bool loadPath(const etk::Uri& _uri); virtual bool loadPath(const etk::String& _path);
virtual bool loadGesture(const etk::Uri& _uri) = 0; virtual bool loadGesture(const etk::String& _filename) = 0;
virtual void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) = 0; virtual void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) = 0;
}; };

View File

@ -8,6 +8,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/Rectangle.hpp> #include <dollar/Rectangle.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
@ -137,10 +138,10 @@ void dollar::EngineN::setRotationInvariance(bool _ignoreRotation) {
} }
} }
bool dollar::EngineN::loadGesture(const etk::Uri& _uri) { bool dollar::EngineN::loadGesture(const etk::String& _filename) {
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureN>(); ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureN>();
DOLLAR_DEBUG("Load Gesture: " << _uri); DOLLAR_DEBUG("Load Gesture: " << _filename);
if (ref->load(_uri) == true) { if (ref->load(_filename) == true) {
addGesture(ref); addGesture(ref);
return true; return true;
} }

View File

@ -34,7 +34,7 @@ namespace dollar {
public: public:
EngineN(bool _protractor); EngineN(bool _protractor);
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _points) override; dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _points) override;
bool loadGesture(const etk::Uri& _uri) override; bool loadGesture(const etk::String& _filename) override;
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override; void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
protected: protected:
float distanceAtBestAngle(const etk::Vector<vec2>& _points, const etk::Vector<vec2>& _reference); float distanceAtBestAngle(const etk::Vector<vec2>& _points, const etk::Vector<vec2>& _reference);

View File

@ -8,6 +8,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/Rectangle.hpp> #include <dollar/Rectangle.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#define MAX_FLOAT std::numeric_limits<float>::max() #define MAX_FLOAT std::numeric_limits<float>::max()
@ -100,10 +101,10 @@ static float calculateBestDistance(const etk::Vector<vec2>& _points, const etk::
} }
bool dollar::EngineP::loadGesture(const etk::Uri& _uri) { bool dollar::EngineP::loadGesture(const etk::String& _filename) {
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureP>(); ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GestureP>();
DOLLAR_DEBUG("Load Gesture: " << _uri); DOLLAR_DEBUG("Load Gesture: " << _filename);
if (ref->load(_uri) == true) { if (ref->load(_filename) == true) {
addGesture(ref); addGesture(ref);
return true; return true;
} }

View File

@ -31,7 +31,7 @@ namespace dollar {
public: public:
EngineP(); EngineP();
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override; dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override;
bool loadGesture(const etk::Uri& _uri) override; bool loadGesture(const etk::String& _filename) override;
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override; void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
}; };
} }

View File

@ -8,6 +8,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/Rectangle.hpp> #include <dollar/Rectangle.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
@ -232,10 +233,10 @@ float dollar::EnginePPlus::calculatePPlusDistance(const etk::Vector<vec2>& _poin
bool dollar::EnginePPlus::loadGesture(const etk::Uri& _uri) { bool dollar::EnginePPlus::loadGesture(const etk::String& _filename) {
ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GesturePPlus>(); ememory::SharedPtr<dollar::Gesture> ref = ememory::makeShared<dollar::GesturePPlus>();
DOLLAR_DEBUG("Load Gesture: " << _uri); DOLLAR_DEBUG("Load Gesture: " << _filename);
if (ref->load(_uri) == true) { if (ref->load(_filename) == true) {
addGesture(ref); addGesture(ref);
return true; return true;
} }
@ -250,7 +251,7 @@ void dollar::EnginePPlus::addGesture(ememory::SharedPtr<dollar::Gesture> _gestur
} }
} }
static void storeSVG(const etk::Uri& _fileName, static void storeSVG(const etk::String& _fileName,
const ememory::SharedPtr<dollar::GesturePPlus>& _gesture, const ememory::SharedPtr<dollar::GesturePPlus>& _gesture,
const etk::Vector<etk::Vector<vec2>>& _strokes, const etk::Vector<etk::Vector<vec2>>& _strokes,
const etk::Vector<vec2>& _points, const etk::Vector<vec2>& _points,
@ -304,14 +305,7 @@ static void storeSVG(const etk::Uri& _fileName,
data += " />\n"; data += " />\n";
} }
data += "</svg>\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();
}
} }

View File

@ -52,7 +52,7 @@ namespace dollar {
public: public:
EnginePPlus(); EnginePPlus();
dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override; dollar::Results recognize2(const etk::Vector<etk::Vector<vec2>>& _paths) override;
bool loadGesture(const etk::Uri& _uri) override; bool loadGesture(const etk::String& _filename) override;
void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override; void addGesture(ememory::SharedPtr<dollar::Gesture> _gesture) override;
protected: protected:
float calculatePPlusDistance(const etk::Vector<vec2>& _points, float calculatePPlusDistance(const etk::Vector<vec2>& _points,

View File

@ -7,7 +7,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/Gesture.hpp> #include <dollar/Gesture.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/uri/uri.hpp> #include <etk/os/FSNode.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
#include <esvg/esvg.hpp> #include <esvg/esvg.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
@ -35,7 +35,7 @@ static etk::Vector<etk::Vector<vec2>> loadPointsJson(const ejson::Document& _doc
return out; return out;
} }
etk::Vector<etk::Vector<vec2>> dollar::loadPoints(const etk::Uri& _fileName, etk::String* _label, etk::String* _type) { etk::Vector<etk::Vector<vec2>> dollar::loadPoints(const etk::String& _fileName, etk::String* _label, etk::String* _type) {
ejson::Document doc; ejson::Document doc;
doc.load(_fileName); doc.load(_fileName);
if (_label != null) { if (_label != null) {
@ -70,11 +70,11 @@ dollar::Gesture::Gesture():
} }
bool dollar::Gesture::load(const etk::Uri& _fileName) { bool dollar::Gesture::load(const etk::String& _fileName) {
etk::String extention = etk::toLower(_fileName.getPath().getExtention()); etk::String tmpName = etk::toLower(_fileName);
if (extention == "json") { if (etk::end_with(tmpName, ".json") == true) {
return loadJSON(_fileName); return loadJSON(_fileName);
} else if (extention == "svg") { } else if (etk::end_with(tmpName, ".svg") == true) {
return loadSVG(_fileName); return loadSVG(_fileName);
} }
DOLLAR_ERROR("Un-sopported LOAD extention : " << _fileName); DOLLAR_ERROR("Un-sopported LOAD extention : " << _fileName);
@ -82,7 +82,7 @@ bool dollar::Gesture::load(const etk::Uri& _fileName) {
return false; return false;
} }
bool dollar::Gesture::loadJSON(const etk::Uri& _fileName) { bool dollar::Gesture::loadJSON(const etk::String& _fileName) {
ejson::Document doc; ejson::Document doc;
doc.load(_fileName); doc.load(_fileName);
if (doc["type"].toString().get() != "REFERENCE") { if (doc["type"].toString().get() != "REFERENCE") {
@ -96,10 +96,12 @@ bool dollar::Gesture::loadJSON(const etk::Uri& _fileName) {
return true; return true;
} }
bool dollar::Gesture::loadSVG(const etk::Uri& _fileName) { bool dollar::Gesture::loadSVG(const etk::String& _fileName) {
esvg::Document doc; esvg::Document doc;
doc.load(_fileName); doc.load(_fileName);
etk::Vector<etk::String> plop = etk::split(_fileName.getPath().getFileName(), '_'); etk::Vector<etk::String> plop = etk::split(_fileName, '.');
plop = etk::split(plop[plop.size() -2], '/');
plop = etk::split(plop[plop.size() -1], '_');
m_name = plop[0]; m_name = plop[0];
m_subId = etk::string_to_int32_t(plop[1]); m_subId = etk::string_to_int32_t(plop[1]);
m_path = doc.getLines(); m_path = doc.getLines();
@ -114,12 +116,12 @@ bool dollar::Gesture::loadSVG(const etk::Uri& _fileName) {
} }
bool dollar::Gesture::store(const etk::Uri& _fileName) { bool dollar::Gesture::store(const etk::String& _fileName) {
etk::String extention = etk::toLower(_fileName.getPath().getExtention()); etk::String tmpName = etk::toLower(_fileName);
if (extention == "json") { if (etk::end_with(tmpName, ".json") == true) {
storeJSON(_fileName); storeJSON(_fileName);
return true; return true;
} else if (extention == "svg") { } else if (etk::end_with(tmpName, ".svg") == true) {
storeSVG(_fileName); storeSVG(_fileName);
return true; return true;
} }
@ -128,7 +130,7 @@ bool dollar::Gesture::store(const etk::Uri& _fileName) {
return false; return false;
} }
void dollar::Gesture::storeJSON(const etk::Uri& _fileName) { void dollar::Gesture::storeJSON(const etk::String& _fileName) {
ejson::Document doc; ejson::Document doc;
doc.add("type", ejson::String("REFERENCE")); doc.add("type", ejson::String("REFERENCE"));
doc.add("value", ejson::String(m_name)); doc.add("value", ejson::String(m_name));
@ -149,7 +151,7 @@ void dollar::Gesture::storeJSON(const etk::Uri& _fileName) {
doc.store(_fileName); doc.store(_fileName);
} }
void dollar::Gesture::storeSVG(const etk::Uri& _fileName, bool _storeDot) { void dollar::Gesture::storeSVG(const etk::String& _fileName, bool _storeDot) {
etk::Vector<etk::Vector<vec2>> strokes = dollar::scaleToOne(m_path, true); etk::Vector<etk::Vector<vec2>> strokes = dollar::scaleToOne(m_path, true);
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
data += "<svg height=\"100\" width=\"100\">\n"; data += "<svg height=\"100\" width=\"100\">\n";
@ -175,14 +177,7 @@ void dollar::Gesture::storeSVG(const etk::Uri& _fileName, bool _storeDot) {
*/ */
} }
data += "</svg>\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();
}
} }
void dollar::Gesture::set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path) { void dollar::Gesture::set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path) {

View File

@ -8,7 +8,6 @@
#include <etk/math/Vector2D.hpp> #include <etk/math/Vector2D.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include <etk/uri/uri.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
namespace dollar { namespace dollar {
@ -27,14 +26,14 @@ namespace dollar {
float getKeepAspectRatio() { float getKeepAspectRatio() {
return m_aspectRatio; return m_aspectRatio;
} }
bool load(const etk::Uri& _filename); bool load(const etk::String& _filename);
bool store(const etk::Uri& _filename); bool store(const etk::String& _filename);
void set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path); void set(const etk::String& _name, uint32_t _subId, etk::Vector<etk::Vector<vec2>> _path);
protected: protected:
bool loadJSON(const etk::Uri& _filename); bool loadJSON(const etk::String& _filename);
bool loadSVG(const etk::Uri& _filename); bool loadSVG(const etk::String& _filename);
void storeJSON(const etk::Uri& _filename); void storeJSON(const etk::String& _filename);
void storeSVG(const etk::Uri& _filename, bool _storeDot=false); void storeSVG(const etk::String& _filename, bool _storeDot=false);
public: public:
const etk::String& getName() { const etk::String& getName() {
return m_name; return m_name;
@ -47,5 +46,5 @@ namespace dollar {
* @brief Load all point from a specific file * @brief Load all point from a specific file
* *
*/ */
etk::Vector<etk::Vector<vec2>> loadPoints(const etk::Uri& _fileName, etk::String* _label=null, etk::String* _type=null); etk::Vector<etk::Vector<vec2>> loadPoints(const etk::String& _fileName, etk::String* _label=null, etk::String* _type=null);
} }

View File

@ -7,6 +7,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/GestureN.hpp> #include <dollar/GestureN.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
#include <esvg/esvg.hpp> #include <esvg/esvg.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>

View File

@ -7,6 +7,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/GestureP.hpp> #include <dollar/GestureP.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
#include <esvg/esvg.hpp> #include <esvg/esvg.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>

View File

@ -7,6 +7,7 @@
#include <dollar/debug.hpp> #include <dollar/debug.hpp>
#include <dollar/GesturePPlus.hpp> #include <dollar/GesturePPlus.hpp>
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/os/FSNode.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
#include <esvg/esvg.hpp> #include <esvg/esvg.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools

View File

@ -20,7 +20,7 @@ int main(int _argc, const char *_argv[]) {
TEST(TestAll, plop) { TEST(TestAll, plop) {
/* /*
dollar::Gesture gest; 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); gest.configure(0.1, 64, false, 0.1f);
*/ */
} }
@ -30,8 +30,8 @@ TEST(TestAll, plop) {
*/ */
TEST(TestAll, singleStroke_normal) { TEST(TestAll, singleStroke_normal) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
reco->loadPath("DATA:///figure"); reco->loadPath("DATA:figure");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/arrow.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");
@ -46,8 +46,8 @@ TEST(TestAll, singleStroke_normal) {
TEST(TestAll, singleStroke_protractor) { TEST(TestAll, singleStroke_protractor) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
reco->loadPath("DATA:///figure"); reco->loadPath("DATA:figure");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/arrow.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");
@ -66,8 +66,8 @@ TEST(TestAll, singleStroke_protractor) {
*/ */
TEST(TestAll, multiStroke_normal) { TEST(TestAll, multiStroke_normal) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N");
reco->loadPath("DATA:///text"); reco->loadPath("DATA:text");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");
@ -82,8 +82,8 @@ TEST(TestAll, multiStroke_normal) {
TEST(TestAll, multiStroke_protractor) { TEST(TestAll, multiStroke_protractor) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N-protractor"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$N-protractor");
reco->loadPath("DATA:///text"); reco->loadPath("DATA:text");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");
@ -100,8 +100,8 @@ TEST(TestAll, multiStroke_protractor) {
*/ */
TEST(TestAll, multiStroke_point) { TEST(TestAll, multiStroke_point) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P");
reco->loadPath("DATA:///text"); reco->loadPath("DATA:text");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");
@ -118,8 +118,8 @@ TEST(TestAll, multiStroke_point) {
*/ */
TEST(TestAll, multiStroke_pointPlus) { TEST(TestAll, multiStroke_pointPlus) {
ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P+"); ememory::SharedPtr<dollar::Engine> reco = dollar::createEngine("$P+");
reco->loadPath("DATA:///text"); reco->loadPath("DATA:text");
dollar::Results res = reco->recognize(dollar::loadPoints("DATA:///test/P.json")); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json"));
EXPECT_EQ(res.haveMatch(), true); EXPECT_EQ(res.haveMatch(), true);
if (res.haveMatch() == false) { if (res.haveMatch() == false) {
TEST_INFO(" Recognise noting ..."); TEST_INFO(" Recognise noting ...");

View File

@ -10,6 +10,7 @@
#include <etk/etk.hpp> #include <etk/etk.hpp>
#include <test-debug/debug.hpp> #include <test-debug/debug.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/Map.hpp> #include <etk/Map.hpp>
static bool keepAspectRatio = false; static bool keepAspectRatio = false;
@ -35,14 +36,14 @@ void usage(const etk::String& _progName) {
TEST_PRINT(" corpus_path Path of the corpus files"); TEST_PRINT(" corpus_path Path of the corpus files");
} }
bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus); bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus);
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
// init etk log system and file interface: // init etk log system and file interface:
etk::init(_argc, _argv); etk::init(_argc, _argv);
etk::Path srcGesture; etk::String srcGesture;
etk::Path srcCorpus; etk::String srcCorpus;
for (int32_t iii=1; iii<_argc; ++iii) { for (int32_t iii=1; iii<_argc; ++iii) {
etk::String arg = _argv[iii]; etk::String arg = _argv[iii];
if ( arg == "-h" if ( arg == "-h"
@ -109,7 +110,7 @@ int main(int _argc, const char *_argv[]) {
return testCorpus(srcGesture, srcCorpus); return testCorpus(srcGesture, srcCorpus);
} }
void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list) { void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>& _list) {
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
data += "<svg height=\"100\" width=\"100\">\n"; data += "<svg height=\"100\" width=\"100\">\n";
for (auto &itFile : _list) { for (auto &itFile : _list) {
@ -130,17 +131,10 @@ void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list)
} }
} }
data += "</svg>\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();
}
} }
void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::Uri>>>& _result) { void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::String>>>& _result) {
TEST_PRINT("Full results:"); TEST_PRINT("Full results:");
for (auto &it : _result) { for (auto &it : _result) {
int32_t nbRecognise = 0; int32_t nbRecognise = 0;
@ -150,8 +144,8 @@ void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results,
if (etk::split(it.first, ' ').size() > 1) { if (etk::split(it.first, ' ').size() > 1) {
type = etk::split(it.first, ' ')[1]; type = etk::split(it.first, ' ')[1];
} }
etk::Vector<etk::Uri> listFull; etk::Vector<etk::String> listFull;
etk::Vector<etk::Uri> listWrong; etk::Vector<etk::String> listWrong;
etk::Map<etk::String, int32_t> wrongValues; etk::Map<etk::String, int32_t> wrongValues;
for (auto itRes : it.second) { for (auto itRes : it.second) {
nbtested ++; nbtested ++;
@ -180,16 +174,16 @@ void annalyseResult(etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results,
TEST_WARNING(" " << it.first << " " << it.second << ""); TEST_WARNING(" " << it.first << " " << it.second << "");
} }
} }
generateFile(etk::Path("out_dollar") / "bench-corpus" / "OK" / label + "_" + type + ".svg", listFull); generateFile("out_dollar/bench-corpus/OK/" + label + "_" + type + ".svg", listFull);
if (listWrong.size() != 0) { if (listWrong.size() != 0) {
generateFile(etk::Path("out_dollar") / "bench-corpus" / "ERROR" / label + "_" + type + "_ERROR.svg", listWrong); generateFile("out_dollar/bench-corpus/ERROR/" + label + "_" + type + "_ERROR.svg", listWrong);
} else { } else {
etk::uri::remove(etk::Path("out_dollar") / "bench-corpus" / "ERROR" / label + "_" + type + "_ERROR.svg"); etk::FSNodeRemove("out_dollar/bench-corpus/ERROR/" + label + "_" + type + "_ERROR.svg");
} }
} }
} }
bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus) { bool testCorpus(const etk::String& _srcGesture, const etk::String& _srcCorpus) {
// declare a Gesture (internal API) // declare a Gesture (internal API)
dollar::EnginePPlus reco; dollar::EnginePPlus reco;
reco.setScaleKeepRatio(keepAspectRatio); reco.setScaleKeepRatio(keepAspectRatio);
@ -207,22 +201,14 @@ bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus) {
return -1; return -1;
} }
TEST_DEBUG("List all file in the corpus path"); TEST_DEBUG("List all file in the corpus path");
etk::Vector<etk::Uri> filesTmp = etk::uri::list(_srcCorpus); etk::FSNode path(_srcCorpus);
etk::Vector<etk::Uri> files; etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
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_PRINT("-- test gestures: "); TEST_PRINT("-- test gestures: ");
TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("---------------------------------------------------------------------------");
// "label_type" ==> list of (result, file test name) // "label_type" ==> list of (result, file test name)
etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::Uri>>> agregateResults; etk::Map<etk::String, etk::Vector<etk::Pair<dollar::Results, etk::String>>> agregateResults;
int32_t nbRecognise = 0; int32_t nbRecognise = 0;
int32_t nbRecognise2 = 0; int32_t nbRecognise2 = 0;
int32_t nbtested = 0; int32_t nbtested = 0;
@ -234,7 +220,8 @@ bool testCorpus(const etk::Uri& _srcGesture, const etk::Uri& _srcCorpus) {
//continue; // rejest for now ... //continue; // rejest for now ...
} }
nbtested++; nbtested++;
etk::String filename = it.getPath().getFileName(); etk::Vector<etk::String> path = etk::split(it, '/');
etk::String filename = path[path.size()-1];
TEST_PRINT("Test '" << label << "' type=" << type << " " << filename); TEST_PRINT("Test '" << label << "' type=" << type << " " << filename);
dollar::Results res = reco.recognize(listPoints); dollar::Results res = reco.recognize(listPoints);

View File

@ -8,6 +8,7 @@
#include <dollar/tools.hpp> #include <dollar/tools.hpp>
#include <etk/etk.hpp> #include <etk/etk.hpp>
#include <test-debug/debug.hpp> #include <test-debug/debug.hpp>
#include <etk/os/FSNode.hpp>
#include <iostream> #include <iostream>
#include <etk/Map.hpp> #include <etk/Map.hpp>
@ -43,13 +44,13 @@ void usage(const etk::String& _progName) {
TEST_PRINT(" example:"); TEST_PRINT(" example:");
} }
bool testCorpus(const etk::Uri& _srcCorpus); bool testCorpus(const etk::String& _srcCorpus);
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
// init etk log system and file interface: // init etk log system and file interface:
etk::init(_argc, _argv); etk::init(_argc, _argv);
etk::Path srcCorpus; etk::String srcCorpus;
for (int32_t iii=1; iii<_argc; ++iii) { for (int32_t iii=1; iii<_argc; ++iii) {
etk::String arg = _argv[iii]; etk::String arg = _argv[iii];
@ -118,7 +119,7 @@ int main(int _argc, const char *_argv[]) {
return testCorpus(srcCorpus); return testCorpus(srcCorpus);
} }
void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list, const etk::Uri& _refName) { void generateFile(const etk::String& _fileName, const etk::Vector<etk::String>& _list, const etk::String& _refName) {
TEST_PRINT(" " << _fileName); TEST_PRINT(" " << _fileName);
etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); etk::String data("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
data += "<svg height=\"100\" width=\"100\">\n"; data += "<svg height=\"100\" width=\"100\">\n";
@ -163,38 +164,24 @@ void generateFile(const etk::Uri& _fileName, const etk::Vector<etk::Uri>& _list,
} }
} }
data += "</svg>\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();
}
} }
#define OUT_OF_RANGE (999999.0f) #define OUT_OF_RANGE (999999.0f)
bool testCorpus(const etk::Uri& _srcCorpus) { bool testCorpus(const etk::String& _srcCorpus) {
TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("---------------------------------------------------------------------------");
TEST_PRINT("-- Create list of files: " << _srcCorpus); TEST_PRINT("-- Create list of files: " << _srcCorpus);
TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("---------------------------------------------------------------------------");
etk::Vector<etk::Uri> filesTmp = etk::uri::list(_srcCorpus); etk::FSNode path(_srcCorpus);
etk::Vector<etk::Uri> files; etk::Vector<etk::String> files = path.folderGetSub(false, true, "*.json");
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"); TEST_PRINT("corpus have " << files.size() << " files");
etk::Vector<etk::String> listOfElementInCorpus; etk::Vector<etk::String> listOfElementInCorpus;
for (auto &it : files) { for (auto &it : files) {
if (it.getPath().getExtention().toLower() == "json") { if (etk::end_with(it, ".json") == true) {
etk::String elemName = etk::split(it.getPath().getFileName(),'_')[0]; etk::Vector<etk::String> path = etk::split(it, '/');
etk::String elemName = etk::split(path[path.size()-1],'_')[0];
if (elemName == "slash") { if (elemName == "slash") {
elemName = "/"; elemName = "/";
}if (elemName == "back-slash") { }if (elemName == "back-slash") {
@ -209,7 +196,7 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
} }
} }
// remove generation path ... // remove generation path ...
etk::uri::remove(etk::Path("out_dollar/generate-form")); etk::FSNodeRemove("out_dollar/generate-form");
//listOfElementInCorpus.clear(); //listOfElementInCorpus.clear();
//listOfElementInCorpus.pushBack("slash"); //listOfElementInCorpus.pushBack("slash");
@ -220,7 +207,7 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("---------------------------------------------------------------------------");
TEST_PRINT("-- Generate FOR: '" << itTypeOfCorpus << "'"); TEST_PRINT("-- Generate FOR: '" << itTypeOfCorpus << "'");
TEST_PRINT("---------------------------------------------------------------------------"); TEST_PRINT("---------------------------------------------------------------------------");
etk::Vector<etk::Uri> fileFiltered; etk::Vector<etk::String> fileFiltered;
etk::String fileNameIt = itTypeOfCorpus; etk::String fileNameIt = itTypeOfCorpus;
if (fileNameIt == "/") { if (fileNameIt == "/") {
fileNameIt = "slash"; fileNameIt = "slash";
@ -228,8 +215,9 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
fileNameIt = "back-slash"; fileNameIt = "back-slash";
} }
for (auto &it : files) { for (auto &it : files) {
if (it.getPath().getExtention().toLower() == "json") { if (etk::end_with(it, ".json") == true) {
etk::String filename = it.getPath().getFileName(); etk::Vector<etk::String> path = etk::split(it, '/');
etk::String filename = path[path.size()-1];
if (etk::start_with(filename, fileNameIt + "_") == true) { if (etk::start_with(filename, fileNameIt + "_") == true) {
fileFiltered.pushBack(it); fileFiltered.pushBack(it);
} }
@ -251,11 +239,11 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
itTypeOfCorpusFileName = "question"; itTypeOfCorpusFileName = "question";
} }
{ {
etk::Vector<etk::Uri> listPath; etk::Vector<etk::String> listPath;
for (size_t iii=0; iii<fileFiltered.size(); ++iii) { for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
listPath.pushBack(fileFiltered[iii]); listPath.pushBack(fileFiltered[iii]);
} }
generateFile(etk::Path("out_dollar") / "generate-form" / "pre_generate" / itTypeOfCorpusFileName + "_FULL.svg", listPath, ""); generateFile("out_dollar/generate-form/pre_generate/" + itTypeOfCorpusFileName + "_FULL.svg", listPath, "");
} }
for (size_t iii=0; iii<fileFiltered.size(); ++iii) { for (size_t iii=0; iii<fileFiltered.size(); ++iii) {
ememory::SharedPtr<dollar::GesturePPlus> gest = ememory::makeShared<dollar::GesturePPlus>(); ememory::SharedPtr<dollar::GesturePPlus> gest = ememory::makeShared<dollar::GesturePPlus>();
@ -269,7 +257,8 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
reco.setPenalityNotLinkSample(penalitySample); reco.setPenalityNotLinkSample(penalitySample);
reco.setPenalityAspectRatio(penalityAspectRatio); reco.setPenalityAspectRatio(penalityAspectRatio);
reco.addGesture(gest); reco.addGesture(gest);
etk::String filename = fileFiltered[iii].getPath().getFileName(); etk::Vector<etk::String> path = etk::split(fileFiltered[iii], '/');
etk::String filename = path[path.size()-1];
TEST_DEBUG("Test : " << fileFiltered[iii]); TEST_DEBUG("Test : " << fileFiltered[iii]);
for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) { for (size_t jjj=0; jjj<fileFiltered.size(); ++jjj) {
if (iii >= jjj) { if (iii >= jjj) {
@ -280,7 +269,8 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
dollar::Results res = reco.recognize(listPoints); dollar::Results res = reco.recognize(listPoints);
results[iii][jjj] = res.getConfidence(); results[iii][jjj] = res.getConfidence();
results[jjj][iii] = res.getConfidence(); results[jjj][iii] = res.getConfidence();
etk::String filename2 = fileFiltered[jjj].getPath().getFileName(); path = etk::split(fileFiltered[jjj], '/');
etk::String filename2 = path[path.size()-1];
TEST_DEBUG(" " << res.getConfidence() << " " << filename2); TEST_DEBUG(" " << res.getConfidence() << " " << filename2);
} }
} }
@ -372,7 +362,8 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size()); TEST_INFO(" nbElement : " << linkIds.size() << " / " << residualValues << " / " << fileFiltered.size());
TEST_INFO(" values : " << linkIds); TEST_INFO(" values : " << linkIds);
for (size_t jjj=0; jjj<ordered.size(); ++jjj) { for (size_t jjj=0; jjj<ordered.size(); ++jjj) {
etk::String filename = fileFiltered[ordered[jjj].second].getPath().getFileName();; etk::Vector<etk::String> path = etk::split(fileFiltered[ordered[jjj].second], '/');
etk::String filename = path[path.size()-1];
etk::String tmppp = " "; etk::String tmppp = " ";
if (jjj<linkIds.size()) { if (jjj<linkIds.size()) {
tmppp = "*"; tmppp = "*";
@ -403,7 +394,7 @@ bool testCorpus(const etk::Uri& _srcCorpus) {
residualValues -= (linkIds.size() +1); residualValues -= (linkIds.size() +1);
TEST_DEBUG("Generate output files (SVG with all added path in one file)"); TEST_DEBUG("Generate output files (SVG with all added path in one file)");
// Generate Files: // Generate Files:
etk::Vector<etk::Uri> listPath; etk::Vector<etk::String> listPath;
for (size_t iii=0; iii<linkIds.size(); ++iii) { for (size_t iii=0; iii<linkIds.size(); ++iii) {
listPath.pushBack(fileFiltered[linkIds[iii]]); listPath.pushBack(fileFiltered[linkIds[iii]]);
} }

View File

@ -10,6 +10,7 @@
#include <etk/tool.hpp> #include <etk/tool.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
#include <esvg/esvg.hpp> #include <esvg/esvg.hpp>
#include <etk/os/FSNode.hpp>
appl::widget::TextAreaRecognition::TextAreaRecognition() { appl::widget::TextAreaRecognition::TextAreaRecognition() {
addObjectType("appl::widget::TextAreaRecognition"); addObjectType("appl::widget::TextAreaRecognition");
@ -19,9 +20,9 @@ void appl::widget::TextAreaRecognition::init() {
ewol::Widget::init(); ewol::Widget::init();
m_updateDone = false; m_updateDone = false;
//m_dollarEngine.loadPath("DATA:///text"); //m_dollarEngine.loadPath("DATA:text");
m_dollarEngine = dollar::createEngine("$P+"); m_dollarEngine = dollar::createEngine("$P+");
m_dollarEngine->loadPath("DATA:///reference"); m_dollarEngine->loadPath("DATA:reference");
// TODO: m_dollarEngine->setScaleKeepRatio(true); // TODO: m_dollarEngine->setScaleKeepRatio(true);
markToRedraw(); markToRedraw();
// connect a periodic update ... // connect a periodic update ...
@ -80,13 +81,14 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons
list.add(obj); list.add(obj);
} }
etk::String streamOut = doc.generateMachineString(); etk::String streamOut = doc.generateMachineString();
etk::Path fileName = "~/DOLLAR/corpus"; etk::String fileName;
fileName = "HOME:DOLLAR/corpus/";
if (_value == "/") { if (_value == "/") {
fileName /= "slash"; fileName += "slash";
} else if (_value == "\\") { } else if (_value == "\\") {
fileName /= "back-slash"; fileName += "back-slash";
} else { } else {
fileName /= _value; fileName += _value;
} }
fileName += "_"; fileName += "_";
fileName += _type; fileName += _type;
@ -95,14 +97,7 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons
fileName += "_"; fileName += "_";
fileName += etk::toString(m_time.get()); fileName += etk::toString(m_time.get());
fileName += ".json"; 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); APPL_WARNING("store: " << fileName);
} }
@ -142,7 +137,7 @@ etk::Vector<etk::Vector<vec2>> scalePoints(etk::Vector<etk::Vector<vec2>> _list,
return _list; return _list;
} }
etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec2>>& _list, int32_t _objectSize, const etk::Uri& _filename) { etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec2>>& _list, int32_t _objectSize, const etk::String& _filename) {
// generate SVG to render: // generate SVG to render:
esvg::Document docSvg; esvg::Document docSvg;
etk::String data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"); etk::String data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n");
@ -168,13 +163,7 @@ etk::Vector<etk::Color<float,4>> renderWithSVG(const etk::Vector<etk::Vector<vec
data += "</svg>\n"; data += "</svg>\n";
docSvg.parse(data); docSvg.parse(data);
//docSvg.store(list[index]->getName()+ ".svg"); //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 ... // generate SVG output ...
ivec2 renderSize = ivec2(_objectSize,_objectSize); ivec2 renderSize = ivec2(_objectSize,_objectSize);

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.debug as debug
import lutin.tools as tools import lutin.tools as tools
import os import os