✘✘✘ Signature - Einleitung

Das ✘✘✘ Signature SDK hat einen streng modularen Aufbau. Für alle unterstützten C-Compiler dird das ✘✘✘ Signature-Modul als Library oder DLL zur Verfügung gestellt und kann so in beliebige Applikationen eingebunden werden. Der Datenaustausch erfolgt über zugeordnete Datenstrukturen XXX_Data und ReImage. In diese Strukturen müssen die zu erkennenden Bilder eingetragen werden, die Module ihrerseits füllen die Struktur mit den Resultaten. Beim Aufruf eines dieser Module muss zusätzlich festgelegt werden, welcher Klassifikator zur Erkennung herangezogen werden soll. Dies wird bei der Initialisierung festgelegt. Das heisst andererseits auch, dass eine initialisierte Struktur fest mit einem bestimmten Klassifikator verbunden ist.

Über die Datenstruktur XXX_Parm können Parameter zur feineren Steuerung des Erkennungsprozesses übergeben werden.

Demo Program xxxdemo.c

/****************************************************************************
*
*  xxxdemo.c
*
*  Sample for xxx.lib applications
*
*  $Date: 17-Dec-2019 09:47 $
*
*  Copyright 1993-2019 re Recognition GmbH 
*  Höhenstrasse 5a, 8280 Kreuzlingen, Schweiz
*  +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 XXX error messages */
  /* re_SetErrorConfig(re_GetErrorConfig() & ~RE_ERRORDISPLAY); */

                            /* or show XXX 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;

}