libnbis.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "libbozorth3/bozorth.h"
  4. #include "libmindtct/lfs.h"
  5. #include "libnbis.h"
  6. /* Default {x,y,t} representation is "NIST internal", not M1 */
  7. //TODO: convert to local
  8. int m1_xyt = 0;
  9. /******************************************************************************
  10. func nbisPgmToMinutiae
  11. detect minutiae on pgm image and prepare it to use in bozorth3 algorithm
  12. input
  13. gpm - pointer to pgm image source data
  14. out
  15. xytPacked - pointer to output buffer
  16. return
  17. Negative on error
  18. count of <struct xyt_packed>
  19. ******************************************************************************/
  20. int nbisPgmToMinutiae( unsigned char* pgm, struct xyt_packed* xytPacked ){
  21. int res;
  22. int i;
  23. MINUTIAE* minutiae;
  24. int* quality_map;
  25. int* direction_map;
  26. int* low_contrast_map;
  27. int* low_flow_map;
  28. int* high_curve_map;
  29. int map_w;
  30. int map_h;
  31. unsigned char* binData;
  32. int binWidth;
  33. int binHeight;
  34. int binDepth;
  35. int inputWidth;
  36. int inputHeight;
  37. double ippmm;
  38. struct xyt_struct* xyt;
  39. struct xytq_struct xytq;
  40. inputHeight = 270;
  41. inputWidth = 144;
  42. ippmm = DEFAULT_PPI / (double)MM_PER_INCH;
  43. //minutiae detect
  44. res = get_minutiae(
  45. &minutiae, //points to a structure containing the detected minutiae
  46. &quality_map, //resulting integrated image quality map
  47. &direction_map, //resulting direction map
  48. &low_contrast_map, //resulting low contrast map
  49. &low_flow_map, //resulting low ridge flow map
  50. &high_curve_map, //resulting high curvature map
  51. &map_w, //width (in blocks) of image maps
  52. &map_h, //height (in blocks) of image maps
  53. &binData, //points to binarized image data
  54. &binWidth, //width (in pixels) of binarized image
  55. &binHeight, //height (in pixels) of binarized image
  56. &binDepth, //pixel depth (in bits) of binarized image
  57. pgm, //grayscale fingerprint image data
  58. inputWidth, //width (in pixels) of the grayscale image
  59. inputHeight, //height (in pixels) of the grayscale image
  60. 8, //pixel depth (in bits) of the grayscale image
  61. ippmm, //the scan resolution (in pixels/mm) of the grayscale image
  62. &lfsparms_V2 //parameters and thresholds for controlling LFS
  63. );
  64. if( res ){
  65. printf( "get_minutiae error: %i\n", res );
  66. return -1;
  67. }
  68. //fill xytq struct from minutiae data
  69. xytq.nrows = minutiae->num;
  70. for( i = 0; i < minutiae->num; i++ ){
  71. //lfs2m1_minutia_XYT( &xytq.xcol[i], &xytq.ycol[i], &xytq.thetacol[i], minutiae->list[i] );
  72. lfs2nist_minutia_XYT( &xytq.xcol[i], &xytq.ycol[i], &xytq.thetacol[i], minutiae->list[i], inputWidth, inputHeight );
  73. xytq.qualitycol[i] = sround( minutiae->list[i]->reliability * 100.0 );
  74. if ( i == MAX_FILE_MINUTIAE ) break;
  75. }
  76. //free unneeded data
  77. free_minutiae( minutiae );
  78. free( quality_map );
  79. free( direction_map );
  80. free( low_contrast_map );
  81. free( low_flow_map );
  82. free( high_curve_map );
  83. free( binData );
  84. //convert xytq to xyt
  85. xyt = bz_prune( &xytq );//need free()!!!
  86. if( !xyt ){
  87. printf( "bz_prune return null\n" );
  88. return -2;
  89. }
  90. //pack data
  91. for( i = 0; i < xyt->nrows; i++ ){
  92. xytPacked[i].x = xyt->xcol[i];
  93. xytPacked[i].y = xyt->ycol[i];
  94. xytPacked[i].t = xyt->thetacol[i];
  95. }
  96. res = xyt->nrows;
  97. free( xyt );
  98. return res;
  99. }
  100. /***************************************
  101. func nbisBozorth3Packed
  102. calculate match score using bozorth3
  103. return
  104. match score
  105. ***************************************/
  106. int nbisBozorth3Packed( struct xyt_packed* packedProbe, int probeCount, struct xyt_packed* packedGallery, int galleryCount ){
  107. int i;
  108. int score;
  109. struct xyt_struct probe;
  110. struct xyt_struct gallery;
  111. probe.nrows = probeCount;
  112. for( i = 0; i < probeCount; i++ ){
  113. probe.xcol[i] = packedProbe[i].x;
  114. probe.ycol[i] = packedProbe[i].y;
  115. probe.thetacol[i] = packedProbe[i].t;
  116. }
  117. gallery.nrows = galleryCount;
  118. for( i = 0; i < galleryCount; i++ ){
  119. gallery.xcol[i] = packedGallery[i].x;
  120. gallery.ycol[i] = packedGallery[i].y;
  121. gallery.thetacol[i] = packedGallery[i].t;
  122. }
  123. score = bozorth_main( &probe, &gallery );
  124. return score == QQ_OVERFLOW_SCORE ? 0 : score;
  125. }