The ✘✘✘ Signatures Developer kit has a strong modular design.
For all supported C/C++ compilers, the modules are made as a run-time
library or DLL when it is available. They can be linked into any application.
Data exchange with the calling program is implemented via related data structure XXX_Data.
In these structure, the images for recognition are required as input, with the corresponding
results returned after recognition. To call of ✘✘✘ Signatures a classifier for recognition
must be specified and initialized. This must be done so that each data structure of
✘✘✘ Signatures is firmly linked to a specific classifier.
Parameters used for finer control of the recognition process can be passed via the data structure XXX_Parm.
/****************************************************************************
*
* xxxdemo.c
*
* Sample for xxx.lib applications
*
* $Date: 17-Dec-2019 09:47 $
*
* Copyright 1993-2019 re Recognition GmbH
* Höhenstrasse 5a, 8280 Kreuzlingen, Switzerland
* +41 (0)71 6725100
* info@reRecognition.com * www.reRecognition.com
*
****************************************************************************/
#if defined(_WIN32) || defined(_WIN64)
#pragma warning(disable:4996)
#define _CRTDBG_MAP_ALLOC
#include <windows.h>
#include <io.h>
#elif defined _UNIX
#include <ncurses.h> // Ncurses library has to be installed
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#if defined(_WIN32) || defined(_WIN64)
#include <crtdbg.h>
#include <conio.h>
#endif
#include "xxx.h"
#ifndef _MAX_PATH
#define _MAX_PATH 256
#endif
#if defined(_DEBUG)
#if !defined(_UNIX)
#define ERR_EXIT(s) {printf("\nError: %s\n",s); printf("\nAny key to continue ..."); getch(); return EXIT_FAILURE;}
#else
#define ERR_EXIT(s) {printf("\nError: %s\n",s); printf("\nAny key to continue ..."); getchar(); return EXIT_FAILURE;}
#endif
#else
#define ERR_EXIT(s) {printf("\nError: %s\n",s); return EXIT_FAILURE;}
#endif
int main(int argc, char *argv[ ]) {
char ImageFileName[_MAX_PATH+1]={0}; /* file names */
char RecFileName[_MAX_PATH+1]={0};
XXX_Data xxx; /* main XXX_Data structure */
ReFileHandle file_handle;
ReImageHandle image_handle_gold, image_handle_probe;
int image_number;
/* ------ input ---------------------------------------------------------- */
/* take input file names from command line ... */
if (argc>1) strcpy(RecFileName,argv[1]);
if (argc>2) strcpy(ImageFileName,argv[2]);
/* ... or get them from the console */
#if defined(_WIN32) || defined(_WIN64) || defined(_CONSOLE)
if (argc<=2) {
if (GetPrivateFileName(RecFileName, "", OF_EXIST | OF_PROMPT, "Rec file",
"xxxdemo.sts", "files", "recfile")!=RE_SUCCESS) return EXIT_FAILURE;
printf("\n");
if (GetPrivateFileName(ImageFileName, "", OF_EXIST | OF_PROMPT, "Img file",
"xxxdemo.sts", "files", "imgfile")!=RE_SUCCESS) return EXIT_FAILURE;
printf("\n");
}
#else
{
char format[16];
FILE *fstream;
int ret; // avoid GCC warnings
sprintf(format," %%%ds",_MAX_PATH-1);
while (!*RecFileName || !(fstream=fopen(RecFileName,"r"))) {
printf("Rec file: ");
fflush(stdout);
ret = scanf(format,RecFileName);
}
fclose(fstream);
while (!*ImageFileName || !(fstream=fopen(ImageFileName,"r"))) {
printf("Img file: ");
fflush(stdout);
ret = scanf(format,ImageFileName);
}
ret = ret; // avoid GCC warnings
fclose(fstream);
}
#endif
/* ------ initialization ------------------------------------------------- */
/* suppress KADMOS error messages */
/* re_SetErrorConfig(re_GetErrorConfig() & ~RE_ERRORDISPLAY); */
/* or show KADMOS error messages */
re_SetErrorConfig(re_GetErrorConfig() | RE_ERRORDISPLAY);
/* initialize recognizer */
memset(&xxx, 0, sizeof(xxx));
strcpy(xxx.init.version, INC_XXX); /* Activate version check */
if (xxx_init(&xxx, RecFileName)!=RE_SUCCESS) ERR_EXIT("xxx_init() failed");
#if defined(_WIN32) || defined(_WIN64)
// xxx_config(&xxx); // under development
#endif
/* open image file */
file_handle = re_openimagefile(ImageFileName, "r");
if (!file_handle) ERR_EXIT("Can't open image file")
image_number = 0;
/* read the gold signature */
image_handle_gold = re_readimagefile(file_handle, image_number, &xxx.gold_image);
if (!image_handle_gold) {
if (re_GetErrorText(NULL)!=RE_SUCCESS) {
ERR_EXIT("Cant't load image");
}
else {
ERR_EXIT("Empty image file");
}
}
/* read the probe signature */
image_number++;
image_handle_probe = re_readimagefile(file_handle, image_number, &xxx.probe_image);
if (!image_handle_probe) {
if (re_GetErrorText(NULL) != RE_SUCCESS) {
ERR_EXIT("Cant't load image");
}
else {
ERR_EXIT("Empty image file");
}
}
/* ------ kernel --------------------------------------------------------- */
while (image_handle_probe) {
int i;
/* compare signatures */
if (xxx_do(&xxx)!=RE_SUCCESS) ERR_EXIT("xxx_do() failed");
/* check and display result */
printf("\n %6d platinum results: ", image_number);
for (i=0; i<PLATINUM_ALT; i++) {
if (!xxx.platinum_wchar[i][0] || xxx.platinum_wchar[i][0]==' ' || !xxx.platinum_value[i])
break;
wprintf(L"%2.2s/%-3d ", xxx.platinum_wchar[i], xxx.platinum_value[i]);
}
if (i==0) {
if (!xxx.platinum_value[0]) printf("no corresponding platinum signature");
}
printf("\n comparison value (distance) %d", xxx.comparison_value);
fflush(stdout);
re_freeimage(image_handle_probe);
re_freeimage(image_handle_gold);
image_handle_gold = re_readimagefile(file_handle, ++image_number, &xxx.gold_image);
image_handle_probe = re_readimagefile(file_handle, ++image_number, &xxx.probe_image);
}
/* ------ end ------------------------------------------------------------ */
re_closeimagefile(file_handle);
xxx_end(&xxx);
printf("\n");
#if defined(_DEBUG) && defined(_CONSOLE)
printf("\nAny key to continue ...");
#if !defined(_UNIX)
_getch();
#else
getchar();
#endif
#endif
#if defined(_WIN32) || defined(_WIN64)
_CrtDumpMemoryLeaks();
#endif
return EXIT_SUCCESS;
}