Anonymizer  4.0
SDK for anonymization of human faces and licence plates in images.
 All Data Structures Functions Variables Typedefs Groups Pages
example-files.cpp

This is an example of how to use the Anonymizer library. This example shows how to explicitly link anonymizer library and run anonymization of an image. Example uses default AnParams parameters

/* **************************************************************** */
/* **************************************************************** */
/* * * */
/* * Anonymizer example console application * */
/* * This example shows how to link Anonymizer library, * */
/* * initialize it and run anonymization of image file. * */
/* * * */
/* * use(Windows): example.exe example_img.jpg * */
/* * use(Linux) : ./example example_img.jpg * */
/* * * */
/* * ------------------------------------------------------------ * */
/* * * */
/* * Eyedea Recognition, Ltd. (C) 2013, Mar 6th * */
/* * * */
/* * Contact: * */
/* * web: http://www.eyedea.cz * */
/* * email: info@eyedea.cz * */
/* * * */
/* **************************************************************** */
/* **************************************************************** */
#include <string>
using namespace std;
#include <explink.h> /* multi-platfoprm explicit linking macros */
#include <Anonymizer.h> /* Anonymizer API */
#define ANONYMIZER_SDK_DIR "../../AnonymizerSDK/"
#define ANONYMIZER_LIB ANONYMIZER_SDK_DIR "/lib/" LIB_PREFFIX "anonymizer.unsecured-" LIB_TARGET LIB_EXT
int main (int argc, const char ** argv)
{
string output = "image.jpg";
const string outputOpt = "-o=";
size_t outputOptLen = outputOpt.length();
const string helpOpt = "--help";
size_t helpOptLen = helpOpt.length();
string input;
/* ////////////////////////////////////////////////////////// */
/* Reading input parameters */
/* */
for( int i = 1; i < argc; i++ )
{
int res = 0;
if( outputOpt.compare( 0, outputOptLen, argv[i], outputOptLen ) == 0 )
output.assign( argv[i] + outputOptLen);
else if( (res = helpOpt.compare( 0, helpOptLen, argv[i], helpOptLen )) == 0 ){
printf("USAGE: %s [options] filename\n"
" options: -o=filename sets the output filename for anonymized image\n"
"\nEXAMPLE:\n ./%s example_img.jpg\n", argv[0], argv[0]);
return 0;
}
else if( argv[i][0] == '-' )
{
printf("WARNING: Unknown option %s\nSee `%s --help' for more information.\n",argv[i], argv[0]);
}
else
input.assign( argv[i] );
}
if( input.empty() ){
printf("ERROR: Input filename is missing.\nTry `%s --help' for more information.\n", argv[0]);
return -1;
}
/* EXPLICIT LINKING */
printf("Loading library and functions\n");
fcn_anInit fcnAnInit;
fcn_anFree fcnAnFree;
fcn_anAnonymize fcnAnAnonymize;
shlib_hnd hDll;
/* load shared library */
OPEN_SHLIB(hDll, ANONYMIZER_LIB);
if (!hDll){
printf(" library '%s' not loaded!\n", ANONYMIZER_LIB);
return -1;
}
/* link AnonymizerSDK functions */
LOAD_SHFCN(fcnAnInit, fcn_anInit, hDll, "anInit");
LOAD_SHFCN(fcnAnFree, fcn_anFree, hDll, "anFree");
LOAD_SHFCN(fcnAnAnonymize, fcn_anAnonymize, hDll, "anAnonymize");
if (!fcnAnInit || !fcnAnFree || !fcnAnAnonymize){
printf(" Loading Anonymizer functions failed!\n");
return -1;
}
printf(" ... done\n");
/* AnonymizerSDK API - Anonymizer initialization. Inputs are path to SDK package, configuration filename (default config.ini) */
void *pState; /* pointer to sdk state */
printf("Anonymizer initialization:\n");
if (!(pState = fcnAnInit((char*)ANONYMIZER_SDK_DIR, NULL)) ){
printf("failed.\n");
return -1;
}else
printf(" ... done.\n");
/* run anonymization - if anonymization parameters are NULL, default values are used. */
printf("Anonymization\n");
if (fcnAnAnonymize((char*)input.c_str(),(char*)output.c_str(),NULL,pState)!=0){
printf(" ... FAILED!\n");
fcnAnFree(pState);
return -1;
}else
printf(" ... done.\n");
/* free Anonymizer state */
printf("Cleaning up\n");
fcnAnFree(pState);
/* free loaded library */
FREE_LIB(hDll);
printf(" ... done.\n");
return 0;
}