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
#include <stdio.h>
#include <string>
using namespace std;
#include <er_explink.h>
#include <Anonymizer.h>
#define ANONYMIZER_SDK_DIR "../../AnonymizerSDK/"
#define ANONYMIZER_LIB ANONYMIZER_SDK_DIR "/lib/" ER_LIB_PREFIX "anonymizer-" ER_LIB_TARGET ER_LIB_EXT
#define ANONYMIZER_INI "config.ini"
int main (int argc, const char ** argv)
{
string output = "image_anonymized.jpg";
const string outputOpt = "-o=";
size_t outputOptLen = outputOpt.length();
const string helpOpt = "--help";
size_t helpOptLen = helpOpt.length();
string input = "../../data/image.jpg";
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"
" filename: input image filename, default ../../data/image.jpg\n"
"\nEXAMPLE:\n %s\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;
}
printf("Loading library and functions\n");
shlib_hnd hDll;
ER_OPEN_SHLIB(hDll, ANONYMIZER_LIB);
if (!hDll){
printf(" library '%s' not loaded!\n", ANONYMIZER_LIB);
return -1;
}
ER_LOAD_SHFCN(fcnAnInit,
fcn_anInit, hDll,
"anInit");
ER_LOAD_SHFCN(fcnAnFree,
fcn_anFree, hDll,
"anFree");
if (!fcnAnInit || !fcnAnFree || !fcnAnAnonymize || !fcnAnVersion || !fcnAnGetErrorMsg){
printf(" Loading Anonymizer functions failed!\n");
return -1;
}
printf(" ... done\n\n");
printf("Loaded %s\n\n", fcnAnVersion(0));
int ern;
printf("Anonymizer initialization:\n");
if ((ern = fcnAnInit((char*)ANONYMIZER_SDK_DIR, (char*)ANONYMIZER_INI, &state)) != 0) {
printf("failed.\n%s",fcnAnGetErrorMsg(ern));
return -1;
}
else
printf(" ... done.\n");
printf("Anonymization\n");
if (fcnAnAnonymize((char*)input.c_str(),(char*)output.c_str(),NULL,state)!=0){
printf(" ... FAILED!\n");
fcnAnFree(state);
return -1;
}else
printf(" ... done.\n");
printf("Cleaning up\n");
fcnAnFree(state);
ER_FREE_LIB(hDll);
printf(" ... done.\n");
return 0;
}