Commit 846a0fa84c0f9aa1817c4723325a0e3f5ebacedb

Authored by Ben Klein
2 parents 5bd7cd9a 30cc0403

Merge pull request #277 from biometrics/janusCreateTemplates

Janus create templates
Showing 1 changed file with 28 additions and 0 deletions
openbr/janus_io.cpp
... ... @@ -2,6 +2,7 @@
2 2  
3 3 #define JANUS_CUSTOM_ADD_SAMPLE
4 4 #define JANUS_CUSTOM_CREATE_GALLERY
  5 +#define JANUS_CUSTOM_CREATE_TEMPLATES
5 6 #include "janus/src/janus_io.cpp"
6 7  
7 8 static void _janus_add_sample(vector<double> &samples, double sample)
... ... @@ -35,3 +36,30 @@ janus_error janus_create_gallery(const char *data_path, janus_metadata metadata,
35 36 futures.waitForFinished();
36 37 return JANUS_SUCCESS;
37 38 }
  39 +
  40 +janus_error janus_create_templates(const char *data_path, janus_metadata metadata, const char *gallery_file, int verbose)
  41 +{
  42 + TemplateIterator ti(metadata, true);
  43 + TemplateData templateData = ti.next();
  44 + unsigned int num_templates = 1;
  45 +
  46 + janus_gallery gallery;
  47 + JANUS_ASSERT(janus_allocate_gallery(&gallery))
  48 + QFutureSynchronizer<void> futures;
  49 + while (!templateData.templateIDs.empty()) {
  50 + futures.addFuture(QtConcurrent::run(_janus_create_template, data_path, templateData, gallery, verbose));
  51 + templateData = ti.next();
  52 + num_templates++;
  53 + }
  54 + futures.waitForFinished();
  55 + janus_flat_gallery flat_gallery = new janus_data[num_templates*janus_max_template_size()];
  56 + size_t bytes;
  57 + JANUS_ASSERT(janus_flatten_gallery(gallery, flat_gallery, &bytes))
  58 +
  59 + std::ofstream file;
  60 + file.open(gallery_file, std::ios::out | std::ios::binary);
  61 + file.write((char*)flat_gallery, bytes);
  62 + file.close();
  63 + delete[] flat_gallery;
  64 + return JANUS_SUCCESS;
  65 +}
... ...