// pgm_similarity_test.c // based on bill hillhouse's test program // compares two pgm images to see how similar they are // accesses the fingerprint scanning hardware, which is assumed to // be connected to the parallel port #include #include #include #include #include #include "unixdefs.h" #include "dbiapi.h" /******************************************************************/ /* Global variables */ /******************************************************************/ /* Autodetection parameters */ DWORD DBI_AutoOT = 3500; DWORD DBI_AutoST = 3000; int DBI_AutoDT = 3; int autoframes = 0; /* our fingerprint image */ BYTE DEW_TYPE DBI_finger_data1[IMAGE_HEIGHT * IMAGE_WIDTH]; BYTE DEW_TYPE DBI_finger_data2[IMAGE_HEIGHT * IMAGE_WIDTH]; /******************************************************************/ /* Initializes the driver and sets up the screen for displaying */ /* the image. Returns 0 if error occured and non zero otherwise. */ /******************************************************************/ int Initialize(void) { double length; BYTE dark_field; DWORD dwRc; /* Initialize the driver */ if (DBI_FAST_OK != (dwRc = DBI_InitDriver(&length, &dark_field))) { fprintf(stderr, "DBI_InitDriver returned failure (%d, %d)\n", MAJOR_ERROR(dwRc), MINOR_ERROR(dwRc) ); return -1; }; /* Initialize the library */ DBI_DLLInit(length, dark_field); return 0; } /******************************************************************/ /* Shuts the driver down and frees up allocated memory for exit. */ /******************************************************************/ void Shutdown() { DBI_Close(); DBI_CloseDriver(); } /******************************************************************/ /* main body of program. Creates the greymap, initializes the */ /* driver and calls DisplayImage until we achieve a captured */ /* state. */ /******************************************************************/ int main(int argc, char *argv[]) { DDT *DDT1, *DDT2; BYTE DEW_TYPE *Image, *TempImage; int q, i, j; long score; FILE *fp; if (argc != 3){ fprintf(stderr,"Useage: %s pgm_file1 pgm_file2\n",argv[0]); exit(1); } DDT1 = (DDT *)malloc(DBI_sizeofDDT()); DDT2 = (DDT *)malloc(DBI_sizeofDDT()); Image = (BYTE DEW_TYPE *)malloc(IMAGE_WIDTH * IMAGE_HEIGHT); TempImage = (BYTE DEW_TYPE *)malloc(IMAGE_WIDTH * IMAGE_HEIGHT); if (!DDT1 || !DDT2 || !Image || !TempImage){ fprintf(stderr,"Error: malloc error\n"); exit(1); } if(Initialize()) { fprintf(stderr,"Error: Initialization failed.\n"); exit(1); } /* Read in the first image. */ if ((fp = fopen( argv[1], "rb" )) == NULL) { fprintf(stderr,"Error: Could not open file %s\n",argv[1]); goto EXIT; } fseek(fp,15,SEEK_SET); if(fread( DBI_finger_data1, (size_t)IMAGE_HEIGHT*IMAGE_WIDTH, 1, fp ) != 1) { fprintf(stderr,"Error: Could not read file %s\n", argv[1]); goto EXIT; } fclose( fp ); /* Read in the second image. */ if ((fp = fopen( argv[2], "rb" )) == NULL) { fprintf(stderr,"Error: Could not open file (%s)\n", argv[2]); goto EXIT; } fseek(fp,15,SEEK_SET); if(fread( DBI_finger_data2, (size_t)IMAGE_HEIGHT*IMAGE_WIDTH, 1, fp ) != 1) { fprintf(stderr,"Error: Could not read file %s\n", argv[2]); goto EXIT; } fclose( fp ); DBI_CharacterizeImage( DBI_finger_data1, Image, TempImage, DDT1, &q ); DBI_CharacterizeImage( DBI_finger_data2, Image, TempImage, DDT2, &q ); score = DBI_Compare( DDT1, DDT2 ); if (DBI_Multi_Dim( &score, 1, FA_1_IN_1000 ) ) { fprintf(stderr,"Authenticated with score %d\n", score); } else { fprintf(stderr,"Rejected with score %d\n", score); } fprintf(stdout,"%d\n", score); EXIT: Shutdown(); free( DDT1 ); free( DDT2 ); free( Image ); free( TempImage ); return 0; }