Commit 6349b9cf49b5131b060c860eeb657aa01072d564

Authored by Josh Klontz
1 parent b2d2cf68

removed NEC wrappers

openbr/plugins/nec3.cmake deleted
1 -set(BR_WITH_NEC3 OFF CACHE BOOL "Build with NEC NeoFaceSDK 3")  
2 -  
3 -if(${BR_WITH_NEC3})  
4 - find_package(NEC3 REQUIRED)  
5 - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/nec3.cpp)  
6 - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${NEC3_LIBS})  
7 -endif()  
openbr/plugins/nec3.cpp deleted
1 -#ifdef WIN32  
2 -#include <windows.h>  
3 -#endif  
4 -  
5 -#include <NeoFacePro.h>  
6 -  
7 -#include "openbr_internal.h"  
8 -#include "openbr/core/resource.h"  
9 -  
10 -using namespace br;  
11 -  
12 -/*!  
13 - * \ingroup initializers  
14 - * \brief Initialize NEC3  
15 - * \author Josh Klontz \cite jklontz  
16 - * \author Scott Klum \cite sklum  
17 - * \warning Needs a maintainer  
18 - */  
19 -class NEC3Initializer : public Initializer  
20 -{  
21 - Q_OBJECT  
22 -  
23 - void initialize() const  
24 - {  
25 - int result = NeoFacePro::Initialize();  
26 - if (result != NFP_SUCCESS) qWarning("NEC3 Initialize error [%d]", result);  
27 - Globals->abbreviations.insert("NEC3", "Open!NEC3Enroll:NEC3Compare");  
28 - }  
29 -  
30 - void finalize() const  
31 - {  
32 - int result = NeoFacePro::Terminate();  
33 - if (result != NFP_SUCCESS) qWarning("NEC3 Finalize error [%d]", result);  
34 - }  
35 -};  
36 -  
37 -BR_REGISTER(Initializer, NEC3Initializer)  
38 -  
39 -/*!  
40 - * \brief NEC3 Context  
41 - * \author Scott Klum \cite sklum  
42 - */  
43 -  
44 -struct NEC3Context  
45 -{  
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);  
58 - }  
59 -};  
60 -  
61 -/*!  
62 - * \ingroup transforms  
63 - * \brief Enroll a face image in NEC NeoFace 3  
64 - * \author Josh Klontz \cite jklontz  
65 - * \author Scott Klum \cite sklum  
66 - * \warning Needs a maintainer  
67 - */  
68 -class NEC3Enroll : public UntrainableTransform  
69 -{  
70 - Q_OBJECT  
71 - Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly RESET reset_detectOnly STORED false)  
72 - BR_PROPERTY(bool, detectOnly, false)  
73 -  
74 - Resource<NEC3Context> contexts;  
75 - QSharedPointer<Transform> flip;  
76 -  
77 - void init()  
78 - {  
79 - contexts.setMaxResources(1);  
80 - flip = QSharedPointer<Transform>(Transform::make("Flip(X)"));  
81 - }  
82 -  
83 - void project(const Template &src, Template &dst) const  
84 - {  
85 - if (src.m().type() != CV_8UC3) qFatal("NEC3Enroll requires 8UC3 images.");  
86 -  
87 - // Bitmaps are stored upside down  
88 - Template flipped;  
89 - flip->project(src, flipped);  
90 -  
91 - cv::Mat input = flipped.m();  
92 - input = input(cv::Rect(0, 0, (input.cols/4)*4, (input.rows/4)*4)).clone(); // For whatever reason, NEC requires images with 4 pixel alignment...  
93 -  
94 - BITMAPINFO binfo;  
95 - binfo.bmiHeader.biWidth = input.cols;  
96 - binfo.bmiHeader.biHeight = input.rows;  
97 - binfo.bmiHeader.biBitCount = 24;  
98 -  
99 - NEC3Context *context = contexts.acquire();  
100 - int result = context->faceInfo.FindFace(binfo, input.data);  
101 - context->faceInfo.LocateEyes();  
102 -  
103 - if (result == NFP_CANNOT_FIND_FACE) {  
104 - if (Globals->verbose) qDebug("NEC3Enroll face not found for file %s", qPrintable(src.file.flat()));  
105 - } else if (result != NFP_SUCCESS) {  
106 - qWarning("NEC3Enroll FindFace error %d for file %s", result, qPrintable(src.file.flat()));  
107 - }  
108 -  
109 - QList<QPointF> landmarks;  
110 - for (int i=0; i<context->faceInfo.GetFaceMax(); i++) {  
111 - if (context->faceInfo.SetFaceIndex(i) != NFP_SUCCESS)  
112 - continue;  
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));  
117 -  
118 - if (detectOnly) {  
119 - dst += src.m();  
120 - } else {  
121 - result = context->faceFeature.SetFeature(&context->faceInfo);  
122 - if (result != NFP_SUCCESS) {  
123 - qWarning("NEC3Enroll SetFeature error %d for file %s", result, qPrintable(src.file.flat()));  
124 - continue;  
125 - }  
126 -  
127 - void *data;  
128 - long size;  
129 - result = context->faceFeature.Serialize(&data, &size);  
130 - if (result != NFP_SUCCESS) {  
131 - qWarning("NEC3Enroll Serialize error %d for file %s", result, qPrintable(src.file.flat()));  
132 - continue;  
133 - }  
134 -  
135 - dst += cv::Mat(1, size, CV_8UC1, data).clone();  
136 - NeoFacePro::CFaceFeature::FreeSerializeData(data);  
137 - }  
138 -  
139 - if (src.file.get<bool>("ForceEnrollment", false) && !dst.isEmpty()) break;  
140 - }  
141 - dst.file.appendPoints(landmarks);  
142 -  
143 - contexts.release(context);  
144 -  
145 - if (!src.file.get<bool>("enrollAll", false) && dst.isEmpty()) dst += cv::Mat();  
146 - }  
147 -};  
148 -  
149 -BR_REGISTER(Transform, NEC3Enroll)  
150 -  
151 -/*!  
152 - * \ingroup distances  
153 - * \brief Compare faces with NEC NeoFace 3 SDK  
154 - * \author Josh Klontz \cite jklontz  
155 - * \author Scott Klum \cite sklum  
156 - * \warning Needs a maintainer  
157 - */  
158 -class NEC3Compare : public Distance  
159 -{  
160 - Q_OBJECT  
161 -  
162 - Resource<NeoFacePro::CVerifier> verifierResource;  
163 -  
164 - float compare(const Template &a, const Template &b) const  
165 - {  
166 - float score = -std::numeric_limits<float>::max();  
167 - if (a.m().data && b.m().data) {  
168 - NeoFacePro::CVerifier *verifier = verifierResource.acquire();  
169 - int result = verifier->Verify(a.m().data, b.m().data, &score);  
170 - if (result != NFP_SUCCESS) qWarning("NEC3Compare verify error [%d]", result);  
171 - verifierResource.release(verifier);  
172 - }  
173 - return score;  
174 - }  
175 -};  
176 -  
177 -BR_REGISTER(Distance, NEC3Compare)  
178 -  
179 -#include "nec3.moc"  
openbr/plugins/neclatent1.cmake deleted
1 -set(BR_WITH_NECLATENT1 OFF CACHE BOOL "Build with NEC Latent SDK 1")  
2 -  
3 -if(${BR_WITH_NECLATENT1})  
4 - find_package(NECLATENT1 REQUIRED)  
5 - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/neclatent1.cpp)  
6 - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${NECLATENT1_LIBS})  
7 - install(DIRECTORY ${NECLATENT1_BIN_DIR}/ DESTINATION bin)  
8 -endif()  
openbr/plugins/neclatent1.cpp deleted
1 -#include <LatentEFS.h>  
2 -  
3 -#include "openbr_internal.h"  
4 -  
5 -// Necessary to allocate a large memory though the actual template size may be much smaller  
6 -#define MAX_TEMPLATE_SIZE 400000  
7 -  
8 -namespace br  
9 -{  
10 -  
11 -/*!  
12 - * \ingroup initializers  
13 - * \brief Initialize the NEC Latent SDK wrapper.  
14 - * \author Josh Klontz \cite jklontz  
15 - */  
16 -class NECLatent1Initialier : public Initializer  
17 -{  
18 - Q_OBJECT  
19 -  
20 - void initialize() const  
21 - {  
22 - Globals->abbreviations.insert("NECTenprintLFML", "Open+Cvt(Gray)+NECLatent1Enroll(false,LFML):NECLatent1Compare(LFML)");  
23 - Globals->abbreviations.insert("NECTenprintELFT", "Open+Cvt(Gray)+NECLatent1Enroll(false,ELFT):NECLatent1Compare(ELFT)");  
24 - Globals->abbreviations.insert("NECTenprintELFTM", "Open+Cvt(Gray)+NECLatent1Enroll(false,ELFT_M):NECLatent1Compare(ELFT_M)");  
25 - Globals->abbreviations.insert("NECLatentLFML", "Open+Cvt(Gray)+NECLatent1Enroll(true,LFML):NECLatent1Compare(LFML)");  
26 - Globals->abbreviations.insert("NECLatentELFT", "Open+Cvt(Gray)+NECLatent1Enroll(true,ELFT):NECLatent1Compare(ELFT)");  
27 - Globals->abbreviations.insert("NECLatentELFTM", "Open+NECLatent1Enroll(true,ELFT_M):NECLatent1Compare(ELFT_M)");  
28 - }  
29 -};  
30 -  
31 -BR_REGISTER(Initializer, NECLatent1Initialier)  
32 -  
33 -/*!  
34 - * \ingroup transforms  
35 - * \brief Enroll an NEC latent fingerprint.  
36 - * \author Josh Klontz \cite jklontz  
37 - * \warning Applications using this transform must have their working directory be the 'bin/win/32' folder of the NEC Latent SDK.  
38 - */  
39 -class NECLatent1EnrollTransform : public UntrainableTransform  
40 -{  
41 - Q_OBJECT  
42 - Q_ENUMS(Algorithm)  
43 - Q_PROPERTY(bool latent READ get_latent WRITE set_latent RESET reset_latent STORED false)  
44 - Q_PROPERTY(Algorithm algorithm READ get_algorithm WRITE set_algorithm RESET reset_algorithm STORED false)  
45 -  
46 -public:  
47 - enum Algorithm { LFML,  
48 - ELFT,  
49 - ELFT_M };  
50 -  
51 -private:  
52 - BR_PROPERTY(bool, latent, false)  
53 - BR_PROPERTY(Algorithm, algorithm, LFML)  
54 -  
55 - void project(const Template &src, Template &dst) const  
56 - {  
57 - static QMutex mutex;  
58 - QMutexLocker locker(&mutex); // It seems that most of the API is not reentrant  
59 -  
60 - if (src.m().type() != CV_8UC1) qFatal("Requires 8UC1 data!");  
61 - uchar *data = src.m().data;  
62 - const int rows = src.m().rows;  
63 - const int columns = src.m().cols;  
64 -  
65 - uchar buff[MAX_TEMPLATE_SIZE];  
66 - uchar* pBuff = NULL;  
67 - int size, error;  
68 - if (latent) {  
69 - if (algorithm == LFML) error = NEC_LFML_ExtractLatent(data, rows, columns, 500, buff, &size);  
70 - else if (algorithm == ELFT) error = NEC_ELFT_ExtractLatent(data, rows, columns, 500, 32, buff, &size);  
71 - else error = NEC_ELFT_M_ExtractLatent(data, columns, 5, &pBuff, &size);  
72 - } else {  
73 - if (algorithm == LFML) error = NEC_LFML_ExtractTenprint(data, rows, columns, 500, buff, &size);  
74 - else if (algorithm == ELFT) error = NEC_ELFT_ExtractTenprint(data, rows, columns, 500, 8, buff, &size);  
75 - else error = NEC_ELFT_M_ExtractTenprint(data, rows, columns, 500, 5, &pBuff, &size);  
76 - }  
77 -  
78 - if (!error) {  
79 - cv::Mat n(1, size, CV_8UC1);  
80 - memcpy(n.data, pBuff ? pBuff : buff, size);  
81 - dst.m() = n;  
82 - } else {  
83 - qWarning("NECLatent1EnrollTransform error %d for file %s.", error, qPrintable(src.file.flat()));  
84 - dst.m() = cv::Mat();  
85 - dst.file.set("FTE", true);  
86 - }  
87 -  
88 - if (pBuff != NULL) NEC_ELFT_M_FreeTemplate(&pBuff);  
89 - }  
90 -};  
91 -  
92 -BR_REGISTER(Transform, NECLatent1EnrollTransform)  
93 -  
94 -/*!  
95 - * \ingroup distances  
96 - * \brief Compare two NEC latent fingerprints  
97 - * \author Josh Klontz \cite jklontz  
98 - */  
99 -class NECLatent1CompareDistance : public Distance  
100 -{  
101 - Q_OBJECT  
102 - Q_ENUMS(Algorithm)  
103 - Q_PROPERTY(Algorithm algorithm READ get_algorithm WRITE set_algorithm RESET reset_algorithm STORED false)  
104 -  
105 -public:  
106 - enum Algorithm { LFML,  
107 - ELFT,  
108 - ELFT_M };  
109 -  
110 -private:  
111 - BR_PROPERTY(Algorithm, algorithm, LFML)  
112 -  
113 - float compare(const Template &a, const Template &b) const  
114 - {  
115 - uchar *aData = a.m().data;  
116 - uchar *bData = b.m().data;  
117 - if (!a.m().data || !b.m().data) return -std::numeric_limits<float>::max();  
118 - int score, error;  
119 - if (algorithm == LFML) error = NEC_LFML_Verify(bData, b.m().total(), aData, a.m().total(), &score);  
120 - else if (algorithm == ELFT) error = NEC_ELFT_Verify(bData, aData, &score, 1);  
121 - else error = NEC_ELFT_M_Verify(bData, aData, &score, 1);  
122 - if (error)  
123 - qWarning("NECLatent1CompareDistance error %d", error);  
124 - return score;  
125 - }  
126 -};  
127 -  
128 -BR_REGISTER(Distance, NECLatent1CompareDistance)  
129 -  
130 -} // namespace br  
131 -  
132 -#include "neclatent1.moc"  
share/openbr/cmake/FindNEC3.cmake deleted
1 -find_path(NEC3_DIR Include/NeoFacePro.h ${CMAKE_SOURCE_DIR}/3rdparty/*)  
2 -  
3 -include_directories(${NEC3_DIR}/Include)  
4 -link_directories(${NEC3_DIR}/Lib)  
5 -  
6 -set(NEC3_LIBS NeoFacePro)  
share/openbr/cmake/FindNECLatent1.cmake deleted
1 -find_path(NECLATENT1_DIR include/LatentEFS.h ${CMAKE_SOURCE_DIR}/3rdparty/*)  
2 -  
3 -set(NECLATENT1_SUBDIR /win/${BITNESS})  
4 -set(NECLATENT1_LIB_DIR ${NECLATENT1_DIR}/lib${NECLATENT1_SUBDIR})  
5 -set(NECLATENT1_BIN_DIR ${NECLATENT1_DIR}/bin${NECLATENT1_SUBDIR})  
6 -  
7 -include_directories(${NECLATENT1_DIR}/include)  
8 -link_directories(${NECLATENT1_LIB_DIR})  
9 -  
10 -if(MSVC)  
11 - file(GLOB NECLATENT1_LIBS ${NECLATENT1_LIB_DIR}/*.lib)  
12 -else()  
13 - file(GLOB NECLATENT1_LIBS ${NECLATENT1_BIN_DIR}/*.dll)  
14 -endif()