diff --git a/openbr/plugins/fst3.cmake b/openbr/plugins/fst3.cmake deleted file mode 100644 index b79a8d3..0000000 --- a/openbr/plugins/fst3.cmake +++ /dev/null @@ -1,13 +0,0 @@ -set(BR_WITH_FST3 OFF CACHE BOOL "Build with Feature Selection Toolbox 3") - -if(${BR_WITH_FST3}) - find_package(FST3 REQUIRED) - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} plugins/fst3.cpp ${FST3_SRC}) - - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIRS}) - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} boost_thread) - - find_package(LibSVM REQUIRED) - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} ${LibSVM_SRC}) -endif() diff --git a/openbr/plugins/fst3.cpp b/openbr/plugins/fst3.cpp deleted file mode 100644 index 3de6015..0000000 --- a/openbr/plugins/fst3.cpp +++ /dev/null @@ -1,455 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "model.h" -#include "common/opencvutils.h" -#include "common/qtutils.h" -#include "plugins/meta.h" -#include "plugins/regions.h" - -//#ifdef MM_SDK_TRAINABLE -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace FST; -//#endif // MM_SDK_TRAINABLE - -using namespace mm; - -enum DimensionStatus { - On, - Off, - Ignore -}; - -//#ifdef MM_SDK_TRAINABLE -template -class FST3Data_Accessor_Splitting_MemMM : public Data_Accessor_Splitting_Mem -{ - QList mll; - QList dsl; - int features; - QMap labelCounts; - -public: - typedef Data_Accessor_Splitting_Mem DASM; - typedef boost::shared_ptr > PScaler; - typedef typename DASM::PSplitters PSplitters; - - FST3Data_Accessor_Splitting_MemMM(const QList &_mll, const QList &_dsl, const PSplitters _dsp, const PScaler _dsc) - : Data_Accessor_Splitting_Mem("MM", _dsp, _dsc), mll(_mll), dsl(_dsl) - { - features = 0; - foreach (DimensionStatus ds, dsl) - if (ds != Ignore) features++; - labelCounts = mll.first().labelCounts(); - } - - FST3Data_Accessor_Splitting_MemMM(const MatrixList &_ml, const PSplitters _dsp, const PScaler _dsc) - : Data_Accessor_Splitting_Mem("MM", _dsp, _dsc) - { - mll.append(_ml); - features = _ml.first().total() * _ml.first().channels(); - for (int i=0; i(damt, x) - {} // weak (referencing) copy-constructor to be used in sharing_clone() - - virtual void initial_data_read(); //!< \note off-limits in shared_clone - virtual void initial_file_prepare() {} - -public: - virtual unsigned int file_getNoOfClasses() const { return labelCounts.size(); } - virtual unsigned int file_getNoOfFeatures() const { return features; } - virtual IDXTYPE file_getClassSize(unsigned int cls) const { return labelCounts[cls]; } -}; - -template -void FST3Data_Accessor_Splitting_MemMM::initial_data_read() //!< \note off-limits in shared_clone -{ - if (Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemMM()::initial_data_read() called from shared_clone instance."); - IDXTYPE idx=0; - - // TODO: Assert that ml data type is DATATYPE - const QList labels = mll.first().labels(); - foreach (int label, labelCounts.keys()) { - for (int i=0; idata[idx++] = reinterpret_cast(m.data)[j]; - } - } - } - } -} - -/*template -Data_Accessor_Splitting_MemMM* Data_Accessor_Splitting_MemMM::sharing_clone() const -{ - Data_Accessor_Splitting_MemMM *clone=new Data_Accessor_Splitting_MemMM(*this, (int)0); - clone->set_sharing_cloned(); - return clone; -} - -template -std::ostream& Data_Accessor_Splitting_MemMM::print(std::ostream& os) const -{ - DASM::print(os); - os << std::endl << "Data_Accessor_Splitting_MemMM()"; - return os; -}*/ - -//#endif // MM_SDK_TRAINABLE - - -class FST3DOS : public Feature -{ - friend class Maker; - - int delta; - - mm::Remap remap; - - DOS(int delta = 1) - { - this->delta = delta; - } - - static QString args() - { - return "delta = 1"; - } - - static DOS *make(const QString &args) - { - QStringList words = QtUtils::parse(args); - if (words.size() > 1) qFatal("DOS::make invalid argument count."); - - int delta = 1; - - bool ok; - switch (words.size()) { - case 1: - delta = words[0].toInt(&ok); if (!ok) qFatal("DOS::make expected integer delta."); - } - - return new DOS(delta); - } - - QSharedPointer clone() const - { - return QSharedPointer(new DOS(delta)); - } - - void train(const MatrixList &data, Matrix &metadata) - { - (void) metadata; - //#ifdef MM_SDK_TRAINABLE - try { - typedef float RETURNTYPE; typedef float DATATYPE; typedef float REALTYPE; - typedef unsigned int IDXTYPE; typedef unsigned int DIMTYPE; typedef int BINTYPE; - typedef Subset SUBSET; - typedef Data_Intervaller >,IDXTYPE> INTERVALLER; - typedef boost::shared_ptr > PSPLITTER; - typedef Data_Splitter_CV SPLITTERCV; - typedef Data_Splitter_5050 SPLITTER5050; - typedef Data_Splitter_Resub SPLITTERRESUB; - typedef Data_Accessor_Splitting_MemMM DATAACCESSOR; - typedef Distance_Euclid DISTANCE; - typedef Classifier_kNN CLASSIFIERKNN; - typedef Criterion_Wrapper WRAPPERKNN; - typedef Sequential_Step_Straight_Threaded EVALUATOR; - - // Initialize dataset - PSPLITTER dsp_outer(new SPLITTER5050()); // keep second half of data for independent testing of final classification performance - PSPLITTER dsp_inner(new SPLITTERCV(3)); // in the course of search use the first half of data by 3-fold cross-validation in wrapper FS criterion evaluation - boost::shared_ptr > dsc(new Data_Scaler_void()); // do not scale data - boost::shared_ptr > splitters(new std::vector); // set-up data access - splitters->push_back(dsp_outer); //splitters->push_back(dsp_inner); - boost::shared_ptr da(new DATAACCESSOR(data, splitters, dsc)); - da->initialize(); - da->setSplittingDepth(0); if(!da->getFirstSplit()) throw fst_error("50/50 data split failed."); - //da->setSplittingDepth(1); if(!da->getFirstSplit()) throw fst_error("3-fold cross-validation failure."); - boost::shared_ptr sub(new SUBSET(da->getNoOfFeatures())); // initiate the storage for subset to-be-selected - //sub->select_all(); - - // Run search - boost::shared_ptr cknn(new CLASSIFIERKNN); cknn->set_k(1); - boost::shared_ptr wknn(new WRAPPERKNN); - wknn->initialize(cknn,da); - boost::shared_ptr eval(new EVALUATOR); // set-up the standard sequential search step object (option: hybrid, ensemble, etc.) - //Search_DOS srch(eval); // set-up Sequential Forward Floating Selection search procedure - //srch.set_delta(delta); - - //FST::Search_SFFS srch(eval); - //srch.set_search_direction(FST::BACKWARD); - - //FST::Search_SFS srch(eval); - //srch.set_search_direction(FST::FORWARD); - - FST::Search_Monte_Carlo_Threaded srch; - srch.set_cardinality_randomization(0.5); // probability of inclusion of each particular feature (~implies also the expected subset size) - srch.set_stopping_condition(0/*max trials*/,30/*seconds*/); // one or both values must have positive value - - RETURNTYPE critval_train; - if(!srch.search(0,critval_train,sub,wknn,std::cout)) throw fst_error("Search not finished."); - - // Create map matrix - const int dims = sub->get_d_raw(); - cv::Mat xMap(1, dims, CV_16SC1), - yMap(1, dims, CV_16SC1); - int index = 0; - for (int i=0; iselected_raw(i)) { - xMap.at(0, index) = i; - yMap.at(0, index) = 0; - index++; - } - } - - remap = Remap(xMap, yMap, cv::INTER_NEAREST); - } - catch (fst_error &e) { qFatal("FST ERROR: %s, code=%d", e.what(), e.code()); } - catch (std::exception &e) { qFatal("non-FST ERROR: %s", e.what()); } - metadata >> remap; - //#else // MM_SDK_TRAINABLE - //qFatal("StreamwiseFS::train not supported."); - //#endif // MM_SDK_TRAINABLE - } - - void project(const Matrix &src, Matrix &dst) const - { - dst = src; - dst >> remap; - } - - void store(QDataStream &stream) const - { - stream << remap; - } - - void load(QDataStream &stream) - { - stream >> remap; - } -}; - -MM_REGISTER(Feature, FST3DOS, true) - - -class FST3StreamwiseFS : public Feature -{ - friend class Maker; - - QSharedPointer weakLearnerTemplate; - int time; - - mm::Dup dup; - mm::Remap remap; - - StreamwiseFS(const QSharedPointer &weakLearnerTemplate, int time) - : dup(weakLearnerTemplate, 1) - { - this->weakLearnerTemplate = weakLearnerTemplate; - this->time = time; - } - - static QString args() - { - return " weakLearnerTemplate, int time"; - } - - static StreamwiseFS *make(const QString &args) - { - QStringList words = QtUtils::parse(args); - if (words.size() != 2) qFatal("StreamwiseFS::make invalid argument count."); - - QSharedPointer weakLearnerTemplate = Feature::make(words[0]); - bool ok; - int time = words[1].toInt(&ok); assert(ok); - - return new StreamwiseFS(weakLearnerTemplate, time); - } - - QSharedPointer clone() const - { - return QSharedPointer(new StreamwiseFS(weakLearnerTemplate, time)); - } - - void train(const MatrixList &data, Matrix &metadata) - { - QList< QSharedPointer > weakLearners; - QList projectedDataList; - QList weakLearnerDimsList; - QList dimStatusList; - - QTime timer; timer.start(); - while (timer.elapsed() / 1000 < time) { - // Construct a new weak learner - QSharedPointer newWeakLearner = weakLearnerTemplate->clone(); - Matrix metadataCopy(metadata); - newWeakLearner->train(data, metadataCopy); - weakLearners.append(newWeakLearner); - - MatrixList projectedData = data; - projectedData >> *newWeakLearner; - projectedDataList.append(projectedData); - weakLearnerDimsList.append(projectedData.first().total() * projectedData.first().channels()); - for (int i=0; i SUBSET; - typedef Data_Intervaller >,IDXTYPE> INTERVALLER; - typedef boost::shared_ptr > PSPLITTER; - typedef Data_Splitter_CV SPLITTERCV; - typedef Data_Splitter_5050 SPLITTER5050; - typedef Data_Accessor_Splitting_MemMM DATAACCESSOR; - typedef Distance_Euclid DISTANCE; - typedef Classifier_kNN CLASSIFIERKNN; - typedef Criterion_Wrapper WRAPPERKNN; - typedef Sequential_Step_Straight_Threaded EVALUATOR; - - // Initialize dataset - PSPLITTER dsp_outer(new SPLITTER5050()); // keep second half of data for independent testing of final classification performance - PSPLITTER dsp_inner(new SPLITTERCV(3)); // in the course of search use the first half of data by 3-fold cross-validation in wrapper FS criterion evaluation - boost::shared_ptr > dsc(new Data_Scaler_void()); // do not scale data - boost::shared_ptr > splitters(new std::vector); // set-up data access - splitters->push_back(dsp_outer); splitters->push_back(dsp_inner); - boost::shared_ptr da(new DATAACCESSOR(projectedDataList, dimStatusList, splitters, dsc)); - da->initialize(); - da->setSplittingDepth(0); if(!da->getFirstSplit()) throw fst_error("50/50 data split failed."); - da->setSplittingDepth(1); if(!da->getFirstSplit()) throw fst_error("3-fold cross-validation failure."); - boost::shared_ptr sub(new SUBSET(da->getNoOfFeatures())); // initiate the storage for subset to-be-selected - - { // Initialize subset from previous iteration results - sub->deselect_all(); - int index = 0; - for (int i=0; iselect(index); - if (dimStatusList[i] != Ignore) index++; - } - } - - // Run search - boost::shared_ptr cknn(new CLASSIFIERKNN); cknn->set_k(3); // set-up 3-Nearest Neighbor classifier based on Euclidean distances - boost::shared_ptr wknn(new WRAPPERKNN); // wrap the 3-NN classifier to enable its usage as FS criterion (criterion value will be estimated by 3-fold cross-val.) - wknn->initialize(cknn,da); - boost::shared_ptr eval(new EVALUATOR); // set-up the standard sequential search step object (option: hybrid, ensemble, etc.) - Search_DOS srch(eval); // set-up Sequential Forward Floating Selection search procedure - srch.set_delta(1); - RETURNTYPE critval_train; - if(!srch.search(0,critval_train,sub,wknn,std::cout)) throw fst_error("Search not finished."); - - { // Update results - int dslIndex = dimStatusList.size() - 1; - int subIndex = da->getNoOfFeatures() - 1; - for (int wlIndex = weakLearnerDimsList.size()-1; wlIndex >= 0; wlIndex--) { - const int weakLearnerDims = weakLearnerDimsList[wlIndex]; - int numSelectedDims = 0; - for (int i=0; iselected_raw(subIndex--) ? numSelectedDims++, On : Ignore; - dslIndex--; - } - - if (numSelectedDims == 0) { - for (int j=0; j(0, index) = i; - yMap.at(0, index) = 0; - index++; - } - } - - remap = Remap(xMap, yMap, cv::INTER_NEAREST); - } - - void project(const Matrix &src, Matrix &dst) const - { - dst = src; - dst >> dup >> mm::Cat >> remap; - } - - void store(QDataStream &stream) const - { - stream << dup << remap; - } - - void load(QDataStream &stream) - { - stream >> dup >> remap; - } -}; - -MM_REGISTER(Feature, FST3StreamwiseFS, true) diff --git a/openbr/plugins/phash.cmake b/openbr/plugins/phash.cmake deleted file mode 100644 index 3ffb76c..0000000 --- a/openbr/plugins/phash.cmake +++ /dev/null @@ -1,7 +0,0 @@ -set(BR_WITH_PHASH OFF CACHE BOOL "Build with pHash") - -if(${BR_WITH_PHASH}) - find_package(pHash REQUIRED) - find_package(CImg REQUIRED) - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/phash.cpp ${PHASH_SRC}) -endif() diff --git a/openbr/plugins/phash.cpp b/openbr/plugins/phash.cpp deleted file mode 100644 index 67c93d6..0000000 --- a/openbr/plugins/phash.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include - -using namespace mm; - -/**** PHASH ****/ -class pHashEnroll : public UntrainableFeature -{ - void project(const Matrix &src, Matrix &dst) const - { - CImg cImg(src.data, src.cols, src.rows, 1, src.channels()); - cv::Mat m(1, sizeof(ulong64), CV_8UC1); - ulong64 hash; - if (ph_dct_imagehash(cImg, hash) == -1) - qFatal("pHashEnroll::project ph_dct_imagehash failure for file %s.", qPrintable(src.metadata.fileName)); - memcpy(m.data, &hash, sizeof(ulong64)); - dst = Matrix(m, src.metadata); - } - - /*** Taken from pHash, modified to take in a CImg instead of a file. ***/ - static CImg* ph_dct_matrix(const int N){ - CImg *ptr_matrix = new CImg(N,N,1,1,1/sqrt((float)N)); - const float c1 = sqrt(2.0/N); - for (int x=0;xdata(x,y) = c1*cos((cimg::PI/2/N)*y*(2*x+1)); - } - } - return ptr_matrix; - } - - static int ph_dct_imagehash(CImg src, ulong64 &hash) - { - CImg meanfilter(7,7,1,1,1); - CImg img; - if (src.spectrum() == 3){ - img = src.RGBtoYCbCr().channel(0).get_convolve(meanfilter); - } else if (src.spectrum() == 4){ - int width = img.width(); - int height = img.height(); - int depth = img.depth(); - img = src.crop(0,0,0,0,width-1,height-1,depth-1,2).RGBtoYCbCr().channel(0).get_convolve(meanfilter); - } else { - img = src.channel(0).get_convolve(meanfilter); - } - - img.resize(32,32); - CImg *C = ph_dct_matrix(32); - CImg Ctransp = C->get_transpose(); - - CImg dctImage = (*C)*img*Ctransp; - - CImg subsec = dctImage.crop(1,1,8,8).unroll('x');; - - float median = subsec.median(); - ulong64 one = 0x0000000000000001; - hash = 0x0000000000000000; - for (int i=0;i< 64;i++){ - float current = subsec(i); - if (current > median) - hash |= one; - one = one << 1; - } - - delete C; - - return 0; - } -}; - -MM_REGISTER(Feature, pHashEnroll, false) - - -/**** PHASH_COMPARE ****/ -class pHashCompare : public ComparerBase -{ - float compare(const cv::Mat &a, const cv::Mat &b) const - { - return 1.f - 1.f * ph_hamming_distance(*reinterpret_cast(a.data), *reinterpret_cast(b.data)) / 64; - } -}; - -MM_REGISTER(Comparer, pHashCompare, false) - - -/**** PHASH ****/ -class pHash : public Algorithm -{ - QString algorithm() const - { - return "Open+pHashEnroll:Identity:pHashCompare"; - } -}; - -MM_REGISTER(Algorithm, pHash, false) diff --git a/openbr/plugins/pp4.cmake b/openbr/plugins/pp4.cmake deleted file mode 100644 index fd79240..0000000 --- a/openbr/plugins/pp4.cmake +++ /dev/null @@ -1,9 +0,0 @@ -set(BR_WITH_PP4 OFF CACHE BOOL "Build with PittPatt 4") - -if(${BR_WITH_PP4}) - find_package(PP4 REQUIRED) - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/pp4.cpp) - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${PP4_LIBS}) - install(DIRECTORY ${PP4_DIR}/lib/ DESTINATION lib) - install(DIRECTORY ${PP4_DIR}/models/ DESTINATION models/pp4) -endif() diff --git a/openbr/plugins/pp4.cpp b/openbr/plugins/pp4.cpp deleted file mode 100644 index 8ae55e4..0000000 --- a/openbr/plugins/pp4.cpp +++ /dev/null @@ -1,385 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define TRY(CC) \ -{ \ - if ((CC) != PPR_SUCCESS) qFatal("%d error (%s, %d): %s.", CC, __FILE__, __LINE__, ppr_error_message(CC)); \ -} - -#define TRY_VIDEO(CC) \ -{ \ - if ((CC) != PPR_VIDEO_IO_SUCCESS) qFatal("%d error (%s, %d): %s.", CC, __FILE__, __LINE__, ppr_video_io_error_message(CC)); \ -} - -#define TRY_RAW_IMAGE(CC) \ -{ \ - if ((CC) != PPR_RAW_IMAGE_SUCCESS) qFatal("%d error (%s, %d): %s.", CC, __FILE__, __LINE__, ppr_raw_image_error_message(CC)); \ -} - -using namespace mm; - -/*! - * \brief PittPatt 4 context - * \author Josh Klontz \cite jklontz - * \warning Needs a maintainer. - */ -struct PP4Context -{ - static ppr_context_type context; - - static void createRawImage(const cv::Mat &src, ppr_raw_image_type &dst) - { - ppr_raw_image_create(&dst, src.cols, src.rows, PPR_RAW_IMAGE_BGR24); - assert((src.type() == CV_8UC3) && src.isContinuous()); - memcpy(dst.data, src.data, 3*src.rows*src.cols); - } - - static void createMat(const ppr_template_type &src, cv::Mat &dst) - { - ppr_flat_template_type flat_template; - TRY(ppr_flatten_template(context,src,&flat_template)) - dst = cv::Mat(1, flat_template.num_bytes, CV_8UC1, flat_template.data).clone(); - ppr_free_flat_template(flat_template); - } - - static void createTemplate(const cv::Mat &src, ppr_template_type *dst) - { - ppr_flat_template_type flat_template; - flat_template.num_bytes = src.cols; - flat_template.data = src.data; - TRY(ppr_unflatten_template(context, flat_template, dst)) - } - - static QString toString(const ppr_landmark_category_type &category) - { - switch (category) { - case PPR_LANDMARK_LEFT_EYE: - return "Left_Eye"; - case PPR_LANDMARK_RIGHT_EYE: - return "Right_Eye"; - case PPR_LANDMARK_NOSE_BASE: - return "Nose_Base"; - case PPR_LANDMARK_NOSE_BRIDGE: - return "Nose_Bridge"; - case PPR_LANDMARK_NOSE_TIP: - return "Nose_Tip"; - case PPR_LANDMARK_NOSE_TOP: - return "Nose_Top"; - case PPR_LANDMARK_EYE_NOSE: - return "Eye_Nose"; - case PPR_LANDMARK_MOUTH: - return "Mouth"; - } - - return "Unknown"; - } - - static File toMetadata(const ppr_object_type &object) - { - File metadata; - metadata.insert("PP4_Object_X", object.position.x - object.dimensions.width/2); - metadata.insert("PP4_Object_Y", object.position.y - object.dimensions.height/2); - metadata.insert("PP4_Object_Width", object.dimensions.width); - metadata.insert("PP4_Object_Height", object.dimensions.height); - metadata.insert("PP4_Object_Confidence", object.confidence); - metadata.insert("PP4_Object_Roll", object.rotation.roll); - metadata.insert("PP4_Object_Pitch", object.rotation.pitch); - metadata.insert("PP4_Object_Yaw", object.rotation.yaw); - metadata.insert("PP4_Object_Precision", object.rotation.precision); - metadata.insert("PP4_Object_ModelID", object.model_id); - metadata.insert("PP4_Object_NumLandmarks", object.num_landmarks); - metadata.insert("PP4_Object_Size", object.size); - - QList categories; - categories << PPR_LANDMARK_RIGHT_EYE - << PPR_LANDMARK_LEFT_EYE - << PPR_LANDMARK_NOSE_BASE - << PPR_LANDMARK_NOSE_BRIDGE - << PPR_LANDMARK_NOSE_TIP - << PPR_LANDMARK_NOSE_TOP - << PPR_LANDMARK_EYE_NOSE - << PPR_LANDMARK_MOUTH; - - for (int i=0; iSDKPath + "/models/pp4"))) - TRY(ppr_set_num_recognition_threads(context, QThreadPool::globalInstance()->maxThreadCount())) - TRY(ppr_set_num_detection_threads(context, 1)) - TRY(ppr_set_detection_precision(context, PPR_FINE_PRECISION)) - TRY(ppr_set_landmark_detector_type(context, PPR_DUAL_MULTI_POSE_LANDMARK_DETECTOR, PPR_AUTOMATIC_LANDMARKS)) - TRY(ppr_set_min_size(context, 4)) - TRY(ppr_set_frontal_yaw_constraint(context, PPR_FRONTAL_YAW_CONSTRAINT_PERMISSIVE)) - TRY(ppr_set_template_extraction_type(context, PPR_EXTRACT_DOUBLE)) - TRY(ppr_initialize_context(context)) - Globals->Abbreviations.insert("PP4", "Open+PP4Detect!PP4Enroll:PP4Compare"); - } - - void finalize() const - { - TRY(ppr_release_context(context)) - ppr_finalize_sdk(); - } -}; - -MM_REGISTER(Initializer, PP4Initializer, "") - -/*! - * \ingroup transforms - * \brief Detect a face in PittPatt 4 - * \author Josh Klontz \cite jklontz - * \warning Needs a maintainer. - */ -class PP4Detect : public UntrainableMetaFeature - , public PP4Context -{ - Q_OBJECT - - void project(const Template &src, Template &dst) const - { - dst.file = src.file; - - foreach (const cv::Mat &matrix, src) { - ppr_raw_image_type raw_image; - createRawImage(matrix, raw_image); - ppr_image_type image; - TRY(ppr_create_image(raw_image, &image)) - ppr_object_list_type object_list; - TRY(ppr_detect_objects(context, image, &object_list)) - - QList objects; - if (src.file.getBool("ForceEnrollment")) objects = getBestObject(object_list); - else objects = getAllObjects(object_list); - - foreach (const ppr_object_type &object, objects) { - dst.file.append(toMetadata(object)); - dst += matrix; - } - - ppr_free_object_list(object_list); - ppr_free_image(image); - ppr_raw_image_free(raw_image); - } - - if (src.file.getBool("ForceEnrollment") && dst.isEmpty()) dst += cv::Mat(); - } - -private: - QList getBestObject(ppr_object_list_type object_list) const - { - int best_index = -1; - float best_confidence = 0; - for (int i=0; i best_confidence) || - (best_index == -1)) { - best_confidence = object.confidence; - best_index = i; - } - } - - QList objects; - if (best_index != -1) objects.append(object_list.objects[best_index]); - return objects; - } - - QList getAllObjects(ppr_object_list_type object_list) const - { - QList objects; - for (int i=0; i target_template_ids, query_template_ids; - enroll(target, &target_gallery, target_template_ids); - enroll(query, &query_gallery, query_template_ids); - - ppr_similarity_matrix_type similarity_matrix; - TRY(ppr_compare_galleries(context, query_gallery, target_gallery, &similarity_matrix)) - - for (int i=0; i::max(); - if ((query_template_id != -1) && (target_template_id != -1)) { - TRY(ppr_get_similarity_matrix_element(context, similarity_matrix, query_template_id, target_template_id, &score)) - } - output->setData(score, i, j); - } - } - - ppr_free_similarity_matrix(similarity_matrix); - ppr_free_gallery(target_gallery); - ppr_free_gallery(query_gallery); - } - - void enroll(const TemplateList &templates, ppr_gallery_type *gallery, QList &template_ids) const - { - foreach (const Template &t, templates) { - if (t.m().data) { - ppr_template_type u; - createTemplate(t.m(), &u); - int template_id; - TRY(ppr_copy_template_to_gallery(context, gallery, u, &template_id)) - template_ids.append(template_id); - ppr_free_template(u); - } else { - template_ids.append(-1); - } - } - } -}; - -MM_REGISTER(Comparer, PP4Compare, "") - -#include "plugins/pp4.moc" diff --git a/openbr/plugins/topsurf.cmake b/openbr/plugins/topsurf.cmake deleted file mode 100644 index 32c0eba..0000000 --- a/openbr/plugins/topsurf.cmake +++ /dev/null @@ -1,10 +0,0 @@ -set(BR_WITH_TOPSURF OFF CACHE BOOL "Build with TOP-SURF") - -if(${BR_WITH_TOPSURF}) - find_package(TopSurf REQUIRED) - set(THIRDPARTY_SRC ${THIRDPARTY_SRC} plugins/topsurf.cpp ${TOPSURF_SRC} ${TOPSURF_FLANN_SRC}) - install(DIRECTORY ${TOPSURF_DIR}/dictionary_10000 - ${TOPSURF_DIR}/dictionary_20000 - ${TOPSURF_DIR}/dictionary_40000 - DESTINATION models/topsurf) -endif() diff --git a/openbr/plugins/topsurf.cpp b/openbr/plugins/topsurf.cpp deleted file mode 100644 index f59cdf3..0000000 --- a/openbr/plugins/topsurf.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include -#include -#include - -#include "common/opencvutils.h" -#include "common/qtutils.h" -#include "common/resource.h" - -using namespace cv; -using namespace mm; -using namespace std; - -class TopSurfInitializer : public Initializer -{ - void initialize() const - { - Globals.Abbreviations.insert("TopSurf", "Open!TopSurfExtract(40000):TopSurfCompare"); - Globals.Abbreviations.insert("TopSurfM", "Open!TopSurfExtract(1000000):TopSurfCompare"); - Globals.Abbreviations.insert("TopSurfKNN", "Open!TopSurfExtract+TopSurfKNN"); - Globals.Abbreviations.insert("DocumentClassification", "TopSurfKNN"); - } - - void finalize() const {} -}; - -MM_REGISTER(Initializer, TopSurfInitializer, false) - - -class TopSurfResourceMaker : public ResourceMaker -{ - QString file; - -public: - TopSurfResourceMaker(const QString &dictionary) - { - file = Globals.SDKPath + "/models/topsurf/dictionary_" + dictionary; - } - -private: - TopSurf *make() const - { - TopSurf *topSurf = new TopSurf(256, 100); - if (!topSurf->LoadDictionary(qPrintable(file))) - qFatal("TopSurfResourceMaker::make failed to load dictionary."); - return topSurf; - } -}; - - -/**** -TopSurfExtract - Wrapper to TopSurf::ExtractDescriptor() - B. Thomee, E.M. Bakker, and M.S. Lew, "TOP-SURF: a visual words toolkit", - in Proceedings of the 18th ACM International Conference on Multimedia, pp. 1473-1476, Firenze, Italy, 2010. -****/ -class TopSurfExtract : public UntrainableFeature -{ - Q_OBJECT - Q_PROPERTY(QString dictionary READ get_dictionary WRITE set_dictionary) - MM_MEMBER(QString, dictionary) - - Resource topSurfResource; - -public: - TopSurfExtract() : topSurfResource(new TopSurfResourceMaker("10000")) {} - -private: - void init() - { - topSurfResource.setResourceMaker(new TopSurfResourceMaker(dictionary)); - } - - void project(const Template &src, Template &dst) const - { - // Compute descriptor (not thread safe) - TopSurf *topSurf = topSurfResource.acquire(); - TOPSURF_DESCRIPTOR descriptor; - IplImage iplSrc = src.m(); - if (!topSurf->ExtractDescriptor(iplSrc, descriptor)) - qFatal("TopSurfExtract::project ExtractDescriptor failure."); - topSurfResource.release(topSurf); - - // Copy descriptor and clean up - unsigned char *data; - int length; - Descriptor2Array(descriptor, data, length); - Mat m(1, length, CV_8UC1); - memcpy(m.data, data, length); - delete data; - TopSurf::ReleaseDescriptor(descriptor); - dst = m; - } - -public: - static QString args() - { - return "10000|20000|40000 dictionary = 10000"; - } - - static TopSurfExtract *make(const QStringList &args) - { - (void) args; - return new TopSurfExtract(); - } -}; - -MM_REGISTER(Feature, TopSurfExtract, true) - - -class TopSurfHist : public UntrainableFeature -{ - Q_OBJECT - Q_PROPERTY(int size READ get_size WRITE set_size) - MM_MEMBER(int, size) - - void project(const Template &src, Template &dst) const - { - TOPSURF_DESCRIPTOR td; - Array2Descriptor(src.m().data, td); - - Mat m(1, size, CV_32FC1); - m.setTo(0); - for (int i=0; i(0, td.visualword[i].identifier % size)++; - - TopSurf::ReleaseDescriptor(td); - dst = m; - } - -public: - static QString args() - { - return "int size = 10000"; - } - - static TopSurfHist *make(const QStringList &args) - { - (void) args; - return new TopSurfHist(); - } -}; - -MM_REGISTER(Feature, TopSurfHist, true) - - -// Wrapper around TopSurf CompareDescriptors -float TopSurfSimilarity(const Mat &a, const Mat &b, bool cosine) -{ - TOPSURF_DESCRIPTOR tda, tdb; - Array2Descriptor(a.data, tda); - Array2Descriptor(b.data, tdb); - - float result; - if (cosine) result = TopSurf::CompareDescriptorsCosine(tda, tdb); - else result = TopSurf::CompareDescriptorsAbsolute(tda, tdb); - - TopSurf::ReleaseDescriptor(tda); - TopSurf::ReleaseDescriptor(tdb); - return result; -} - - -/**** -TopSurfCompare - Wrapper to TopSurf_CompareDescriptors() - B. Thomee, E.M. Bakker, and M.S. Lew, "TOP-SURF: a visual words toolkit", - in Proceedings of the 18th ACM International Conference on Multimedia, pp. 1473-1476, Firenze, Italy, 2010. -****/ -class TopSurfCompare : public ComparerBase -{ - Q_OBJECT - Q_PROPERTY(bool cosine READ get_cosine WRITE set_cosine) - MM_MEMBER(bool, cosine) - - float compare(const Mat &a, const Mat &b) const - { - return TopSurfSimilarity(a, b, cosine); - } - -public: - static QString args() - { - return "bool cosine = 1"; - } - - static TopSurfCompare *make(const QStringList &args) - { - (void) args; - return new TopSurfCompare(); - } -}; - -MM_REGISTER(Comparer, TopSurfCompare, true) - - -/**** -TopSurfKNN - KNN classifier for TopSurf features. -****/ -class TopSurfKNN : public Feature -{ - Q_OBJECT - Q_PROPERTY(int k READ get_k WRITE set_k) - Q_PROPERTY(bool cosine READ get_cosine WRITE set_cosine) - MM_MEMBER(int, k) - MM_MEMBER(bool, cosine) - - TemplateList data; - -private: - void train(const TemplateList &data) - { - this->data = data; - } - - void project(const Template &src, Template &dst) const - { - // Compute distance to each descriptor - QList< QPair > distances; // - distances.reserve(data.size()); - foreach (const Template &t, data) - distances.append(QPair(TopSurfSimilarity(src, t, cosine), t.file.label())); - - // Find nearest neighbors - qSort(distances); - QHash > counts; // > - for (int i=0; i &distance = distances[i]; - QPair &count = counts[distance.second]; - count.first++; - count.second += distance.first; - } - - // Find most occuring label - int best_label = -1; - int best_count = 0; - float best_distance = numeric_limits::max(); - foreach (int label, counts.keys()) { - const QPair &count = counts[label]; - if ((count.first > best_count) || ((count.first == best_count) && (count.second < best_distance))) { - best_label = label; - best_count = count.first; - best_distance = count.second; - } - } - assert(best_label != -1); - - // Measure confidence - int rest_count = 0; - float rest_distance = 0; - foreach (int label, counts.keys()) { - if (label != best_label) { - const QPair &count = counts[label]; - rest_count = count.first; - rest_distance = count.second; - } - } - - dst = src; - dst.file["Label"] = best_label; - dst.file["Confidence"] = (float)best_count/(float)k; - } - - void store(QDataStream &stream) const - { - stream << data; - } - - void load(QDataStream &stream) - { - stream >> data; - } - -public: - static QString args() - { - return "int k, int cosine = 1"; - } - - static TopSurfKNN *make(const QStringList &args) - { - (void) args; - return new TopSurfKNN(); - } -}; - -MM_REGISTER(Feature, TopSurfKNN, true) - -#include "topsurf.moc" diff --git a/openbr/plugins/yubico.cmake b/openbr/plugins/yubico.cmake deleted file mode 100644 index 8273747..0000000 --- a/openbr/plugins/yubico.cmake +++ /dev/null @@ -1,13 +0,0 @@ -set(BR_WITH_YUBICO OFF CACHE BOOL "Build YubiKey authentication") - -if(${BR_WITH_YUBICO}) - find_package(YubiKey REQUIRED) # For decrypting YubiKeys - find_package(YKPers REQUIRED) # For reading YubiKeys - - install(FILES ${YUBIKEY_LICENSE} RENAME YubiKey DESTINATION share/openbr/licenses) - install(FILES ${YKPERS_LICENSE} RENAME YKPers DESTINATION share/openbr/licenses) - install(FILES ${YKPERS_RULES} DESTINATION share/openbr) - - set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} ${YUBIKEY_SRC} ${YKPERS_SRC} plugins/yubico.cpp) - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${YKPERS_LIBS}) -endif() diff --git a/openbr/plugins/yubico.cpp b/openbr/plugins/yubico.cpp deleted file mode 100644 index 03e0bdd..0000000 --- a/openbr/plugins/yubico.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/**** -YubiKey Challenge-Response Authentication - -To configure YubiKeys for mm usage: -1) Download the cross platform personalization tool from http://yubico.com/personalization-tool. -2) Insert YubiKey and launch the personalization tool (may require sudo access). -3) Click "Challenge-Response Mode". -4) Click "Yubico OTP". -5) Select "Configuration Slot 2" -6) In the Private Identity text box enter "21 92 78 11 55 8a". -7) In the Secret Key text box enter "e7 32 df 49 f3 87 e6 89 04 d2 03 6a 59 ad b7 2f". -8) Click "Write Configuration". -9) Done! - -Unix implementation derived from "ykchalresp.c" in ykpers repository. -Windows implementation derived from "MFCTestDlg.cpp" in Yubikey Client API installer. - -!!! Attention Linux Users !!! -cp trunk/3rdparty/ykpers-1.6.3/70-yubikey.rules /etc/udev/rules.d - -!!! Attention Windows Users !!! -Install Yubikey Client API. -****/ - -using namespace mm; - -static int challenge_response(YK_KEY *yk, int slot, - unsigned char *challenge, unsigned int len, - bool hmac, bool may_block, bool verbose, unsigned char output_buf[(SHA1_MAX_BLOCK_SIZE * 2) + 1]) -{ - unsigned char response[64]; - int yk_cmd; - unsigned int flags = 0; - unsigned int response_len = 0; - unsigned int expect_bytes = 0; - - memset(response, 0, sizeof(response)); - - if (may_block) - flags |= YK_FLAG_MAYBLOCK; - - if (verbose) { - fprintf(stderr, "Sending %i bytes %s challenge to slot %i\n", len, (hmac == true) ? "HMAC" : "Yubico", slot); - //_yk_hexdump(challenge, len); - } - - switch(slot) { - case 1: - yk_cmd = (hmac == true) ? SLOT_CHAL_HMAC1 : SLOT_CHAL_OTP1; - break; - case 2: - yk_cmd = (hmac == true) ? SLOT_CHAL_HMAC2 : SLOT_CHAL_OTP2; - break; - } - - if (!yk_write_to_key(yk, yk_cmd, challenge, len)) - return 0; - - if (verbose) { - fprintf(stderr, "Reading response...\n"); - } - - /* HMAC responses are 160 bits, Yubico 128 */ - expect_bytes = (hmac == true) ? 20 : 16; - - if (! yk_read_response_from_key(yk, slot, flags, - &response, sizeof(response), - expect_bytes, - &response_len)) - return 0; - - if (hmac && response_len > 20) - response_len = 20; - if (! hmac && response_len > 16) - response_len = 16; - - memset(output_buf, 0, SHA1_MAX_BLOCK_SIZE * 2 + 1); - if (hmac) { - yubikey_hex_encode((char *)output_buf, (char *)response, response_len); - } else { - yubikey_modhex_encode((char *)output_buf, (char *)response, response_len); - } - // printf("%s\n", output_buf); - - return 1; -} - -/*! - * \ingroup initializers - * \brief Initialize yubikey - * \author Josh Klontz \cite jklontz - */ -class YubiKey : public Initializer -{ - Q_OBJECT - - void initialize() const - { - // Read from device - YK_KEY *yk = 0; - - if (!yk_init()) - qFatal("YubiKey::initialize yk_init failure."); - - if (!(yk = yk_open_first_key())) - qFatal("Could not connect to license."); - - // Challenge value is arbitrary - srand(time(NULL)); - uint8_t challenge[6] = {rand()%255, rand()%255, rand()%255, rand()%255, rand()%255, rand()%255}; - unsigned char output_buf[(SHA1_MAX_BLOCK_SIZE * 2) + 1]; - if (!challenge_response(yk, 2, challenge, 6, false, true, false, output_buf)) - qFatal("YubiKey::initialize challenge_response failure."); - - if (yk && !yk_close_key(yk)) - qFatal("YubiKey::initialize yk_close_key failure."); - - if (!yk_release()) - qFatal("YubiKey::initialize yk_release failure."); - - // Check response - // Our Secret Key! Shhh... - const uint8_t key[YUBIKEY_KEY_SIZE] = {0xe7, 0x32, 0xdf, 0x49, 0xf3, 0x87, 0xe6, 0x89, 0x04, 0xd2, 0x03, 0x6a, 0x59, 0xad, 0xb7, 0x2f}; - yubikey_token_st out; - yubikey_parse(output_buf, key, &out); - - // Our Private Identity! Shhh... - uint8_t uid[YUBIKEY_UID_SIZE] = {0x21, 0x92, 0x78, 0x11, 0x55, 0x8a}; - if ((uid[0] != (out.uid[0] ^ challenge[0])) || - (uid[1] != (out.uid[1] ^ challenge[1])) || - (uid[2] != (out.uid[2] ^ challenge[2])) || - (uid[3] != (out.uid[3] ^ challenge[3])) || - (uid[4] != (out.uid[4] ^ challenge[4])) || - (uid[5] != (out.uid[5] ^ challenge[5]))) - qFatal("Invalid license."); - } - - void finalize() const - { - // Nothing to do - } -}; - -MM_REGISTER(Initializer,YubiKey,"") - -#include "yubico.moc" diff --git a/share/openbr/cmake/FindCT8.cmake b/share/openbr/cmake/FindCT8.cmake deleted file mode 100644 index 2b52560..0000000 --- a/share/openbr/cmake/FindCT8.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# ================================================================ -# The CT8 CMake configuration file -# -# Usage from an external project: -# In your CMakeLists.txt, add these lines: -# -# find_package(CT8 REQUIRED) -# target_link_libraries(MY_TARGET ${CT8_LIBS}) -# ================================================================ - -set(CT8_DIR "CT8_DIR-NOTFOUND" CACHE PATH "Cognitec FaceVACS 8.x directory") - - -if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(ARCH_STRING x86_64) -else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(ARCH_STRING x86_32) -endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - -if(DEFINED MSVC80) - set(COMP_DIR_EXT "msc_8.0-ipp_crtdll") -elseif(DEFINED MSVC90) - set(COMP_DIR_EXT "msc_9.0-ipp_crtdll") -elseif(DEFINED MSVC10) - set(COMP_DIR_EXT "msc_10.0-ipp_crtdll") -elseif(CMAKE_HOST_APPLE) - set(COMP_DIR_EXT "gcc-4.2-ipp") -else() - set(COMP_DIR_EXT "gcc-4.3-ipp") -endif() - -set(CT8_DIR_LIB ${CT8_DIR}/lib/${ARCH_STRING}/${COMP_DIR_EXT} ) -set(CT8_LIBRARY_RELEASE libfrsdk-8.6.0) -set(CT8_LIBRARY_DEBUG libfrsdk-8.6.0d) - -include_directories(${CT8_DIR}/include) -link_directories(${CT8_DIR_LIB} ${CT8_DIR_LIB}_g) diff --git a/share/openbr/cmake/FindFST3.cmake b/share/openbr/cmake/FindFST3.cmake deleted file mode 100644 index b107bff..0000000 --- a/share/openbr/cmake/FindFST3.cmake +++ /dev/null @@ -1,4 +0,0 @@ -find_path(FST3_DIR _src_criteria/classifier.hpp ${CMAKE_SOURCE_DIR}/3rdparty/*) -mark_as_advanced(FST3_DIR) -include_directories(${FST3_DIR}/_src_criteria ${FST3_DIR}/_src_dataio ${FST3_DIR}/_src_global ${FST3_DIR}/_src_search) -set(FST3_SRC ${FST3_DIR}/_src_global/global.cpp) diff --git a/share/openbr/cmake/FindPP4.cmake b/share/openbr/cmake/FindPP4.cmake deleted file mode 100644 index bea3d42..0000000 --- a/share/openbr/cmake/FindPP4.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# ================================================================ -# The PP4 CMake configuration file -# -# Usage from an external project: -# In your CMakeLists.txt, add these lines: -# -# find_package(PP4 REQUIRED) -# target_link_libraries(MY_TARGET ${PP4_LIBS}) -# ================================================================ - -find_path(PP4_DIR include/pittpatt_nc_sdk.h ${CMAKE_SOURCE_DIR}/3rdparty/*) -include_directories(${PP4_DIR}/include) -link_directories(${PP4_DIR}/lib) -set(PP4_LIBS pittpatt_nc_sdk - pittpatt_raw_image - pittpatt_raw_image_io - pittpatt_recognition_core - pittpatt_video_io) diff --git a/share/openbr/cmake/FindTopSurf.cmake b/share/openbr/cmake/FindTopSurf.cmake deleted file mode 100644 index 361fc6b..0000000 --- a/share/openbr/cmake/FindTopSurf.cmake +++ /dev/null @@ -1,5 +0,0 @@ -find_path(TOPSURF_DIR topsurf/topsurf.h ${CMAKE_SOURCE_DIR}/3rdparty/*) -mark_as_advanced(TOPSURF_DIR) -include_directories(${TOPSURF_DIR}) -aux_source_directory(${TOPSURF_DIR}/topsurf TOPSURF_SRC) -aux_source_directory(${TOPSURF_DIR}/topsurf/flann TOPSURF_FLANN_SRC) diff --git a/share/openbr/cmake/FindYubiKey.cmake b/share/openbr/cmake/FindYubiKey.cmake deleted file mode 100644 index 8eb4bab..0000000 --- a/share/openbr/cmake/FindYubiKey.cmake +++ /dev/null @@ -1,15 +0,0 @@ -find_path(YUBIKEY_DIR yubikey.h ${CMAKE_SOURCE_DIR}/3rdparty/*) -mark_as_advanced(YUBIKEY_DIR) -include_directories(${YUBIKEY_DIR}) -if(MSVC) - include_directories(${YUBIKEY_DIR}/stdbool) -endif() - -if(NOT TARGET yubikey) - set(YUBIKEY_SRC ${YUBIKEY_DIR}/ykaes.c ${YUBIKEY_DIR}/ykcrc.c ${YUBIKEY_DIR}/ykhex.c ${YUBIKEY_DIR}/ykmodhex.c ${YUBIKEY_DIR}/yktoken.c) - if(WIN32) - set_source_files_properties(${YUBIKEY_SRC} PROPERTIES LANGUAGE CXX) - endif() -endif() - -set(YUBIKEY_LICENSE ${YUBIKEY_DIR}/COPYING) diff --git a/share/openbr/cmake/FindpHash.cmake b/share/openbr/cmake/FindpHash.cmake deleted file mode 100644 index f6d3166..0000000 --- a/share/openbr/cmake/FindpHash.cmake +++ /dev/null @@ -1,4 +0,0 @@ -find_path(PHASH_DIR src/pHash.h ${CMAKE_SOURCE_DIR}/3rdparty/*) -mark_as_advanced(PHASH_DIR) -include_directories(${PHASH_DIR} ${PHASH_DIR}/src) -set(PHASH_SRC ${PHASH_DIR}/src/pHash.cpp ${PHASH_DIR}/src/ph_fft.c)