Commit b721e1e0de388878d97f175ef0e4be0ffe3f0ad8

Authored by Scott Klum
1 parent 80ff6487

NEC3 refactored

sdk/core/bee.cpp
@@ -145,6 +145,7 @@ Mat readMatrix(const br::File &matrix) @@ -145,6 +145,7 @@ Mat readMatrix(const br::File &matrix)
145 // Check format 145 // Check format
146 QByteArray format = file.readLine(); 146 QByteArray format = file.readLine();
147 bool isDistance = (format[0] == 'D'); 147 bool isDistance = (format[0] == 'D');
  148 +
148 if (format[1] != '2') qFatal("bee.cpp readMatrix invalid matrix header."); 149 if (format[1] != '2') qFatal("bee.cpp readMatrix invalid matrix header.");
149 150
150 // Skip sigset lines 151 // Skip sigset lines
sdk/plugins/nec3.cpp
  1 +#include <windows.h>
1 #include <NeoFacePro.h> 2 #include <NeoFacePro.h>
2 -#include <mm_plugin.h>  
3 3
4 -#include "common/resource.h" 4 +#include <openbr_plugin.h>
  5 +#include "core/resource.h"
5 6
6 -using namespace mm; 7 +using namespace br;
7 8
8 /*! 9 /*!
9 * \ingroup initializers 10 * \ingroup initializers
10 * \brief Initialize NEC3 11 * \brief Initialize NEC3
11 * \author Josh Klontz \cite jklontz 12 * \author Josh Klontz \cite jklontz
  13 + * \author Scott Klum \cite sklum
12 * \warning Needs a maintainer 14 * \warning Needs a maintainer
13 */ 15 */
14 class NEC3Initializer : public Initializer 16 class NEC3Initializer : public Initializer
@@ -19,7 +21,7 @@ class NEC3Initializer : public Initializer @@ -19,7 +21,7 @@ class NEC3Initializer : public Initializer
19 { 21 {
20 int result = NeoFacePro::Initialize(); 22 int result = NeoFacePro::Initialize();
21 if (result != NFP_SUCCESS) qWarning("NEC3 Initialize error [%d]", result); 23 if (result != NFP_SUCCESS) qWarning("NEC3 Initialize error [%d]", result);
22 - Globals->Abbreviations.insert("NEC3", "Open+NEC3Enroll:NEC3Compare"); 24 + Globals->abbreviations.insert("NEC3", "Open!NEC3Enroll:NEC3Compare");
23 } 25 }
24 26
25 void finalize() const 27 void finalize() const
@@ -29,40 +31,27 @@ class NEC3Initializer : public Initializer @@ -29,40 +31,27 @@ class NEC3Initializer : public Initializer
29 } 31 }
30 }; 32 };
31 33
32 -MM_REGISTER(Initializer, NEC3Initializer) 34 +BR_REGISTER(Initializer, NEC3Initializer)
33 35
34 /*! 36 /*!
35 - * \brief Helper class  
36 - * \author Josh Klontz \cite jklontz  
37 - * \warning Needs a maintainer 37 + * \brief NEC3 Context
  38 + * \author Scott Klum \cite sklum
38 */ 39 */
39 -class CFaceInfoResourceMaker : public ResourceMaker<NeoFacePro::CFaceInfo>  
40 -{  
41 - NeoFacePro::CFaceInfo *make() const  
42 - {  
43 - NeoFacePro::CFaceInfo *faceInfo = new NeoFacePro::CFaceInfo();  
44 - faceInfo->SetParamAlgorithm(NFP_ALGORITHM003);  
45 - faceInfo->SetParamEyesRoll(15);  
46 - faceInfo->SetParamEyesMaxWidth(1000);  
47 - faceInfo->SetParamEyesMinWidth(30);  
48 - faceInfo->SetParamMaxFace(5);  
49 - faceInfo->SetParamReliability(0);  
50 - return faceInfo;  
51 - }  
52 -};  
53 40
54 -/*!  
55 - * \brief Helper class  
56 - * \author Josh Klontz \cite jklontz  
57 - * \warning Needs a maintainer  
58 - */  
59 -class CFaceFeatureResourceMaker : public ResourceMaker<NeoFacePro::CFaceFeature> 41 +struct NEC3Context
60 { 42 {
61 - NeoFacePro::CFaceFeature *make() const  
62 - {  
63 - NeoFacePro::CFaceFeature *faceFeature = new NeoFacePro::CFaceFeature();  
64 - faceFeature->SetParamFeatureType(NFP_FEATURE_S14);  
65 - return faceFeature; 43 + NeoFacePro::CFaceInfo faceInfo;
  44 + NeoFacePro::CFaceFeature faceFeature;
  45 +
  46 + NEC3Context() {
  47 + faceInfo.SetParamAlgorithm(NFP_ALGORITHM003);
  48 + faceInfo.SetParamEyesRoll(15);
  49 + faceInfo.SetParamEyesMaxWidth(1000);
  50 + faceInfo.SetParamEyesMinWidth(30);
  51 + faceInfo.SetParamMaxFace(1);
  52 + faceInfo.SetParamReliability(0);
  53 +
  54 + faceFeature.SetParamFeatureType(NFP_FEATURE_S14);
66 } 55 }
67 }; 56 };
68 57
@@ -70,30 +59,22 @@ class CFaceFeatureResourceMaker : public ResourceMaker&lt;NeoFacePro::CFaceFeature&gt; @@ -70,30 +59,22 @@ class CFaceFeatureResourceMaker : public ResourceMaker&lt;NeoFacePro::CFaceFeature&gt;
70 * \ingroup transforms 59 * \ingroup transforms
71 * \brief Enroll a face image in NEC NeoFace 3 60 * \brief Enroll a face image in NEC NeoFace 3
72 * \author Josh Klontz \cite jklontz 61 * \author Josh Klontz \cite jklontz
  62 + * \author Scott Klum \cite sklum
73 * \warning Needs a maintainer 63 * \warning Needs a maintainer
74 */ 64 */
75 -class NEC3Enroll : public UntrainableFeature 65 +class NEC3Enroll : public UntrainableTransform
76 { 66 {
77 Q_OBJECT 67 Q_OBJECT
78 - Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly)  
79 - MM_MEMBER(bool, detectOnly) 68 + Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly RESET reset_detectOnly STORED false)
  69 + BR_PROPERTY(bool, detectOnly, false)
80 70
81 - Resource<NeoFacePro::CFaceInfo> faceInfoResource;  
82 - Resource<NeoFacePro::CFaceFeature> faceFeatureResource;  
83 - QSharedPointer<Feature> flip;  
84 -  
85 - QString parameters() const  
86 - {  
87 - return "bool detectOnly = 0";  
88 - } 71 + Resource<NEC3Context> contexts;
  72 + QSharedPointer<Transform> flip;
89 73
90 void init() 74 void init()
91 { 75 {
92 - faceInfoResource.setResourceMaker(new CFaceInfoResourceMaker());  
93 - faceFeatureResource.setResourceMaker(new CFaceFeatureResourceMaker());  
94 - faceInfoResource.setMaxResources(1); // Only works in serial  
95 - faceFeatureResource.setMaxResources(1); // Only works in serial  
96 - flip = QSharedPointer<Feature>(Feature::make("Flip(X)")); 76 + contexts.setMaxResources(1);
  77 + flip = QSharedPointer<Transform>(Transform::make("Flip(X)"));
97 } 78 }
98 79
99 void project(const Template &src, Template &dst) const 80 void project(const Template &src, Template &dst) const
@@ -112,29 +93,29 @@ class NEC3Enroll : public UntrainableFeature @@ -112,29 +93,29 @@ class NEC3Enroll : public UntrainableFeature
112 binfo.bmiHeader.biHeight = input.rows; 93 binfo.bmiHeader.biHeight = input.rows;
113 binfo.bmiHeader.biBitCount = 24; 94 binfo.bmiHeader.biBitCount = 24;
114 95
115 - NeoFacePro::CFaceInfo *faceInfo = faceInfoResource.acquire();  
116 - int result = faceInfo->FindFace(binfo, input.data);  
117 - faceInfo->LocateEyes(); 96 + NEC3Context *context = contexts.acquire();
  97 + int result = context->faceInfo.FindFace(binfo, input.data);
  98 + context->faceInfo.LocateEyes();
  99 +
118 if (result == NFP_CANNOT_FIND_FACE) { 100 if (result == NFP_CANNOT_FIND_FACE) {
119 if (Globals->verbose) qDebug("NEC3Enroll face not found for file %s", qPrintable(src.file.flat())); 101 if (Globals->verbose) qDebug("NEC3Enroll face not found for file %s", qPrintable(src.file.flat()));
120 } else if (result != NFP_SUCCESS) { 102 } else if (result != NFP_SUCCESS) {
121 qWarning("NEC3Enroll FindFace error %d for file %s", result, qPrintable(src.file.flat())); 103 qWarning("NEC3Enroll FindFace error %d for file %s", result, qPrintable(src.file.flat()));
122 } 104 }
123 105
124 - NeoFacePro::CFaceFeature *faceFeature = faceFeatureResource.acquire();  
125 - QList<cv::Point2f> landmarks;  
126 - for (int i=0; i<faceInfo->GetFaceMax(); i++) {  
127 - if (faceInfo->SetFaceIndex(i) != NFP_SUCCESS) 106 + QList<QPointF> landmarks;
  107 + for (int i=0; i<context->faceInfo.GetFaceMax(); i++) {
  108 + if (context->faceInfo.SetFaceIndex(i) != NFP_SUCCESS)
128 continue; 109 continue;
129 - POINT right = faceInfo->GetRightEye();  
130 - POINT left = faceInfo->GetLeftEye();  
131 - landmarks.append(cv::Point2f(right.x, right.y));  
132 - landmarks.append(cv::Point2f(left.x, left.y)); 110 + POINT right = context->faceInfo.GetRightEye();
  111 + POINT left = context->faceInfo.GetLeftEye();
  112 + landmarks.append(QPointF(right.x, right.y));
  113 + landmarks.append(QPointF(left.x, left.y));
133 114
134 if (detectOnly) { 115 if (detectOnly) {
135 dst += src.m(); 116 dst += src.m();
136 } else { 117 } else {
137 - result = faceFeature->SetFeature(faceInfo); 118 + result = context->faceFeature.SetFeature(&context->faceInfo);
138 if (result != NFP_SUCCESS) { 119 if (result != NFP_SUCCESS) {
139 qWarning("NEC3Enroll SetFeature error %d for file %s", result, qPrintable(src.file.flat())); 120 qWarning("NEC3Enroll SetFeature error %d for file %s", result, qPrintable(src.file.flat()));
140 continue; 121 continue;
@@ -142,7 +123,7 @@ class NEC3Enroll : public UntrainableFeature @@ -142,7 +123,7 @@ class NEC3Enroll : public UntrainableFeature
142 123
143 void *data; 124 void *data;
144 long size; 125 long size;
145 - result = faceFeature->Serialize(&data, &size); 126 + result = context->faceFeature.Serialize(&data, &size);
146 if (result != NFP_SUCCESS) { 127 if (result != NFP_SUCCESS) {
147 qWarning("NEC3Enroll Serialize error %d for file %s", result, qPrintable(src.file.flat())); 128 qWarning("NEC3Enroll Serialize error %d for file %s", result, qPrintable(src.file.flat()));
148 continue; 129 continue;
@@ -156,22 +137,22 @@ class NEC3Enroll : public UntrainableFeature @@ -156,22 +137,22 @@ class NEC3Enroll : public UntrainableFeature
156 } 137 }
157 dst.file.appendLandmarks(landmarks); 138 dst.file.appendLandmarks(landmarks);
158 139
159 - faceInfoResource.release(faceInfo);  
160 - faceFeatureResource.release(faceFeature); 140 + contexts.release(context);
161 141
162 if (src.file.getBool("ForceEnrollment") && dst.isEmpty()) dst += cv::Mat(); 142 if (src.file.getBool("ForceEnrollment") && dst.isEmpty()) dst += cv::Mat();
163 } 143 }
164 }; 144 };
165 145
166 -MM_REGISTER(Feature, NEC3Enroll) 146 +BR_REGISTER(Transform, NEC3Enroll)
167 147
168 /*! 148 /*!
169 * \ingroup distances 149 * \ingroup distances
170 * \brief Compare faces with NEC NeoFace 3 SDK 150 * \brief Compare faces with NEC NeoFace 3 SDK
171 * \author Josh Klontz \cite jklontz 151 * \author Josh Klontz \cite jklontz
  152 + * \author Scott Klum \cite sklum
172 * \warning Needs a maintainer 153 * \warning Needs a maintainer
173 */ 154 */
174 -class NEC3Compare : public BasicComparer 155 +class NEC3Compare : public Distance
175 { 156 {
176 Q_OBJECT 157 Q_OBJECT
177 158
@@ -190,6 +171,6 @@ class NEC3Compare : public BasicComparer @@ -190,6 +171,6 @@ class NEC3Compare : public BasicComparer
190 } 171 }
191 }; 172 };
192 173
193 -MM_REGISTER(Comparer, NEC3Compare) 174 +BR_REGISTER(Distance, NEC3Compare)
194 175
195 #include "nec3.moc" 176 #include "nec3.moc"