https://doi.org/10.5201/ipol.2019.272
Tip revision: c92e3756afa20b81ced28d0142f3e8f5e8e4f9ba authored by Software Heritage on 01 January 2017, 00:00:00 UTC
ipol: Deposit 663 in collection ipol
ipol: Deposit 663 in collection ipol
Tip revision: c92e375
facedet.cpp
/*
* Copyright (c) 2009 Silvia Ramis, Marta Ramis
* Copyright (c) 2016 Jose-Luis Lisani <joseluis.lisani@uib.es>
* Copyright (c) 2019 Jose-Luis Lisani <joseluis.lisani@uib.es>
* All rights reserved.
*
* This code was originally written by Silvia Ramis and Marta Ramis
* for their Final Project on Computer Sciences Engineering (2009)
* under the supervision of J.L. Lisani
* Some parts of the code were written by J.L. Lisani
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include "library/parser.h"
#include "library/lib_facedet.h"
//Main function: read arguments and call face detection function
//Input:
//- input image (PNG format)
//- name of folder containing learned classifiers
//- maximum number of false positives in output result
//Output:
//- raw detections after simplification (displayed in PNG image)
//- raw detections after simplification (text file)
//- detections after rejection of unstable detections and simplification (displayed in PNG image)
//- detections after rejection of unstable detections and simplification (text file)
int main(int argc, char **argv)
{
std::vector<ParStruct *> parameters;
ParStruct pInput = {(char *) "input", NULL, (char *) "input image"};
parameters.push_back(&pInput);
ParStruct pClass = {(char *) "classifiers", NULL, (char *) "folder containing learned image classifiers"};
parameters.push_back(&pClass);
ParStruct pOutput = {(char *) "output", NULL, (char *) "root name of output files"};
parameters.push_back(&pOutput);
std::vector <OptStruct *> options;
OptStruct oN = {(char *) "n:", 0, (char *) "1", NULL, (char *) "Maximum number of false positives"};
options.push_back(&oN);
OptStruct oS = {(char *) "s:", 0, (char *) "24", NULL, (char *) "Minimum size (pixels) of detected faces"};
options.push_back(&oS);
OptStruct oL = {(char *) "l:", 0, (char *) "220", NULL, (char *) "Maximum size (pixels) of detected faces"};
options.push_back(&oL);
OptStruct oZ = {(char *) "z:", 0, (char *) "1", NULL, (char *) "Size increase factor of checked subwindows (if 1 check all subwindows in size range)"};
options.push_back(&oZ);
if (!parsecmdline((char *) "facedet", (char *) "A contrario face detection", \
argc, argv, options, parameters))
return EXIT_FAILURE;
const char *namein = pInput.value;
const char *namedirclass = pClass.value;
const char *nameout = pOutput.value;
//Parameters of the method
//default value of parameter for 4th classifier (final output of detector):
float nfa2 = atof(oN.value);
//Minimum size (pixels) of detected faces: sizeMin x sizeMin
int sizeMin = atoi(oS.value);
//Maximum size (pixels) of detected faces: sizeMax x sizeMax
int sizeMax = atoi(oL.value);
//Factor of decrease/increase of zoom factors for resizing sub-windows
//to standard face size (24 x 24)
float zStep = atof(oZ.value);
//name of classifiers in namedirclass folder
char nameclass1[200];
char nameclass2[200];
char nameclass3[200];
char nameclass4[200];
sprintf(nameclass1, "%s/%s", namedirclass, "classifier5.txt");
sprintf(nameclass2, "%s/%s", namedirclass, "classifier10.txt");
sprintf(nameclass3, "%s/%s", namedirclass, "classifier80.txt");
sprintf(nameclass4, "%s/%s", namedirclass, "classifier200.txt");
//default parameters for the definition of the detection thresholds
//of the classifier
float prc1=20.0f; //parameter for 1st classifier (keep 20% best detections)
float prc2=5.0f; //parameter for 2nd classifier (keep 5% best detections)
float nfa1=100.0f;//parameter for 3rd classifier (allow up to 100 false
//positives)
//call detection function
detectfaces(namein, nameclass1, nameclass2, nameclass3, nameclass4,
nameout, sizeMin, sizeMax, zStep, prc1/100.0f, prc2/100.0f, nfa1, nfa2);
return EXIT_SUCCESS;
}