Commit b48eeb8b38de79dd78e0b100cdf1efb7338e3e9b

Authored by Josh Klontz
1 parent 6afe15b5

improved neclatent1 wrapper

Showing 1 changed file with 25 additions and 12 deletions
openbr/plugins/neclatent1.cpp
1 1 #include <openbr/openbr_plugin.h>
2 2 #include <LatentEFS.h>
3 3  
4   -// necessary to allocate a large memory though the actual template size
5   -// may be much smaller
  4 +// Necessary to allocate a large memory though the actual template size may be much smaller
6 5 #define MAX_TEMPLATE_SIZE 400000
7 6  
8 7 namespace br
... ... @@ -21,6 +20,7 @@ class NECLatent1Initialier : public Initializer
21 20 {
22 21 Globals->abbreviations.insert("NECTenprint1", "Open+Cvt(Gray)+NECLatent1Enroll:NECLatent1Compare");
23 22 Globals->abbreviations.insert("NECLatent1", "Open+Cvt(Gray)+NECLatent1Enroll(true):NECLatent1Compare");
  23 + Globals->abbreviations.insert("NECLatentLFFS1", "Open+NECLatent1Enroll(true,ELFT_M):NECLatent1Compare(ELFT_M)");
24 24 }
25 25 };
26 26  
... ... @@ -41,7 +41,8 @@ class NECLatent1EnrollTransform : public UntrainableTransform
41 41  
42 42 public:
43 43 enum Algorithm { LFML,
44   - ELFT };
  44 + ELFT,
  45 + ELFT_M };
45 46  
46 47 private:
47 48 BR_PROPERTY(bool, latent, false)
... ... @@ -50,27 +51,35 @@ private:
50 51 void project(const Template &src, Template &dst) const
51 52 {
52 53 if (src.m().type() != CV_8UC1) qFatal("Requires 8UC1 data!");
53   - unsigned char data[MAX_TEMPLATE_SIZE];
  54 + uchar *data = src.m().data;
  55 + const int rows = src.m().rows;
  56 + const int columns = src.m().cols;
  57 + uchar buff[MAX_TEMPLATE_SIZE];
  58 + uchar* pBuff = NULL;
54 59 int size = 0;
55 60 int error;
56 61  
57 62 if (latent) {
58   - if (algorithm == LFML) error = NEC_LFML_ExtractLatent(src.m().data, src.m().rows, src.m().cols, 500, data, &size);
59   - else error = NEC_ELFT_ExtractLatent(src.m().data, src.m().rows, src.m().cols, 500, 4, data, &size);
  63 + if (algorithm == LFML) error = NEC_LFML_ExtractLatent(data, rows, columns, 500, buff, &size);
  64 + else if (algorithm == ELFT) error = NEC_ELFT_ExtractLatent(data, rows, columns, 500, 4, buff, &size);
  65 + else error = NEC_ELFT_M_ExtractLatent(data, columns, 1, &pBuff, &size);
60 66 } else {
61   - if (algorithm == LFML) error = NEC_LFML_ExtractTenprint(src.m().data, src.m().rows, src.m().cols, 500, data, &size);
62   - else error = NEC_ELFT_ExtractTenprint(src.m().data, src.m().rows, src.m().cols, 500, 2, data, &size);
  67 + if (algorithm == LFML) error = NEC_LFML_ExtractTenprint(data, rows, columns, 500, buff, &size);
  68 + else if (algorithm == ELFT) error = NEC_ELFT_ExtractTenprint(data, rows, columns, 500, 2, buff, &size);
  69 + else qFatal("ELFT_M Tenprint not implemented.");
63 70 }
64 71  
65 72 if (!error) {
66 73 cv::Mat n(1, size, CV_8UC1);
67   - memcpy(n.data, data, size);
  74 + memcpy(n.data, buff, size);
68 75 dst.m() = n;
69 76 } else {
70 77 qWarning("NECLatent1EnrollTransform error %d for file %s.", error, qPrintable(src.file.flat()));
71 78 dst.m() = cv::Mat();
72 79 dst.file.set("FTE", true);
73 80 }
  81 +
  82 + if (pBuff != NULL) NEC_ELFT_M_FreeTemplate(&pBuff);
74 83 }
75 84 };
76 85  
... ... @@ -89,17 +98,21 @@ class NECLatent1CompareDistance : public Distance
89 98  
90 99 public:
91 100 enum Algorithm { LFML,
92   - ELFT };
  101 + ELFT,
  102 + ELFT_M };
93 103  
94 104 private:
95 105 BR_PROPERTY(Algorithm, algorithm, LFML)
96 106  
97 107 float compare(const Template &a, const Template &b) const
98 108 {
  109 + uchar *aData = a.m().data;
  110 + uchar *bData = b.m().data;
99 111 if (!a.m().data || !b.m().data) return -std::numeric_limits<float>::max();
100 112 int score;
101   - if (algorithm == LFML) NEC_LFML_Verify(b.m().data, b.m().total(), a.m().data, a.m().total(), &score);
102   - else NEC_ELFT_Verify(b.m().data, a.m().data, &score, 2);
  113 + if (algorithm == LFML) NEC_LFML_Verify(bData, b.m().total(), aData, a.m().total(), &score);
  114 + else if (algorithm == ELFT) NEC_ELFT_Verify(bData, aData, &score, 1);
  115 + else NEC_ELFT_M_Verify(bData, aData, &score, 1);
103 116 return score;
104 117 }
105 118 };
... ...