Commit 396f323ab9221998be2605bee3797a2db093ed91
1 parent
b4c3e2bd
added/moved some shared functionality into universal_template
Showing
4 changed files
with
78 additions
and
13 deletions
app/CMakeLists.txt
app/br-download/br-download.cpp
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | #include <cstdio> |
| 21 | 21 | #include <cstring> |
| 22 | 22 | #include <string> |
| 23 | +#include <openbr/universal_template.h> | |
| 23 | 24 | |
| 24 | 25 | using namespace cv; |
| 25 | 26 | using namespace std; |
| ... | ... | @@ -62,17 +63,8 @@ static bool processReply(QNetworkReply* reply) |
| 62 | 63 | static QMutex lock; |
| 63 | 64 | QMutexLocker locker(&lock); |
| 64 | 65 | |
| 65 | - QFile file; | |
| 66 | - file.open(stdout, QFile::WriteOnly); | |
| 67 | 66 | const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); |
| 68 | - file.write(hash); // ImageID | |
| 69 | - file.write(hash); // TemplateID | |
| 70 | - const int32_t algorithmID = 3; // Encoded image | |
| 71 | - file.write((const char*) &algorithmID, 4); // AlgorithmID | |
| 72 | - const uint32_t size = data.size(); | |
| 73 | - file.write((const char*) &size, 4); // Size | |
| 74 | - file.write(data); | |
| 75 | - file.flush(); | |
| 67 | + br_append_utemplate_contents(stdout, reinterpret_cast<const int8_t*>(hash.data()), reinterpret_cast<const int8_t*>(hash.data()), 3, data.size(), reinterpret_cast<const int8_t*>(data.data())); | |
| 76 | 68 | return true; |
| 77 | 69 | } |
| 78 | 70 | ... | ... |
openbr/universal_template.cpp
| 1 | +#include <QFile> | |
| 2 | +#include <cstdlib> | |
| 3 | +#include <cstring> | |
| 4 | + | |
| 1 | 5 | #include "universal_template.h" |
| 2 | 6 | |
| 7 | +br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data) | |
| 8 | +{ | |
| 9 | + br_utemplate utemplate = (br_utemplate) malloc(sizeof(br_universal_template) + size); | |
| 10 | + memcpy(utemplate->imageID, imageID, 16); | |
| 11 | + memcpy(utemplate->templateID, templateID, 16); | |
| 12 | + utemplate->algorithmID = algorithmID; | |
| 13 | + utemplate->size = size; | |
| 14 | + memcpy(utemplate+1, data, size); | |
| 15 | + return utemplate; | |
| 16 | +} | |
| 17 | + | |
| 18 | +void br_free_utemplate(br_const_utemplate utemplate) | |
| 19 | +{ | |
| 20 | + free((void*) utemplate); | |
| 21 | +} | |
| 22 | + | |
| 23 | +void br_append_utemplate(FILE *file, br_const_utemplate utemplate) | |
| 24 | +{ | |
| 25 | + br_append_utemplate_contents(file, utemplate->imageID, utemplate->templateID, utemplate->algorithmID, utemplate->size, utemplate->data); | |
| 26 | +} | |
| 27 | + | |
| 28 | +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) | |
| 29 | +{ | |
| 30 | + QFile qFile; | |
| 31 | + qFile.open(file, QFile::WriteOnly | QFile::Append); | |
| 32 | + qFile.write((const char*) imageID, 16); | |
| 33 | + qFile.write((const char*) templateID, 16); | |
| 34 | + qFile.write((const char*) &algorithmID, 4); | |
| 35 | + qFile.write((const char*) &size, 4); | |
| 36 | + qFile.write((const char*) data, size); | |
| 37 | +} | ... | ... |
openbr/universal_template.h
| ... | ... | @@ -17,18 +17,55 @@ |
| 17 | 17 | #ifndef BR_UNIVERSAL_TEMPLATE_H |
| 18 | 18 | #define BR_UNIVERSAL_TEMPLATE_H |
| 19 | 19 | |
| 20 | +#include <stdio.h> | |
| 20 | 21 | #include <stdint.h> |
| 22 | +#include <openbr/openbr_export.h> | |
| 23 | + | |
| 24 | +#ifdef __cplusplus | |
| 25 | +extern "C" { | |
| 26 | +#endif | |
| 21 | 27 | |
| 22 | 28 | /*! |
| 23 | 29 | * \brief A flat template format for representing arbitrary feature vectors. |
| 24 | 30 | */ |
| 25 | 31 | struct br_universal_template |
| 26 | 32 | { |
| 27 | - uint8_t imageID[16]; /*!< MD5 hash of the undecoded origin file. */ | |
| 28 | - uint8_t templateID[16]; /*!< MD5 hash of _data_. */ | |
| 33 | + int8_t imageID[16]; /*!< MD5 hash of the undecoded origin file. */ | |
| 34 | + int8_t templateID[16]; /*!< MD5 hash of _data_. */ | |
| 29 | 35 | int32_t algorithmID; /*!< type of _data_. */ |
| 30 | 36 | uint32_t size; /*!< length of _data_. */ |
| 31 | - uint8_t data[]; /*!< _size_-byte buffer. */ | |
| 37 | + int8_t data[]; /*!< _size_-byte buffer. */ | |
| 32 | 38 | }; |
| 33 | 39 | |
| 40 | +typedef struct br_universal_template *br_utemplate; | |
| 41 | +typedef const struct br_universal_template *br_const_utemplate; | |
| 42 | + | |
| 43 | +/*! | |
| 44 | + * \brief br_universal_template constructor. | |
| 45 | + * \see br_free_utemplate | |
| 46 | + */ | |
| 47 | +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); | |
| 48 | + | |
| 49 | +/*! | |
| 50 | + * \brief br_universal_template destructor. | |
| 51 | + * \see br_new_utemplate | |
| 52 | + */ | |
| 53 | +BR_EXPORT void br_free_utemplate(br_const_utemplate utemplate); | |
| 54 | + | |
| 55 | +/*! | |
| 56 | + * \brief Serialize a br_universal_template to a file. | |
| 57 | + * \see br_append_utemplate_contents | |
| 58 | + */ | |
| 59 | +BR_EXPORT void br_append_utemplate(FILE *file, br_const_utemplate utemplate); | |
| 60 | + | |
| 61 | +/*! | |
| 62 | + * \brief Serialize a br_universal_template to a file. | |
| 63 | + * \see br_append_utemplate | |
| 64 | + */ | |
| 65 | +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); | |
| 66 | + | |
| 67 | +#ifdef __cplusplus | |
| 68 | +} | |
| 69 | +#endif | |
| 70 | + | |
| 34 | 71 | #endif // BR_UNIVERSAL_TEMPLATE_H | ... | ... |