Commit 19dede75d79558c2e84add074f30ece2e3729607

Authored by sklum
2 parents f7e73dc8 fc1c58b6

Merge pull request #243 from biometrics/janus_search

Implemented openbr janus_search
openbr/gui/faceviewer.h
... ... @@ -19,7 +19,7 @@ public:
19 19 explicit FaceViewer(QWidget *parent = 0);
20 20  
21 21 public slots:
22   - void setFile(const File &file_);
  22 + void setFile(const br::File &file_);
23 23  
24 24 protected slots:
25 25 void mouseMoveEvent(QMouseEvent *event);
... ...
openbr/gui/templateviewer.h
... ... @@ -24,7 +24,7 @@ public:
24 24 explicit TemplateViewer(QWidget *parent = 0);
25 25  
26 26 public slots:
27   - void setFile(const File &file);
  27 + void setFile(const br::File &file);
28 28 void setEditable(bool enabled);
29 29 void setMousePoint(const QPointF &mousePoint);
30 30 void setFormat(const QString &format);
... ... @@ -52,10 +52,10 @@ protected slots:
52 52 void paintEvent(QPaintEvent *event);
53 53  
54 54 signals:
55   - void newInput(File);
  55 + void newInput(br::File);
56 56 void newInput(QImage);
57 57 void newMousePoint(QPointF);
58   - void selectedInput(File);
  58 + void selectedInput(br::File);
59 59 };
60 60  
61 61 }
... ...
openbr/gui/templateviewergrid.cpp
... ... @@ -18,10 +18,10 @@ void TemplateViewerGrid::setFiles(const FileList &files)
18 18 const int size = std::max(1, (int)ceil(sqrt((float)files.size())));
19 19 while (templateViewers.size() < size*size) {
20 20 templateViewers.append(QSharedPointer<TemplateViewer>(new TemplateViewer()));
21   - connect(templateViewers.last().data(), SIGNAL(newInput(File)), this, SIGNAL(newInput(File)));
  21 + connect(templateViewers.last().data(), SIGNAL(newInput(br::File)), this, SIGNAL(newInput(br::File)));
22 22 connect(templateViewers.last().data(), SIGNAL(newInput(QImage)), this, SIGNAL(newInput(QImage)));
23 23 connect(templateViewers.last().data(), SIGNAL(newMousePoint(QPointF)), this, SIGNAL(newMousePoint(QPointF)));
24   - connect(templateViewers.last().data(), SIGNAL(selectedInput(File)), this, SIGNAL(selectedInput(File)));
  24 + connect(templateViewers.last().data(), SIGNAL(selectedInput(br::File)), this, SIGNAL(selectedInput(br::File)));
25 25 }
26 26  
27 27 { // Clear layout
... ...
openbr/gui/templateviewergrid.h
... ... @@ -24,15 +24,15 @@ public:
24 24 explicit TemplateViewerGrid(QWidget *parent = 0);
25 25  
26 26 public slots:
27   - void setFiles(const FileList &file);
  27 + void setFiles(const br::FileList &file);
28 28 void setFormat(const QString &format);
29 29 void setMousePoint(const QPointF &mousePoint);
30 30  
31 31 signals:
32   - void newInput(File);
  32 + void newInput(br::File);
33 33 void newInput(QImage);
34 34 void newMousePoint(QPointF);
35   - void selectedInput(File);
  35 + void selectedInput(br::File);
36 36 };
37 37  
38 38 } // namespace br
... ...
openbr/janus.cpp
1 1 #include "janus.h"
2 2 #include "janus_io.h"
3 3 #include "openbr_plugin.h"
  4 +#include "openbr/core/opencvutils.h"
  5 +#include "openbr/core/common.h"
4 6  
5 7 using namespace br;
6 8  
... ... @@ -154,6 +156,34 @@ janus_error janus_gallery_size(janus_gallery gallery, size_t *size)
154 156 return JANUS_SUCCESS;
155 157 }
156 158  
  159 +janus_error janus_search(const janus_template template_, janus_gallery gallery, int requested_returns, janus_template_id *template_ids, float *similarities, int *actual_returns)
  160 +{
  161 + TemplateList query;
  162 + query.append(*template_);
  163 +
  164 + const TemplateList targets = TemplateList::fromGallery(gallery);
  165 +
  166 + if (targets.size() < requested_returns) *actual_returns = targets.size();
  167 + else *actual_returns = requested_returns;
  168 +
  169 + QScopedPointer<MatrixOutput> matrix(MatrixOutput::make(targets.files(), query.files()));
  170 + distance->compare(targets, query, matrix.data());
  171 +
  172 + typedef QPair<float,int> Pair;
  173 + QList<Pair> sortedSimilarities = Common::Sort(OpenCVUtils::matrixToVector<float>(matrix.data()->data.row(0)), true, *actual_returns);
  174 +
  175 + FileList targetFiles;
  176 + for (int i=0; i<sortedSimilarities.size(); i++) {
  177 + matrix.data()->data.at<float>(0,i) = sortedSimilarities[i].first;
  178 + targetFiles.append(targets[sortedSimilarities[i].second]);
  179 + }
  180 + const QVector<janus_template_id> targetIds = File::get<janus_template_id,File>(targetFiles, "TEMPLATE_ID").toVector();
  181 +
  182 + memcpy(similarities, matrix->data.data, *actual_returns * sizeof(float));
  183 + memcpy(template_ids, targetIds.data(), *actual_returns * sizeof(janus_template_id));
  184 + return JANUS_SUCCESS;
  185 +}
  186 +
157 187 janus_error janus_compare(janus_gallery target, janus_gallery query, float *similarity_matrix, janus_template_id *target_ids, janus_template_id *query_ids)
158 188 {
159 189 const TemplateList targets = TemplateList::fromGallery(target);
... ...