diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 06b7194..6eba193 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -184,6 +184,12 @@ struct AlgorithmCore return fileList; } + void enroll(Template &data) + { + if (transform.isNull()) qFatal("Null transform."); + data >> *transform; + } + void retrieveOrEnroll(const File &file, QScopedPointer &gallery, FileList &galleryFiles) { if (!file.getBool("enroll") && (QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { @@ -371,6 +377,11 @@ FileList br::Enroll(const File &input, const File &gallery) return AlgorithmManager::getAlgorithm(gallery.get("algorithm"))->enroll(input, gallery); } +void br::Enroll(Template &tmpl) +{ + AlgorithmManager::getAlgorithm(tmpl.file.get("algorithm"))->enroll(tmpl); +} + void br::Compare(const File &targetGallery, const File &queryGallery, const File &output) { AlgorithmManager::getAlgorithm(output.get("algorithm"))->compare(targetGallery, queryGallery, output); diff --git a/openbr/openbr.cpp b/openbr/openbr.cpp index 0a0ccc7..41c16db 100644 --- a/openbr/openbr.cpp +++ b/openbr/openbr.cpp @@ -23,6 +23,7 @@ #include "core/plot.h" #include "core/qtutils.h" #include "plugins/openbr_internal.h" +#include using namespace br; @@ -114,6 +115,14 @@ void br_initialize(int &argc, char *argv[], const char *sdk_path) Context::initialize(argc, argv, sdk_path); } +void br_initialize_default() +{ + int argc = 1; + char app[] = "br"; + char *argv[1] = {app}; + Context::initialize(argc, argv, ""); +} + bool br_is_classifier(const char *algorithm) { return IsClassifier(algorithm); @@ -289,3 +298,41 @@ void br_slave_process(const char * baseName) worker->mainLoop(); delete worker; } + +br_template br_load_img(const char *data, int len) +{ + std::vector buf(data, data+len); + cv::Mat img = cv::imdecode(cv::Mat(buf), CV_LOAD_IMAGE_COLOR); + Template *tmpl = new Template(img); + return (br_template)tmpl; +} + +unsigned char *br_unload_img(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + return t->m().data; +} + +int br_img_rows(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + return t->m().rows; +} + +int br_img_cols(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + return t->m().cols; +} + +int br_img_channels(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + return t->m().channels(); +} + +void br_enroll_template(br_template tmpl) +{ + Template *t = reinterpret_cast(tmpl); + Enroll(*t); +} diff --git a/openbr/openbr.h b/openbr/openbr.h index 93d0d8f..2690d0b 100644 --- a/openbr/openbr.h +++ b/openbr/openbr.h @@ -206,6 +206,11 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], * \see br_finalize */ BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = ""); +/*! + * \brief Wraps br::Context::initialize() with default arguments. + * \see br_finalize + */ +BR_EXPORT void br_initialize_default(); /*! * \brief Wraps br::IsClassifier() @@ -414,6 +419,41 @@ BR_EXPORT const char *br_version(); */ BR_EXPORT void br_slave_process(const char * baseKey); +// to avoid having to include unwanted headers +// this will be this header's conception of a template +// any functions that need a Template pointer +// will take this typedef and cast it +typedef void* br_template; +/*! + * \brief Load an image from a string buffer. + * Easy way to pass an image in memory from another programming language to openbr. + * \param data The image buffer. + * \param len The length of the buffer. + * \see br_unload_img + */ +BR_EXPORT br_template br_load_img(const char *data, int len); +/*! + * \brief Unload an image to a string buffer. + * Easy way to pass an image from openbr to another programming language. + */ +BR_EXPORT unsigned char* br_unload_img(br_template tmpl); +/*! + * \brief Get the number of rows in an image. + */ +BR_EXPORT int br_img_rows(br_template tmpl); +/*! + * \brief Get the number of columns in an image. + */ +BR_EXPORT int br_img_cols(br_template tmpl); +/*! + * \brief Get the number of channels in an image. + */ +BR_EXPORT int br_img_channels(br_template tmpl); +/*! + * \brief Enroll a br::Template from the C API! + */ +BR_EXPORT void br_enroll_template(br_template tmpl); + /*! @}*/ #ifdef __cplusplus diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index eb563c9..3ad907c 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1317,6 +1317,11 @@ BR_EXPORT void Train(const File &input, const File &model); * \see br_enroll */ BR_EXPORT FileList Enroll(const File &input, const File &gallery = File()); +/*! + * \brief High-level function for enrolling templates. + * \see br_enroll + */ +BR_EXPORT void Enroll(Template &tmpl); /*! * \brief High-level function for comparing galleries.