From 32bfcd7201ca69b970a40377eed08f8fed0cf53a Mon Sep 17 00:00:00 2001 From: Austin Blanton Date: Tue, 24 Dec 2013 20:59:04 -0500 Subject: [PATCH] Add C API calls for compare with void pointers (and more\!) --- openbr/core/core.cpp | 7 +++++++ openbr/openbr.cpp | 35 +++++++++++++++++++++++++++++++++++ openbr/openbr.h | 26 +++++++++++++++++++++++++- openbr/openbr_plugin.h | 5 +++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 13b4ae3..5365503 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -430,6 +430,13 @@ void br::Compare(const File &targetGallery, const File &queryGallery, const File AlgorithmManager::getAlgorithm(output.get("algorithm"))->compare(targetGallery, queryGallery, output); } +void br::CompareTemplateLists(const TemplateList &target, const TemplateList &query, Output *output) +{ + QString alg = output->file.get("algorithm"); + QSharedPointer dist = Distance::fromAlgorithm(alg); + dist->compare(target, query, output); +} + void br::PairwiseCompare(const File &targetGallery, const File &queryGallery, const File &output) { AlgorithmManager::getAlgorithm(output.get("algorithm"))->pairwiseCompare(targetGallery, queryGallery, output); diff --git a/openbr/openbr.cpp b/openbr/openbr.cpp index 981d000..8b5582b 100644 --- a/openbr/openbr.cpp +++ b/openbr/openbr.cpp @@ -323,6 +323,14 @@ unsigned char *br_unload_img(br_template tmpl) return t->m().data; } +br_template_list br_template_list_from_buffer(const char *buf, int len) +{ + QByteArray arr(buf, len); + TemplateList *tl = new TemplateList(); + *tl = TemplateList::fromBuffer(arr); + return (br_template_list)tl; +} + void br_free_template(br_template tmpl) { Template *t = reinterpret_cast(tmpl); @@ -335,6 +343,12 @@ void br_free_template_list(br_template_list tl) delete realTL; } +void br_free_output(br_matrix_output output) +{ + MatrixOutput *matOut = reinterpret_cast(output); + delete matOut; +} + int br_img_rows(br_template tmpl) { Template *t = reinterpret_cast(tmpl); @@ -359,6 +373,12 @@ bool br_img_is_empty(br_template tmpl) return t->m().empty(); } +const char* br_get_filename(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + return t->file.name.toStdString().c_str(); +} + void br_set_filename(br_template tmpl, const char *filename) { Template *t = reinterpret_cast(tmpl); @@ -391,6 +411,21 @@ void br_enroll_template_list(br_template_list tl) Enroll(*realTL); } +br_matrix_output br_compare_template_lists(br_template_list target, br_template_list query) +{ + TemplateList *targetTL = reinterpret_cast(target); + TemplateList *queryTL = reinterpret_cast(query); + MatrixOutput *output = MatrixOutput::make(targetTL->files(), queryTL->files()); + CompareTemplateLists(*targetTL, *queryTL, output); + return (br_matrix_output)output; +} + +float br_get_matrix_output_at(br_matrix_output output, int row, int col) +{ + MatrixOutput *matOut = reinterpret_cast(output); + return matOut->data.at(row, col); +} + br_template br_get_template(br_template_list tl, int index) { TemplateList *realTL = reinterpret_cast(tl); diff --git a/openbr/openbr.h b/openbr/openbr.h index fdecfc7..6dd19b7 100644 --- a/openbr/openbr.h +++ b/openbr/openbr.h @@ -437,6 +437,7 @@ BR_EXPORT void br_slave_process(const char * baseKey); typedef void* br_template; typedef void* br_template_list; typedef void* br_gallery; +typedef void* br_matrix_output; /*! * \brief Load an image from a string buffer. * Easy way to pass an image in memory from another programming language to openbr. @@ -452,6 +453,12 @@ BR_EXPORT br_template br_load_img(const char *data, int len); */ BR_EXPORT unsigned char* br_unload_img(br_template tmpl); /*! + * \brief Deserialize a br::TemplateList from a buffer. + * Can be the buffer for a .gal file, + * since they are just a TemplateList serialized to disk. + */ +BR_EXPORT br_template_list br_template_list_from_buffer(const char *buf, int len); +/*! * \brief Free a br::Template's memory. */ BR_EXPORT void br_free_template(br_template tmpl); @@ -460,6 +467,10 @@ BR_EXPORT void br_free_template(br_template tmpl); */ BR_EXPORT void br_free_template_list(br_template_list tl); /*! + * \brief Free a br::Output's memory. + */ +BR_EXPORT void br_free_output(br_matrix_output output); +/*! * \brief Get the number of rows in an image. * \param tmpl Pointer to a br::Template. */ @@ -479,7 +490,11 @@ BR_EXPORT int br_img_channels(br_template tmpl); */ BR_EXPORT bool br_img_is_empty(br_template tmpl); /*! - * \brief Set the filename for a template. + * \brief Get the filename for a br::Template + */ +BR_EXPORT const char* br_get_filename(br_template tmpl); +/*! + * \brief Set the filename for a br::Template. */ BR_EXPORT void br_set_filename(br_template tmpl, const char *filename); /*! @@ -497,6 +512,15 @@ BR_EXPORT br_template_list br_enroll_template(br_template tmpl); */ BR_EXPORT void br_enroll_template_list(br_template_list tl); /*! + * \brief Compare br::TemplateLists from the C API! + * \return Pointer to a br::MatrixOutput. + */ +BR_EXPORT br_matrix_output br_compare_template_lists(br_template_list target, br_template_list query); +/*! + * \brief Get a value in the br::MatrixOutput. + */ +BR_EXPORT float br_get_matrix_output_at(br_matrix_output output, int row, int col); +/*! * \brief Get a pointer to a br::Template at a specified index. * \param tl Pointer to a br::TemplateList. * \param index The index of the br::Template. diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 30f3799..58689b8 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1343,6 +1343,11 @@ BR_EXPORT void Enroll(TemplateList &tmpl); * \see br_compare */ BR_EXPORT void Compare(const File &targetGallery, const File &queryGallery, const File &output); +/*! + * \brief High-level function for comparing templates. + */ +BR_EXPORT void CompareTemplateLists(const TemplateList &target, const TemplateList &query, Output *output); + /*! * \brief High-level function for doing a series of pairwise comparisons. -- libgit2 0.21.4