Commit 32bfcd7201ca69b970a40377eed08f8fed0cf53a
1 parent
5e74d174
Add C API calls for compare with void pointers (and more\!)
Showing
4 changed files
with
72 additions
and
1 deletions
openbr/core/core.cpp
| ... | ... | @@ -430,6 +430,13 @@ void br::Compare(const File &targetGallery, const File &queryGallery, const File |
| 430 | 430 | AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->compare(targetGallery, queryGallery, output); |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | +void br::CompareTemplateLists(const TemplateList &target, const TemplateList &query, Output *output) | |
| 434 | +{ | |
| 435 | + QString alg = output->file.get<QString>("algorithm"); | |
| 436 | + QSharedPointer<Distance> dist = Distance::fromAlgorithm(alg); | |
| 437 | + dist->compare(target, query, output); | |
| 438 | +} | |
| 439 | + | |
| 433 | 440 | void br::PairwiseCompare(const File &targetGallery, const File &queryGallery, const File &output) |
| 434 | 441 | { |
| 435 | 442 | AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->pairwiseCompare(targetGallery, queryGallery, output); | ... | ... |
openbr/openbr.cpp
| ... | ... | @@ -323,6 +323,14 @@ unsigned char *br_unload_img(br_template tmpl) |
| 323 | 323 | return t->m().data; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | +br_template_list br_template_list_from_buffer(const char *buf, int len) | |
| 327 | +{ | |
| 328 | + QByteArray arr(buf, len); | |
| 329 | + TemplateList *tl = new TemplateList(); | |
| 330 | + *tl = TemplateList::fromBuffer(arr); | |
| 331 | + return (br_template_list)tl; | |
| 332 | +} | |
| 333 | + | |
| 326 | 334 | void br_free_template(br_template tmpl) |
| 327 | 335 | { |
| 328 | 336 | Template *t = reinterpret_cast<Template*>(tmpl); |
| ... | ... | @@ -335,6 +343,12 @@ void br_free_template_list(br_template_list tl) |
| 335 | 343 | delete realTL; |
| 336 | 344 | } |
| 337 | 345 | |
| 346 | +void br_free_output(br_matrix_output output) | |
| 347 | +{ | |
| 348 | + MatrixOutput *matOut = reinterpret_cast<MatrixOutput*>(output); | |
| 349 | + delete matOut; | |
| 350 | +} | |
| 351 | + | |
| 338 | 352 | int br_img_rows(br_template tmpl) |
| 339 | 353 | { |
| 340 | 354 | Template *t = reinterpret_cast<Template*>(tmpl); |
| ... | ... | @@ -359,6 +373,12 @@ bool br_img_is_empty(br_template tmpl) |
| 359 | 373 | return t->m().empty(); |
| 360 | 374 | } |
| 361 | 375 | |
| 376 | +const char* br_get_filename(br_template tmpl) | |
| 377 | +{ | |
| 378 | + Template *t = reinterpret_cast<Template*>(tmpl); | |
| 379 | + return t->file.name.toStdString().c_str(); | |
| 380 | +} | |
| 381 | + | |
| 362 | 382 | void br_set_filename(br_template tmpl, const char *filename) |
| 363 | 383 | { |
| 364 | 384 | Template *t = reinterpret_cast<Template*>(tmpl); |
| ... | ... | @@ -391,6 +411,21 @@ void br_enroll_template_list(br_template_list tl) |
| 391 | 411 | Enroll(*realTL); |
| 392 | 412 | } |
| 393 | 413 | |
| 414 | +br_matrix_output br_compare_template_lists(br_template_list target, br_template_list query) | |
| 415 | +{ | |
| 416 | + TemplateList *targetTL = reinterpret_cast<TemplateList*>(target); | |
| 417 | + TemplateList *queryTL = reinterpret_cast<TemplateList*>(query); | |
| 418 | + MatrixOutput *output = MatrixOutput::make(targetTL->files(), queryTL->files()); | |
| 419 | + CompareTemplateLists(*targetTL, *queryTL, output); | |
| 420 | + return (br_matrix_output)output; | |
| 421 | +} | |
| 422 | + | |
| 423 | +float br_get_matrix_output_at(br_matrix_output output, int row, int col) | |
| 424 | +{ | |
| 425 | + MatrixOutput *matOut = reinterpret_cast<MatrixOutput*>(output); | |
| 426 | + return matOut->data.at<float>(row, col); | |
| 427 | +} | |
| 428 | + | |
| 394 | 429 | br_template br_get_template(br_template_list tl, int index) |
| 395 | 430 | { |
| 396 | 431 | TemplateList *realTL = reinterpret_cast<TemplateList*>(tl); | ... | ... |
openbr/openbr.h
| ... | ... | @@ -437,6 +437,7 @@ BR_EXPORT void br_slave_process(const char * baseKey); |
| 437 | 437 | typedef void* br_template; |
| 438 | 438 | typedef void* br_template_list; |
| 439 | 439 | typedef void* br_gallery; |
| 440 | +typedef void* br_matrix_output; | |
| 440 | 441 | /*! |
| 441 | 442 | * \brief Load an image from a string buffer. |
| 442 | 443 | * 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); |
| 452 | 453 | */ |
| 453 | 454 | BR_EXPORT unsigned char* br_unload_img(br_template tmpl); |
| 454 | 455 | /*! |
| 456 | + * \brief Deserialize a br::TemplateList from a buffer. | |
| 457 | + * Can be the buffer for a .gal file, | |
| 458 | + * since they are just a TemplateList serialized to disk. | |
| 459 | + */ | |
| 460 | +BR_EXPORT br_template_list br_template_list_from_buffer(const char *buf, int len); | |
| 461 | +/*! | |
| 455 | 462 | * \brief Free a br::Template's memory. |
| 456 | 463 | */ |
| 457 | 464 | BR_EXPORT void br_free_template(br_template tmpl); |
| ... | ... | @@ -460,6 +467,10 @@ BR_EXPORT void br_free_template(br_template tmpl); |
| 460 | 467 | */ |
| 461 | 468 | BR_EXPORT void br_free_template_list(br_template_list tl); |
| 462 | 469 | /*! |
| 470 | + * \brief Free a br::Output's memory. | |
| 471 | + */ | |
| 472 | +BR_EXPORT void br_free_output(br_matrix_output output); | |
| 473 | +/*! | |
| 463 | 474 | * \brief Get the number of rows in an image. |
| 464 | 475 | * \param tmpl Pointer to a br::Template. |
| 465 | 476 | */ |
| ... | ... | @@ -479,7 +490,11 @@ BR_EXPORT int br_img_channels(br_template tmpl); |
| 479 | 490 | */ |
| 480 | 491 | BR_EXPORT bool br_img_is_empty(br_template tmpl); |
| 481 | 492 | /*! |
| 482 | - * \brief Set the filename for a template. | |
| 493 | + * \brief Get the filename for a br::Template | |
| 494 | + */ | |
| 495 | +BR_EXPORT const char* br_get_filename(br_template tmpl); | |
| 496 | +/*! | |
| 497 | + * \brief Set the filename for a br::Template. | |
| 483 | 498 | */ |
| 484 | 499 | BR_EXPORT void br_set_filename(br_template tmpl, const char *filename); |
| 485 | 500 | /*! |
| ... | ... | @@ -497,6 +512,15 @@ BR_EXPORT br_template_list br_enroll_template(br_template tmpl); |
| 497 | 512 | */ |
| 498 | 513 | BR_EXPORT void br_enroll_template_list(br_template_list tl); |
| 499 | 514 | /*! |
| 515 | + * \brief Compare br::TemplateLists from the C API! | |
| 516 | + * \return Pointer to a br::MatrixOutput. | |
| 517 | + */ | |
| 518 | +BR_EXPORT br_matrix_output br_compare_template_lists(br_template_list target, br_template_list query); | |
| 519 | +/*! | |
| 520 | + * \brief Get a value in the br::MatrixOutput. | |
| 521 | + */ | |
| 522 | +BR_EXPORT float br_get_matrix_output_at(br_matrix_output output, int row, int col); | |
| 523 | +/*! | |
| 500 | 524 | * \brief Get a pointer to a br::Template at a specified index. |
| 501 | 525 | * \param tl Pointer to a br::TemplateList. |
| 502 | 526 | * \param index The index of the br::Template. | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -1343,6 +1343,11 @@ BR_EXPORT void Enroll(TemplateList &tmpl); |
| 1343 | 1343 | * \see br_compare |
| 1344 | 1344 | */ |
| 1345 | 1345 | BR_EXPORT void Compare(const File &targetGallery, const File &queryGallery, const File &output); |
| 1346 | +/*! | |
| 1347 | + * \brief High-level function for comparing templates. | |
| 1348 | + */ | |
| 1349 | +BR_EXPORT void CompareTemplateLists(const TemplateList &target, const TemplateList &query, Output *output); | |
| 1350 | + | |
| 1346 | 1351 | |
| 1347 | 1352 | /*! |
| 1348 | 1353 | * \brief High-level function for doing a series of pairwise comparisons. | ... | ... |