Commit b8ba2990e2ae36f092e9722a416c20c0332197cf
1 parent
8cc44c70
forgot to commit this
Showing
1 changed file
with
55 additions
and
0 deletions
app/examples/face_recognition_train.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2012 The MITRE Corporation * | |
| 3 | + * * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | + * you may not use this file except in compliance with the License. * | |
| 6 | + * You may obtain a copy of the License at * | |
| 7 | + * * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | + * * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software * | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | + * See the License for the specific language governing permissions and * | |
| 14 | + * limitations under the License. * | |
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | + | |
| 17 | +/*! | |
| 18 | + * \ingroup cli | |
| 19 | + * \page cli_face_recognition_train Face Recognition Train | |
| 20 | + * \ref cpp_face_recognition_train "C++ Equivalent" | |
| 21 | + * \code | |
| 22 | + * $ br -algorithm 'Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(128,128,0.33,0.45)+(Grid(10,10)+SIFTDescriptor(12)+ByRow)/(Blur(1.1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)+LBP(1,2)+RectRegions(8,8,6,6)+Hist(59))+PCA(0.95)+Normalize(L2)+Dup(12)+RndSubspace(0.05,1)+LDA(0.98)+Cat+PCA(0.95)+Normalize(L1)+Quantize:NegativeLogPlusOne(ByteL1)' -train ../data/ATT/img FaceRecognitionATT | |
| 23 | + * \endcode | |
| 24 | + */ | |
| 25 | + | |
| 26 | +//! [face_recognition_train] | |
| 27 | +#include <openbr/openbr_plugin.h> | |
| 28 | + | |
| 29 | +int main(int argc, char *argv[]) | |
| 30 | +{ | |
| 31 | + br::Context::initialize(argc, argv); | |
| 32 | + | |
| 33 | + const QString trainedModelFile = "FaceRecognitionATT"; | |
| 34 | + if (QFile(trainedModelFile).exists()) | |
| 35 | + return 0; // Already trained | |
| 36 | + | |
| 37 | + br::Globals->algorithm = "Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(128,128,0.33,0.45)+(Grid(10,10)+SIFTDescriptor(12)+ByRow)/(Blur(1.1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)+LBP(1,2)+RectRegions(8,8,6,6)+Hist(59))+PCA(0.95)+Normalize(L2)+Dup(12)+RndSubspace(0.05,1)+LDA(0.98)+Cat+PCA(0.95)+Normalize(L1)+Quantize:NegativeLogPlusOne(ByteL1)"; | |
| 38 | + // br::Globals->algorithm = "4SF"; // Equally valid alternative. "4SF" is the abbreviation, see openbr/plugins/algorithms.cpp | |
| 39 | + | |
| 40 | + // Note the structure of the `../data/ATT/img` training data: | |
| 41 | + // - Subdirectory for each person | |
| 42 | + // - Multiple images per person | |
| 43 | + // Run `scripts/downloadDatasets.sh` to obtain these images if you haven't already. | |
| 44 | + const QString trainingData = "../data/ATT/img"; | |
| 45 | + | |
| 46 | + // After training completes you can use `FaceRecognitionATT` like `FaceRecognition`: | |
| 47 | + // $ br -algorithm FaceRecognitionATT | |
| 48 | + // provided the `FaceRecognitionATT` file is in your current working directory or in `share/openbr/models/algorithms`. | |
| 49 | + printf("Note: Training will take at least a few minutes to complete.\n"); | |
| 50 | + br::Train(trainingData, trainedModelFile); | |
| 51 | + | |
| 52 | + br::Context::finalize(); | |
| 53 | + return 0; | |
| 54 | +} | |
| 55 | +//! [face_recognition_train] | ... | ... |