diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f566302..15f42d3 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -7,5 +7,6 @@ add_subdirectory(examples) # Build additional OpenBR utilities if(NOT ${BR_EMBEDDED}) add_subdirectory(br-download) + add_subdirectory(br-enroll) add_subdirectory(br-gui) endif() diff --git a/app/br-download/br-download.cpp b/app/br-download/br-download.cpp index 66ca074..013f5d7 100644 --- a/app/br-download/br-download.cpp +++ b/app/br-download/br-download.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace cv; using namespace std; @@ -62,17 +63,8 @@ static bool processReply(QNetworkReply* reply) static QMutex lock; QMutexLocker locker(&lock); - QFile file; - file.open(stdout, QFile::WriteOnly); const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); - file.write(hash); // ImageID - file.write(hash); // TemplateID - const int32_t algorithmID = 3; // Encoded image - file.write((const char*) &algorithmID, 4); // AlgorithmID - const uint32_t size = data.size(); - file.write((const char*) &size, 4); // Size - file.write(data); - file.flush(); + br_append_utemplate_contents(stdout, reinterpret_cast(hash.data()), reinterpret_cast(hash.data()), 3, data.size(), reinterpret_cast(data.data())); return true; } diff --git a/openbr/universal_template.cpp b/openbr/universal_template.cpp index 7f18ed8..809b428 100644 --- a/openbr/universal_template.cpp +++ b/openbr/universal_template.cpp @@ -1,2 +1,37 @@ +#include +#include +#include + #include "universal_template.h" +br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data) +{ + br_utemplate utemplate = (br_utemplate) malloc(sizeof(br_universal_template) + size); + memcpy(utemplate->imageID, imageID, 16); + memcpy(utemplate->templateID, templateID, 16); + utemplate->algorithmID = algorithmID; + utemplate->size = size; + memcpy(utemplate+1, data, size); + return utemplate; +} + +void br_free_utemplate(br_const_utemplate utemplate) +{ + free((void*) utemplate); +} + +void br_append_utemplate(FILE *file, br_const_utemplate utemplate) +{ + br_append_utemplate_contents(file, utemplate->imageID, utemplate->templateID, utemplate->algorithmID, utemplate->size, utemplate->data); +} + +void br_append_utemplate_contents(FILE *file, const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data) +{ + QFile qFile; + qFile.open(file, QFile::WriteOnly | QFile::Append); + qFile.write((const char*) imageID, 16); + qFile.write((const char*) templateID, 16); + qFile.write((const char*) &algorithmID, 4); + qFile.write((const char*) &size, 4); + qFile.write((const char*) data, size); +} diff --git a/openbr/universal_template.h b/openbr/universal_template.h index ba6011a..dbdcff7 100644 --- a/openbr/universal_template.h +++ b/openbr/universal_template.h @@ -17,18 +17,55 @@ #ifndef BR_UNIVERSAL_TEMPLATE_H #define BR_UNIVERSAL_TEMPLATE_H +#include #include +#include + +#ifdef __cplusplus +extern "C" { +#endif /*! * \brief A flat template format for representing arbitrary feature vectors. */ struct br_universal_template { - uint8_t imageID[16]; /*!< MD5 hash of the undecoded origin file. */ - uint8_t templateID[16]; /*!< MD5 hash of _data_. */ + int8_t imageID[16]; /*!< MD5 hash of the undecoded origin file. */ + int8_t templateID[16]; /*!< MD5 hash of _data_. */ int32_t algorithmID; /*!< type of _data_. */ uint32_t size; /*!< length of _data_. */ - uint8_t data[]; /*!< _size_-byte buffer. */ + int8_t data[]; /*!< _size_-byte buffer. */ }; +typedef struct br_universal_template *br_utemplate; +typedef const struct br_universal_template *br_const_utemplate; + +/*! + * \brief br_universal_template constructor. + * \see br_free_utemplate + */ +BR_EXPORT br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data); + +/*! + * \brief br_universal_template destructor. + * \see br_new_utemplate + */ +BR_EXPORT void br_free_utemplate(br_const_utemplate utemplate); + +/*! + * \brief Serialize a br_universal_template to a file. + * \see br_append_utemplate_contents + */ +BR_EXPORT void br_append_utemplate(FILE *file, br_const_utemplate utemplate); + +/*! + * \brief Serialize a br_universal_template to a file. + * \see br_append_utemplate + */ +BR_EXPORT void br_append_utemplate_contents(FILE *file, const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data); + +#ifdef __cplusplus +} +#endif + #endif // BR_UNIVERSAL_TEMPLATE_H