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