Commit effd3d229305ca9aaa041ae12e58c21134f04298

Authored by Charles Otto
1 parent 725e25b4

Add a Transform interface to distance -- compares each input against a fixed gallery

Showing 1 changed file with 37 additions and 0 deletions
openbr/plugins/distance.cpp
... ... @@ -23,6 +23,7 @@
23 23  
24 24 #include "openbr/core/distance_sse.h"
25 25 #include "openbr/core/qtutils.h"
  26 +#include "openbr/core/opencvutils.h"
26 27  
27 28 using namespace cv;
28 29  
... ... @@ -450,5 +451,41 @@ class SumDistance : public Distance
450 451  
451 452 BR_REGISTER(Distance, SumDistance)
452 453  
  454 +/*!
  455 + * \ingroup transforms
  456 + * \brief Compare each template to a fixed gallery (with name = galleryName), using the specified distance.
  457 + * dst will contain a 1 by n vector of scores.
  458 + * \author Charles Otto \cite caotto
  459 + */
  460 +class GalleryCompareTransform : public Transform
  461 +{
  462 + Q_OBJECT
  463 + Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
  464 + Q_PROPERTY(QString galleryName READ get_galleryName WRITE set_galleryName RESET reset_galleryName STORED false)
  465 + BR_PROPERTY(br::Distance*, distance, NULL)
  466 + BR_PROPERTY(QString, galleryName, "")
  467 +
  468 + TemplateList gallery;
  469 +
  470 + void project(const Template &src, Template &dst) const
  471 + {
  472 + dst = src;
  473 + if (gallery.isEmpty())
  474 + return;
  475 +
  476 + QList<float> line = distance->compare(gallery, src);
  477 + dst.m() = OpenCVUtils::toMat(line, 1);
  478 + }
  479 +
  480 + void init()
  481 + {
  482 + if (!galleryName.isEmpty())
  483 + gallery = TemplateList::fromGallery(galleryName);
  484 + }
  485 +};
  486 +
  487 +BR_REGISTER(Transform, GalleryCompareTransform)
  488 +
  489 +
453 490 } // namespace br
454 491 #include "distance.moc"
... ...