Commit c5786a1a821d6d74771832851071c717b34d3ac1

Authored by Brendan Klare
2 parents 5d9b53fa 9f10de6b

Merge branch 'master' of https://github.com/biometrics/openbr

openbr/core/core.cpp
... ... @@ -184,6 +184,12 @@ struct AlgorithmCore
184 184 return fileList;
185 185 }
186 186  
  187 + void enroll(Template &data)
  188 + {
  189 + if (transform.isNull()) qFatal("Null transform.");
  190 + data >> *transform;
  191 + }
  192 +
187 193 void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles)
188 194 {
189 195 if (!file.getBool("enroll") && (QStringList() << "gal" << "mem" << "template").contains(file.suffix())) {
... ... @@ -371,6 +377,11 @@ FileList br::Enroll(const File &amp;input, const File &amp;gallery)
371 377 return AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery);
372 378 }
373 379  
  380 +void br::Enroll(Template &tmpl)
  381 +{
  382 + AlgorithmManager::getAlgorithm(tmpl.file.get<QString>("algorithm"))->enroll(tmpl);
  383 +}
  384 +
374 385 void br::Compare(const File &targetGallery, const File &queryGallery, const File &output)
375 386 {
376 387 AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->compare(targetGallery, queryGallery, output);
... ...
openbr/openbr.cpp
... ... @@ -23,6 +23,7 @@
23 23 #include "core/plot.h"
24 24 #include "core/qtutils.h"
25 25 #include "plugins/openbr_internal.h"
  26 +#include <opencv2/highgui/highgui.hpp>
26 27  
27 28 using namespace br;
28 29  
... ... @@ -114,6 +115,14 @@ void br_initialize(int &amp;argc, char *argv[], const char *sdk_path)
114 115 Context::initialize(argc, argv, sdk_path);
115 116 }
116 117  
  118 +void br_initialize_default()
  119 +{
  120 + int argc = 1;
  121 + char app[] = "br";
  122 + char *argv[1] = {app};
  123 + Context::initialize(argc, argv, "");
  124 +}
  125 +
117 126 bool br_is_classifier(const char *algorithm)
118 127 {
119 128 return IsClassifier(algorithm);
... ... @@ -289,3 +298,41 @@ void br_slave_process(const char * baseName)
289 298 worker->mainLoop();
290 299 delete worker;
291 300 }
  301 +
  302 +br_template br_load_img(const char *data, int len)
  303 +{
  304 + std::vector<char> buf(data, data+len);
  305 + cv::Mat img = cv::imdecode(cv::Mat(buf), CV_LOAD_IMAGE_COLOR);
  306 + Template *tmpl = new Template(img);
  307 + return (br_template)tmpl;
  308 +}
  309 +
  310 +unsigned char *br_unload_img(br_template tmpl)
  311 +{
  312 + Template *t = reinterpret_cast<Template*>(tmpl);
  313 + return t->m().data;
  314 +}
  315 +
  316 +int br_img_rows(br_template tmpl)
  317 +{
  318 + Template *t = reinterpret_cast<Template*>(tmpl);
  319 + return t->m().rows;
  320 +}
  321 +
  322 +int br_img_cols(br_template tmpl)
  323 +{
  324 + Template *t = reinterpret_cast<Template*>(tmpl);
  325 + return t->m().cols;
  326 +}
  327 +
  328 +int br_img_channels(br_template tmpl)
  329 +{
  330 + Template *t = reinterpret_cast<Template*>(tmpl);
  331 + return t->m().channels();
  332 +}
  333 +
  334 +void br_enroll_template(br_template tmpl)
  335 +{
  336 + Template *t = reinterpret_cast<Template*>(tmpl);
  337 + Enroll(*t);
  338 +}
... ...
openbr/openbr.h
... ... @@ -206,6 +206,11 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[],
206 206 * \see br_finalize
207 207 */
208 208 BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = "");
  209 +/*!
  210 + * \brief Wraps br::Context::initialize() with default arguments.
  211 + * \see br_finalize
  212 + */
  213 +BR_EXPORT void br_initialize_default();
209 214  
210 215 /*!
211 216 * \brief Wraps br::IsClassifier()
... ... @@ -414,6 +419,41 @@ BR_EXPORT const char *br_version();
414 419 */
415 420 BR_EXPORT void br_slave_process(const char * baseKey);
416 421  
  422 +// to avoid having to include unwanted headers
  423 +// this will be this header's conception of a template
  424 +// any functions that need a Template pointer
  425 +// will take this typedef and cast it
  426 +typedef void* br_template;
  427 +/*!
  428 + * \brief Load an image from a string buffer.
  429 + * Easy way to pass an image in memory from another programming language to openbr.
  430 + * \param data The image buffer.
  431 + * \param len The length of the buffer.
  432 + * \see br_unload_img
  433 + */
  434 +BR_EXPORT br_template br_load_img(const char *data, int len);
  435 +/*!
  436 + * \brief Unload an image to a string buffer.
  437 + * Easy way to pass an image from openbr to another programming language.
  438 + */
  439 +BR_EXPORT unsigned char* br_unload_img(br_template tmpl);
  440 +/*!
  441 + * \brief Get the number of rows in an image.
  442 + */
  443 +BR_EXPORT int br_img_rows(br_template tmpl);
  444 +/*!
  445 + * \brief Get the number of columns in an image.
  446 + */
  447 +BR_EXPORT int br_img_cols(br_template tmpl);
  448 +/*!
  449 + * \brief Get the number of channels in an image.
  450 + */
  451 +BR_EXPORT int br_img_channels(br_template tmpl);
  452 +/*!
  453 + * \brief Enroll a br::Template from the C API!
  454 + */
  455 +BR_EXPORT void br_enroll_template(br_template tmpl);
  456 +
417 457 /*! @}*/
418 458  
419 459 #ifdef __cplusplus
... ...
openbr/openbr_plugin.h
... ... @@ -1317,6 +1317,11 @@ BR_EXPORT void Train(const File &amp;input, const File &amp;model);
1317 1317 * \see br_enroll
1318 1318 */
1319 1319 BR_EXPORT FileList Enroll(const File &input, const File &gallery = File());
  1320 +/*!
  1321 + * \brief High-level function for enrolling templates.
  1322 + * \see br_enroll
  1323 + */
  1324 +BR_EXPORT void Enroll(Template &tmpl);
1320 1325  
1321 1326 /*!
1322 1327 * \brief High-level function for comparing galleries.
... ...