Commit 51f633f32529f38b6194a3c18579f0fd78320eb7
1 parent
8ea461f0
Decode and enroll images from strings in C API
Showing
4 changed files
with
78 additions
and
1 deletions
openbr/core/core.cpp
| @@ -160,7 +160,7 @@ struct AlgorithmCore | @@ -160,7 +160,7 @@ struct AlgorithmCore | ||
| 160 | data.removeAt(i); | 160 | data.removeAt(i); |
| 161 | const int numFiles = data.size(); | 161 | const int numFiles = data.size(); |
| 162 | 162 | ||
| 163 | - data >> *transform; | 163 | + enroll(data); |
| 164 | 164 | ||
| 165 | g->writeBlock(data); | 165 | g->writeBlock(data); |
| 166 | const FileList newFiles = data.files(); | 166 | const FileList newFiles = data.files(); |
| @@ -184,6 +184,11 @@ struct AlgorithmCore | @@ -184,6 +184,11 @@ struct AlgorithmCore | ||
| 184 | return fileList; | 184 | return fileList; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | + void enroll(TemplateList &data) | ||
| 188 | + { | ||
| 189 | + data >> *transform; | ||
| 190 | + } | ||
| 191 | + | ||
| 187 | void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles) | 192 | void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles) |
| 188 | { | 193 | { |
| 189 | if (!file.getBool("enroll") && (QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { | 194 | if (!file.getBool("enroll") && (QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { |
| @@ -371,6 +376,14 @@ FileList br::Enroll(const File &input, const File &gallery) | @@ -371,6 +376,14 @@ FileList br::Enroll(const File &input, const File &gallery) | ||
| 371 | return AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery); | 376 | return AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery); |
| 372 | } | 377 | } |
| 373 | 378 | ||
| 379 | +void br::Enroll(const Template &tmpl) | ||
| 380 | +{ | ||
| 381 | + QList<Template> tmpls; | ||
| 382 | + tmpls.append(tmpl); | ||
| 383 | + TemplateList tl(tmpls); | ||
| 384 | + AlgorithmManager::getAlgorithm(tmpl.file.get<QString>("algorithm"))->enroll(tl); | ||
| 385 | +} | ||
| 386 | + | ||
| 374 | void br::Compare(const File &targetGallery, const File &queryGallery, const File &output) | 387 | void br::Compare(const File &targetGallery, const File &queryGallery, const File &output) |
| 375 | { | 388 | { |
| 376 | AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->compare(targetGallery, queryGallery, output); | 389 | AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->compare(targetGallery, queryGallery, output); |
openbr/openbr.cpp
| @@ -23,6 +23,7 @@ | @@ -23,6 +23,7 @@ | ||
| 23 | #include "core/plot.h" | 23 | #include "core/plot.h" |
| 24 | #include "core/qtutils.h" | 24 | #include "core/qtutils.h" |
| 25 | #include "plugins/openbr_internal.h" | 25 | #include "plugins/openbr_internal.h" |
| 26 | +#include <opencv2/highgui/highgui.hpp> | ||
| 26 | 27 | ||
| 27 | using namespace br; | 28 | using namespace br; |
| 28 | 29 | ||
| @@ -114,6 +115,14 @@ void br_initialize(int &argc, char *argv[], const char *sdk_path) | @@ -114,6 +115,14 @@ void br_initialize(int &argc, char *argv[], const char *sdk_path) | ||
| 114 | Context::initialize(argc, argv, sdk_path); | 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 | bool br_is_classifier(const char *algorithm) | 126 | bool br_is_classifier(const char *algorithm) |
| 118 | { | 127 | { |
| 119 | return IsClassifier(algorithm); | 128 | return IsClassifier(algorithm); |
| @@ -289,3 +298,36 @@ void br_slave_process(const char * baseName) | @@ -289,3 +298,36 @@ void br_slave_process(const char * baseName) | ||
| 289 | worker->mainLoop(); | 298 | worker->mainLoop(); |
| 290 | delete worker; | 299 | delete worker; |
| 291 | } | 300 | } |
| 301 | + | ||
| 302 | +br_template br_load_img(const char *data) | ||
| 303 | +{ | ||
| 304 | + int size = strlen(data); | ||
| 305 | + std::vector<char> buf(data, data+size); | ||
| 306 | + cv::Mat img = cv::imdecode(cv::Mat(buf), CV_LOAD_IMAGE_ANYDEPTH); | ||
| 307 | + Template *tmpl = new Template(img); | ||
| 308 | + return (br_template)tmpl; | ||
| 309 | +} | ||
| 310 | + | ||
| 311 | +const unsigned char *br_unload_img(br_template tmpl) | ||
| 312 | +{ | ||
| 313 | + Template *t = (Template*)tmpl; | ||
| 314 | + return t->m().data; | ||
| 315 | +} | ||
| 316 | + | ||
| 317 | +int br_img_rows(br_template tmpl) | ||
| 318 | +{ | ||
| 319 | + Template *t = (Template*)tmpl; | ||
| 320 | + return t->m().rows; | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | +int br_img_cols(br_template tmpl) | ||
| 324 | +{ | ||
| 325 | + Template *t = (Template*)tmpl; | ||
| 326 | + return t->m().cols; | ||
| 327 | +} | ||
| 328 | + | ||
| 329 | +void br_enroll_template(br_template tmpl) | ||
| 330 | +{ | ||
| 331 | + Template *t = (Template*)tmpl; | ||
| 332 | + Enroll(*t); | ||
| 333 | +} |
openbr/openbr.h
| @@ -206,6 +206,7 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], | @@ -206,6 +206,7 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], | ||
| 206 | * \see br_finalize | 206 | * \see br_finalize |
| 207 | */ | 207 | */ |
| 208 | BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = ""); | 208 | BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = ""); |
| 209 | +BR_EXPORT void br_initialize_default(); | ||
| 209 | 210 | ||
| 210 | /*! | 211 | /*! |
| 211 | * \brief Wraps br::IsClassifier() | 212 | * \brief Wraps br::IsClassifier() |
| @@ -414,6 +415,22 @@ BR_EXPORT const char *br_version(); | @@ -414,6 +415,22 @@ BR_EXPORT const char *br_version(); | ||
| 414 | */ | 415 | */ |
| 415 | BR_EXPORT void br_slave_process(const char * baseKey); | 416 | BR_EXPORT void br_slave_process(const char * baseKey); |
| 416 | 417 | ||
| 418 | +// to avoid having to include unwanted headers | ||
| 419 | +// this will be this header's conception of a template | ||
| 420 | +// any functions that need a Template pointer | ||
| 421 | +// will take this typedef and cast it | ||
| 422 | +// (and then we'll cross our fingers) | ||
| 423 | +typedef void* br_template; | ||
| 424 | +/*! | ||
| 425 | + * \brief Load an image from a string buffer. | ||
| 426 | + * Easy way to pass an image in memory from another programming language to openbr. | ||
| 427 | + */ | ||
| 428 | +BR_EXPORT br_template br_load_img(const char *data); | ||
| 429 | +BR_EXPORT const unsigned char* br_unload_img(br_template tmpl); | ||
| 430 | +BR_EXPORT int br_img_rows(br_template tmpl); | ||
| 431 | +BR_EXPORT int br_img_cols(br_template tmpl); | ||
| 432 | +BR_EXPORT void br_enroll_template(br_template tmpl); | ||
| 433 | + | ||
| 417 | /*! @}*/ | 434 | /*! @}*/ |
| 418 | 435 | ||
| 419 | #ifdef __cplusplus | 436 | #ifdef __cplusplus |
openbr/openbr_plugin.h
| @@ -1317,6 +1317,11 @@ BR_EXPORT void Train(const File &input, const File &model); | @@ -1317,6 +1317,11 @@ BR_EXPORT void Train(const File &input, const File &model); | ||
| 1317 | * \see br_enroll | 1317 | * \see br_enroll |
| 1318 | */ | 1318 | */ |
| 1319 | BR_EXPORT FileList Enroll(const File &input, const File &gallery = File()); | 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(const Template &tmpl); | ||
| 1320 | 1325 | ||
| 1321 | /*! | 1326 | /*! |
| 1322 | * \brief High-level function for comparing galleries. | 1327 | * \brief High-level function for comparing galleries. |