Commit 780b1296dd7b543b9149925f020cb71302ab4875

Authored by Josh Klontz
1 parent 0cbf7f6a

removed janus

.gitmodules
1   -[submodule "openbr/janus"]
2   - path = openbr/janus
3   - url = https://github.com/biometrics/janus.git
4 1 [submodule "3rdparty/qhttpserver"]
5 2 path = 3rdparty/qhttpserver
6 3 url = https://github.com/nikhilm/qhttpserver.git
... ...
openbr/CMakeLists.txt
... ... @@ -9,17 +9,6 @@ set(SRC openbr.cpp
9 9 aux_source_directory(core BR_CORE)
10 10 include(plugins/plugins.cmake)
11 11  
12   -# Janus API
13   -option(BR_WITH_JANUS "Build IARPA Janus related applications." ON)
14   -if(BR_WITH_JANUS)
15   - include_directories(janus/include)
16   - install(DIRECTORY janus/include DESTINATION .)
17   - set(BR_JANUS janus.cpp
18   - janus_io.cpp
19   - janus/src/opencv_io/opencv_io.cpp)
20   - add_definitions(-DJANUS_LIBRARY)
21   -endif()
22   -
23 12 # Optional GUI module
24 13 if(NOT BR_EMBEDDED)
25 14 aux_source_directory(gui BR_GUI)
... ... @@ -46,16 +35,6 @@ if(BR_WITH_DLIB)
46 35 add_dependencies(openbr dlib)
47 36 endif()
48 37  
49   -# Janus implementation
50   -if(BR_WITH_JANUS)
51   - set(JANUS_BUILD_PP5_WRAPPER ${BR_WITH_PP5} CACHE BOOL "Build Janus implementation using PittPatt 5")
52   - set(JANUS_BUILD_DOCS ${BR_BUILD_DOCUMENTATION} CACHE BOOL "Build Janus HTML Doxygen documentation")
53   - mark_as_advanced(JANUS_BUILD_PP5_WRAPPER)
54   - mark_as_advanced(JANUS_BUILD_DOCS)
55   - set(JANUS_IMPLEMENTATION openbr)
56   - add_subdirectory(janus)
57   -endif()
58   -
59 38 # Install
60 39 install(TARGETS openbr
61 40 RUNTIME DESTINATION bin
... ...
openbr/janus deleted
1   -Subproject commit bab25ea9b9f26791859415abe953f6df82ace86e
openbr/janus.cpp deleted
1   -#include "iarpa_janus.h"
2   -#include "iarpa_janus_io.h"
3   -#include "openbr_plugin.h"
4   -#include "openbr/core/opencvutils.h"
5   -#include "openbr/core/common.h"
6   -#include <fstream>
7   -using namespace br;
8   -
9   -static QSharedPointer<Transform> detect;
10   -static QSharedPointer<Transform> augment;
11   -static QSharedPointer<Distance> distance;
12   -
13   -size_t janus_max_template_size()
14   -{
15   - return 102400;// 100 KB
16   -}
17   -
18   -janus_error janus_initialize(const char *sdk_path, const char *temp_path, const char *model_file)
19   -{
20   - int argc = 1;
21   - const char *argv[1] = { "janus" };
22   - Context::initialize(argc, (char**)argv, sdk_path, false);
23   - Globals->quiet = true;
24   - Globals->enrollAll = true;
25   - Globals->file.set(QString("temp_path"), QString(temp_path));
26   - const QString algorithm = model_file;
27   - detect.reset(Transform::make("Cvt(Gray)+Cascade(FrontalFace,ROCMode=true)", NULL));
28   - if (algorithm.isEmpty()) {
29   - augment.reset(Transform::make("Cvt(Gray)+Affine(88,88,0.25,0.35)+<FaceRecognitionExtraction>+<FaceRecognitionEmbedding>+<FaceRecognitionQuantization>", NULL));
30   - distance = Distance::fromAlgorithm("FaceRecognition");
31   - } else {
32   - augment = Transform::fromAlgorithm(algorithm);
33   - distance = Distance::fromAlgorithm(algorithm);
34   - }
35   - return JANUS_SUCCESS;
36   -}
37   -
38   -janus_error janus_finalize()
39   -{
40   - detect.reset();
41   - augment.reset();
42   - distance.reset();
43   - Context::finalize();
44   - return JANUS_SUCCESS;
45   -}
46   -
47   -struct janus_template_type : public Template
48   -{};
49   -
50   -janus_error janus_allocate_template(janus_template *template_)
51   -{
52   - *template_ = new janus_template_type();
53   - return JANUS_SUCCESS;
54   -}
55   -
56   -bool compareConfidence(Template a, Template b) { return (a.file.get<float>("Confidence") > b.file.get<float>("Confidence")); }
57   -
58   -janus_error janus_detect(const janus_image image, janus_attributes *attributes_array, const size_t num_requested, size_t *num_actual)
59   -{
60   - TemplateList src, dst;
61   -
62   - Template t;
63   - cv::Mat input(image.height,
64   - image.width,
65   - image.color_space == JANUS_GRAY8 ? CV_8UC1 : CV_8UC3,
66   - image.data);
67   -
68   - t.append(input);
69   - src.append(t);
70   - detect->project(src, dst);
71   - *num_actual = dst.size();
72   - if (dst.size() == 0)
73   - return JANUS_FAILURE_TO_DETECT;
74   -
75   - // Sort by confidence, descending
76   - std::sort(dst.begin(), dst.end(), compareConfidence);
77   -
78   - size_t count = 0;
79   - foreach (const Template &temp, dst) {
80   - QRectF rect = temp.file.rects().first();
81   - attributes_array->face_x = rect.x();
82   - attributes_array->face_y = rect.y();
83   - attributes_array->face_width = rect.width();
84   - attributes_array->face_height = rect.height();
85   - attributes_array->detection_confidence = temp.file.get<float>("Confidence");
86   - attributes_array++;
87   - if (++count >= num_requested)
88   - break;
89   - }
90   - attributes_array -= count;
91   - return JANUS_SUCCESS;
92   -}
93   -
94   -janus_error janus_augment(const janus_image image, janus_attributes *attributes, janus_template template_)
95   -{
96   - Template t;
97   - if (std::isnan(attributes->face_x) ||
98   - std::isnan(attributes->face_y) ||
99   - std::isnan(attributes->face_width) ||
100   - std::isnan(attributes->face_height))
101   - return JANUS_MISSING_ATTRIBUTES;
102   -
103   - QRectF rect(attributes->face_x,
104   - attributes->face_y,
105   - attributes->face_width,
106   - attributes->face_height);
107   -
108   - if (rect.x() < 0) rect.setX(0);
109   - if (rect.y() < 0) rect.setY(0);
110   - if (rect.x() + rect.width() > image.width) rect.setWidth(image.width - rect.x());
111   - if (rect.y() + rect.height() > image.height) rect.setHeight(image.height - rect.y());
112   -
113   - cv::Mat input(image.height,
114   - image.width,
115   - image.color_space == JANUS_GRAY8 ? CV_8UC1 : CV_8UC3,
116   - image.data);
117   -
118   - input = input(cv::Rect(rect.x(), rect.y(), rect.width(), rect.height())).clone();
119   - t.append(input);
120   - if (!std::isnan(attributes->right_eye_x) &&
121   - !std::isnan(attributes->right_eye_y) &&
122   - !std::isnan(attributes->left_eye_x) &&
123   - !std::isnan(attributes->left_eye_y)) {
124   - t.file.set("Affine_0", QPointF(attributes->right_eye_x - rect.x(), attributes->right_eye_y - rect.y()));
125   - t.file.set("Affine_1", QPointF(attributes->left_eye_x - rect.x(), attributes->left_eye_y - rect.y()));
126   - t.file.set("First_Eye", t.file.get<QPointF>("Affine_0"));
127   - t.file.set("Second_Eye", t.file.get<QPointF>("Affine_1"));
128   - t.file.appendPoint(t.file.get<QPointF>("Affine_0"));
129   - t.file.appendPoint(t.file.get<QPointF>("Affine_1"));
130   - }
131   - Template u;
132   - augment->project(t, u);
133   - if (u.file.fte) u.m() = cv::Mat();
134   - template_->append(u);
135   - return (u.isEmpty() || !u.first().data) ? JANUS_FAILURE_TO_ENROLL : JANUS_SUCCESS;
136   -}
137   -
138   -janus_error janus_flatten_template(janus_template template_, janus_flat_template flat_template, size_t *bytes)
139   -{
140   - *bytes = 0;
141   - foreach (const cv::Mat &m, *template_) {
142   - if (!m.data)
143   - continue;
144   -
145   - if (!m.isContinuous())
146   - return JANUS_UNKNOWN_ERROR;
147   -
148   - const size_t templateBytes = m.rows * m.cols * m.elemSize();
149   - if (*bytes + sizeof(size_t) + templateBytes > janus_max_template_size())
150   - break;
151   -
152   - memcpy(flat_template, &templateBytes, sizeof(templateBytes));
153   - flat_template += sizeof(templateBytes);
154   - *bytes += sizeof(templateBytes);
155   -
156   - memcpy(flat_template, m.data, templateBytes);
157   - flat_template += templateBytes;
158   - *bytes += templateBytes;
159   - }
160   - return JANUS_SUCCESS;
161   -}
162   -
163   -janus_error janus_free_template(janus_template template_)
164   -{
165   - delete template_;
166   - return JANUS_SUCCESS;
167   -}
168   -
169   -struct janus_gallery_type : public QList<janus_template>
170   -{};
171   -
172   -void unflatten_template(const janus_flat_template flat_template, const size_t template_bytes, janus_gallery gallery, const janus_template_id template_id)
173   -{
174   - janus_template t;
175   - JANUS_ASSERT(janus_allocate_template(&t))
176   - t->file.set("TEMPLATE_ID", QString::number((int)template_id));
177   - janus_flat_template flat_template_ = flat_template;
178   -
179   - while (flat_template_ < flat_template + template_bytes) {
180   - size_t bytes = *reinterpret_cast<size_t*>(flat_template_);
181   - flat_template_ += sizeof(bytes);
182   -
183   - t->append(cv::Mat(1, bytes, CV_8UC1, flat_template_).clone());
184   - flat_template_ += bytes;
185   - }
186   - gallery->append(t);
187   -}
188   -
189   -janus_error janus_write_gallery(const janus_flat_template *templates, const size_t *templates_bytes, const janus_template_id *template_ids, const size_t num_templates, janus_gallery_path gallery_path)
190   -{
191   - std::ofstream file;
192   - file.open(gallery_path, std::ios::out | std::ios::binary);
193   -
194   - for (size_t i=0; i<num_templates; i++) {
195   - file.write((char*)&template_ids[i], sizeof(janus_template_id));
196   - file.write((char*)&templates_bytes[i], sizeof(size_t));
197   - file.write((char*)templates[i], templates_bytes[i]);
198   - }
199   -
200   - file.close();
201   - return JANUS_SUCCESS;
202   -}
203   -
204   -janus_error janus_open_gallery(janus_gallery_path gallery_path, janus_gallery *gallery)
205   -{
206   - *gallery = new janus_gallery_type();
207   - std::ifstream file;
208   - file.open(gallery_path, std::ios::in | std::ios::binary | std::ios::ate);
209   - const size_t bytes = file.tellg();
210   - file.seekg(0, std::ios::beg);
211   - janus_data *templates = new janus_data[bytes];
212   - file.read((char*)templates, bytes);
213   - file.close();
214   -
215   - janus_data *templates_ = templates;
216   - while (templates_ < templates + bytes) {
217   - janus_template_id template_id = *reinterpret_cast<janus_template_id*>(templates_);
218   - templates_ += sizeof(janus_template_id);
219   - const size_t template_bytes = *reinterpret_cast<size_t*>(templates_);
220   - templates_ += sizeof(size_t);
221   -
222   - janus_flat_template flat_template = new janus_data[template_bytes];
223   - memcpy(flat_template, templates_, template_bytes);
224   - templates_ += template_bytes;
225   -
226   - unflatten_template(flat_template, template_bytes, *gallery, template_id);
227   - delete[] flat_template;
228   - }
229   -
230   - delete[] templates;
231   - return JANUS_SUCCESS;
232   -}
233   -
234   -janus_error janus_close_gallery(janus_gallery gallery)
235   -{
236   - delete gallery;
237   - return JANUS_SUCCESS;
238   -}
239   -
240   -janus_error janus_verify(const janus_flat_template a, const size_t a_bytes, const janus_flat_template b, const size_t b_bytes, float *similarity)
241   -{
242   - *similarity = 0;
243   -
244   - int comparisons = 0;
245   - janus_flat_template a_template = a;
246   - while (a_template < a + a_bytes) {
247   - const size_t a_template_bytes = *reinterpret_cast<size_t*>(a_template);
248   - a_template += sizeof(a_template_bytes);
249   - janus_flat_template b_template = b;
250   - while (b_template < b + b_bytes) {
251   - const size_t b_template_bytes = *reinterpret_cast<size_t*>(b_template);
252   - b_template += sizeof(b_template_bytes);
253   - *similarity += distance->compare(cv::Mat(1, a_template_bytes, CV_8UC1, a_template),
254   - cv::Mat(1, b_template_bytes, CV_8UC1, b_template));
255   - comparisons++;
256   -
257   - b_template += b_template_bytes;
258   - }
259   -
260   - a_template += a_template_bytes;
261   - }
262   -
263   - if (*similarity != *similarity) // True for NaN
264   - return JANUS_UNKNOWN_ERROR;
265   -
266   - if (comparisons > 0) *similarity /= comparisons;
267   - else *similarity = -std::numeric_limits<float>::max();
268   - return JANUS_SUCCESS;
269   -}
270   -
271   -janus_error janus_search(const janus_flat_template probe, const size_t probe_bytes, const janus_gallery gallery, const size_t requested_returns, janus_template_id *template_ids, float *similarities, size_t *actual_returns)
272   -{
273   - typedef QPair<float, int> Pair;
274   - QList<Pair> comparisons; comparisons.reserve(requested_returns);
275   - foreach (const janus_template &target_template, *gallery) {
276   - janus_template_id target_id = target_template->file.get<janus_template_id>("TEMPLATE_ID");
277   -
278   - size_t target_bytes;
279   - janus_data *buffer = new janus_data[janus_max_template_size()];
280   - JANUS_ASSERT(janus_flatten_template(target_template, buffer, &target_bytes))
281   -
282   - janus_flat_template target_flat = new janus_data[target_bytes];
283   - memcpy(target_flat, buffer, target_bytes);
284   -
285   - float similarity;
286   - JANUS_ASSERT(janus_verify(probe, probe_bytes, target_flat, target_bytes, &similarity))
287   - if ((size_t)comparisons.size() < requested_returns) {
288   - comparisons.append(Pair(similarity, target_id));
289   - std::sort(comparisons.begin(), comparisons.end());
290   - } else {
291   - Pair temp = comparisons.first();
292   - if (temp.first < similarity) {
293   - comparisons.removeFirst();
294   - comparisons.append(Pair(similarity, target_id));
295   - std::sort(comparisons.begin(), comparisons.end());
296   - }
297   - }
298   - delete[] buffer;
299   - delete[] target_flat;
300   - }
301   - *actual_returns = comparisons.size();
302   - QList<Pair> temp; temp.reserve(comparisons.size());
303   - std::reverse_copy(comparisons.begin(), comparisons.end(), std::back_inserter(temp));
304   - comparisons = temp;
305   - foreach(const Pair &comparison, comparisons) {
306   - *similarities = comparison.first; similarities++;
307   - *template_ids = comparison.second; template_ids++;
308   - }
309   - return JANUS_SUCCESS;
310   -}
openbr/janus_io.cpp deleted
1   -#include <QtConcurrent>
2   -
3   -#define JANUS_CUSTOM_ADD_SAMPLE
4   -#define JANUS_CUSTOM_CREATE_GALLERY
5   -#define JANUS_CUSTOM_CREATE_TEMPLATES
6   -#include "janus/src/janus_io.cpp"
7   -
8   -static void _janus_add_sample(vector<double> &samples, double sample)
9   -{
10   - static QMutex sampleLock;
11   - QMutexLocker sampleLocker(&sampleLock);
12   - samples.push_back(sample);
13   -}
14   -
15   -typedef QPair<janus_template_id, FlatTemplate> TemplatePair;
16   -
17   -TemplatePair _janus_create_flat_template(const char *data_path, TemplateData templateData, bool verbose)
18   -{
19   - janus_template template_;
20   - janus_template_id templateID;
21   - JANUS_ASSERT(TemplateIterator::create(data_path, templateData, &template_, &templateID, verbose))
22   - templateData.release();
23   - return TemplatePair(templateID, FlatTemplate(template_));
24   -}
25   -
26   -janus_error janus_create_gallery(const char *data_path, janus_metadata metadata, janus_gallery_path gallery_path, int verbose)
27   -{
28   - TemplateIterator ti(metadata, true);
29   - TemplateData templateData = ti.next();
30   - QFutureSynchronizer<TemplatePair> futures;
31   - while (!templateData.templateIDs.empty()) {
32   - futures.addFuture(QtConcurrent::run(_janus_create_flat_template, data_path, templateData, verbose));
33   - templateData = ti.next();
34   - }
35   - futures.waitForFinished();
36   - QList< QFuture<TemplatePair> > flat_templates = futures.futures();
37   -
38   - vector<janus_flat_template> templates;
39   - vector<size_t> template_bytes;
40   - vector<janus_template_id> template_ids;
41   - size_t num_templates = 0;
42   -
43   - foreach (const QFuture<TemplatePair> &future, flat_templates) {
44   - template_ids.push_back(future.result().first);
45   - template_bytes.push_back(future.result().second.data->bytes);
46   - templates.push_back(future.result().second.data->flat_template);
47   - num_templates++;
48   - }
49   -
50   - JANUS_ASSERT(janus_write_gallery(&templates[0], &template_bytes[0], &template_ids[0], num_templates, gallery_path))
51   - return JANUS_SUCCESS;
52   -}
53   -
54   -janus_error janus_create_templates(const char *data_path, janus_metadata metadata, const char *gallery_file, int verbose)
55   -{
56   - TemplateIterator ti(metadata, true);
57   - TemplateData templateData = ti.next();
58   -
59   - QFutureSynchronizer<TemplatePair> futures;
60   - while (!templateData.templateIDs.empty()) {
61   - futures.addFuture(QtConcurrent::run(_janus_create_flat_template, data_path, templateData, verbose));
62   - templateData = ti.next();
63   - }
64   - futures.waitForFinished();
65   - QList< QFuture<TemplatePair> > flat_templates = futures.futures();
66   -
67   - std::ofstream file;
68   - file.open(gallery_file, std::ios::out | std::ios::binary);
69   - foreach (const QFuture<TemplatePair> &future, flat_templates) {
70   - janus_template_id templateID = future.result().first;
71   - FlatTemplate flatTemplate = future.result().second;
72   - file.write((char*)&templateID, sizeof(templateID));
73   - file.write((char*)&flatTemplate.data->bytes, sizeof(flatTemplate.data->bytes));
74   - file.write((char*)flatTemplate.data->flat_template, flatTemplate.data->bytes);
75   - }
76   -
77   - file.close();
78   - return JANUS_SUCCESS;
79   -}