Commit 8427e67a3f37403889d642a0c9b8f5eb4c370db5
1 parent
48097472
now supporting threaded janus_enroll
Showing
3 changed files
with
39 additions
and
2 deletions
openbr/CMakeLists.txt
| ... | ... | @@ -5,7 +5,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 5 | 5 | # Janus API |
| 6 | 6 | include_directories(janus/include) |
| 7 | 7 | install(DIRECTORY janus/include DESTINATION .) |
| 8 | -set(BR_JANUS janus/src/janus_io.cpp janus/src/opencv_io/opencv_io.cpp) | |
| 8 | +set(BR_JANUS janus/src/opencv_io/opencv_io.cpp) | |
| 9 | 9 | add_definitions(-DJANUS_LIBRARY) |
| 10 | 10 | |
| 11 | 11 | # Collect source files | ... | ... |
openbr/janus_io.cpp
0 → 100644
| 1 | +#include <QtConcurrent> | |
| 2 | + | |
| 3 | +#define JANUS_CUSTOM_ADD_SAMPLE | |
| 4 | +#define JANUS_CUSTOM_CREATE_GALLERY | |
| 5 | +#include "janus/src/janus_io.cpp" | |
| 6 | + | |
| 7 | +static void _janus_add_sample(vector<double> &samples, double sample) | |
| 8 | +{ | |
| 9 | + static QMutex sampleLock; | |
| 10 | + QMutexLocker sampleLocker(&sampleLock); | |
| 11 | + samples.push_back(sample); | |
| 12 | +} | |
| 13 | + | |
| 14 | +static void _janus_create_template(const char *data_path, TemplateData templateData, janus_gallery gallery) | |
| 15 | +{ | |
| 16 | + janus_template template_; | |
| 17 | + janus_template_id templateID; | |
| 18 | + JANUS_ASSERT(TemplateIterator::create(data_path, templateData, &template_, &templateID)) | |
| 19 | + | |
| 20 | + static QMutex enrollLock; | |
| 21 | + QMutexLocker enrollLocker(&enrollLock); | |
| 22 | + | |
| 23 | + JANUS_ASSERT(janus_enroll(template_, templateID, gallery)) | |
| 24 | +} | |
| 25 | + | |
| 26 | +janus_error janus_create_gallery(const char *data_path, janus_metadata metadata, janus_gallery gallery) | |
| 27 | +{ | |
| 28 | + TemplateIterator ti(metadata, true); | |
| 29 | + TemplateData templateData = ti.next(); | |
| 30 | + QFutureSynchronizer<void> futures; | |
| 31 | + while (!templateData.templateIDs.empty()) { | |
| 32 | + futures.addFuture(QtConcurrent::run(_janus_create_template, data_path, templateData, gallery)); | |
| 33 | + templateData = ti.next(); | |
| 34 | + } | |
| 35 | + futures.waitForFinished(); | |
| 36 | + return JANUS_SUCCESS; | |
| 37 | +} | ... | ... |