Skip to content
Commits on Source (22)
......@@ -2,7 +2,6 @@
# -*- coding: UTF-8 -*-
import datetime
import fuckit
import inspect
import json
import os
......@@ -72,7 +71,7 @@ class NIST( object ):
To get and set data, use the :func:`~NIST.traditional.NIST.get_field`
and :func:`~NIST.traditional.NIST.set_field()` functions.
"""
debug.info( "Initialization of the NIST object" )
debug.debug( "Initialization of the NIST object" )
self.stdver = ""
......@@ -161,7 +160,7 @@ class NIST( object ):
>>> n
NIST object, Type-01, Type-02, Type-09, Type-13
"""
debug.info( "Reading from file : %s" % infile )
debug.debug( "Reading from file : %s" % infile )
self.fileuri = infile
self.filename = os.path.splitext( os.path.basename( infile ) )[ 0 ]
......@@ -536,7 +535,7 @@ class NIST( object ):
02.002 IDC: 0
02.004 : ...
"""
debug.info( "Dumping NIST" )
debug.debug( "Dumping NIST" )
self.clean()
......@@ -671,7 +670,7 @@ class NIST( object ):
* Check the IDC field for every ntype (fields x.002)
* Reset all lengths (fields x.001)
"""
debug.info( "Cleaning the NIST object" )
debug.debug( "Cleaning the NIST object" )
# Delete all empty data.
for ntype in self.get_ntype():
......@@ -767,8 +766,10 @@ class NIST( object ):
>>> n.set_field( "1.002", "0300" )
"""
if value == None:
with fuckit:
try:
self.delete_tag( tag, idc )
except:
pass
return
......@@ -1167,3 +1168,11 @@ class NIST( object ):
content is the same).
"""
return deepcopy( self )
def is_initialized( self ):
try:
self.get_field( "1.003" )
return True
except:
return False
......@@ -31,7 +31,7 @@ voidType = {
5: '1',
6: '',
7: '',
8: '1',
8: '0',
},
9: {
......@@ -53,7 +53,7 @@ voidType = {
5: '',
6: '',
7: '',
8: '1',
8: '0',
9: '',
10: '',
11: 'NONE',
......
......@@ -8,8 +8,6 @@ from math import cos, pi, sin
from PIL import Image, ImageDraw, ImageFont, ImageOps, ImageColor
from scipy.spatial.qhull import ConvexHull
import base64
import fuckit
import os
import numpy as np
......@@ -110,7 +108,7 @@ class NISTf( NIST_traditional ):
>>> mark2 = mark.get()
>>> mark2.clean()
"""
debug.info( "Cleaning the NIST object" )
debug.debug( "Cleaning the NIST object" )
# Check the minutiae
if 9 in self.get_ntype():
......@@ -745,10 +743,12 @@ class NISTf( NIST_traditional ):
data = lstTo012( data )
if data == "":
with fuckit:
try:
self.delete( "9.012", idc )
self.delete( "9.010", idc )
except:
pass
return 0
if isinstance( data, str ):
......@@ -1274,7 +1274,7 @@ class NISTf( NIST_traditional ):
#
############################################################################
def get_latent( self, format = 'RAW', idc = -1 ):
def get_latent( self, format = 'PIL', idc = -1 ):
"""
Return the image in the format passed in parameter (RAW or PIL).
......@@ -1335,8 +1335,10 @@ class NISTf( NIST_traditional ):
idc = self.checkIDC( 13, idc )
res = self.get_resolution( idc )
with fuckit:
try:
os.makedirs( os.path.dirname( f ) )
except:
pass
self.get_latent( "PIL", idc ).save( f, dpi = ( res, res ) )
return os.path.isfile( f )
......@@ -1362,8 +1364,10 @@ class NISTf( NIST_traditional ):
idc = self.checkIDC( 13, idc )
res = self.get_resolution( idc )
with fuckit:
try:
os.makedirs( os.path.dirname( f ) )
except:
pass
self.get_latent_annotated( idc ).save( f, dpi = ( res, res ) )
return os.path.isfile( f )
......@@ -1395,14 +1399,20 @@ class NISTf( NIST_traditional ):
img = options.get( "img", self.get_latent( 'PIL', idc ) )
res = self.get_resolution( idc )
with fuckit:
try:
img = self.annotate( img, self.get_minutiae( idc = idc, **options ), "minutiae", res, idc, **options )
except:
pass
with fuckit:
try:
img = self.annotate( img, self.get_cores( idc ), "center", res, idc, **options )
except:
pass
with fuckit:
try:
img = self.annotate( img, self.get_delta( idc ), "delta", res, idc, **options )
except:
pass
return img
......@@ -1953,14 +1963,20 @@ class NISTf( NIST_traditional ):
img = self.get_print( 'PIL', idc )
res = self.get_resolution( idc )
with fuckit:
try:
img = self.annotate( img, self.get_minutiae( idc = idc ), "minutiae", res, idc )
except:
pass
with fuckit:
try:
img = self.annotate( img, self.get_cores( idc ), "center", res, idc )
except:
pass
with fuckit:
try:
img = self.annotate( img, self.get_delta( idc ), "delta", res, idc )
except:
pass
return img
......@@ -1996,7 +2012,7 @@ class NISTf( NIST_traditional ):
"""
self.get_print_diptych( idc ).save( f )
def set_print( self, image = None, res = None, size = ( 512, 512 ), format = "WSQ", idc = -1, **options ):
def set_print( self, image = None, res = None, size = ( 512, 512 ), format = "RAW", idc = -1, **options ):
"""
Function to set an print image to the 4.999 field, and set the size.
......@@ -2094,9 +2110,9 @@ class NISTf( NIST_traditional ):
#
############################################################################
def get_image( self, format = "PIL", idc = -1 ):
def get_image( self, *args, **kwargs ):
"""
Get the appropriate image (latent fingermark, of fingerprint).
Get the appropriate image (latent fingermark, fingerprint or palmair image).
:param format: Format of the returened image.
:type format: str
......@@ -2104,6 +2120,9 @@ class NISTf( NIST_traditional ):
:param idc: IDC value.
:type idc: int
:param fpc: FPC (Finger Position Code) value.
:type fpc: int
:return: Fingermark of fingerprint Image
:rtype: PIL.Image or str
......@@ -2124,13 +2143,11 @@ class NISTf( NIST_traditional ):
notImplemented
"""
ntypes = self.get_ntype()
if 13 in ntypes:
return self.get_latent( format, idc )
elif ifany( [ 4, 14 ], ntypes ):
return self.get_print( format, idc )
for f in [ self.get_latent, self.get_print, self.get_palmar ]:
try:
return f( *args, **kwargs )
except:
pass
else:
raise notImplemented
......@@ -2421,10 +2438,10 @@ class NISTf( NIST_traditional ):
card = card.resize( ( int( w * fac ), int( h * fac ) ), Image.BICUBIC )
palmpos = {
22: ( 150.4, 31.4, 200.6, 157.9 ),
24: ( 8.8, 158.2, 57.7, 287.9 ),
27: ( 58.2, 158.3, 200.6, 287.9 ),
25: ( 8.9, 31.4, 150.0, 157.8 ),
22: ( 150.4, 31.4, 200.6, 157.9 ), # Right writer's
24: ( 8.8, 158.2, 57.7, 287.9 ), # Left writer's
25: ( 8.9, 31.4, 150.0, 157.8 ), # Right palm
27: ( 58.2, 158.3, 200.6, 287.9 ), # Left palm
}
for fpc in [ 22, 24, 25, 27 ]:
......@@ -2573,6 +2590,7 @@ class NISTf( NIST_traditional ):
>>> mark = NISTf().init_latent( **params )
>>> print( mark ) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Informations about the NIST object:
Obj ID: ...
Records: Type-01, Type-02, Type-09, Type-13
Class: NISTf
<BLANKLINE>
......@@ -2629,6 +2647,7 @@ class NISTf( NIST_traditional ):
>>> pr = NISTf().init_print( **params )
>>> print( pr ) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Informations about the NIST object:
Obj ID: ...
Records: Type-01, Type-02, Type-04, Type-09
Class: NISTf
<BLANKLINE>
......@@ -2649,15 +2668,15 @@ class NISTf( NIST_traditional ):
02.002 IDC: 0
02.004 : ...
NIST Type-04 (IDC 1)
04.001 LEN: 673
04.001 LEN: 250018
04.002 IDC: 1
04.003 IMP: 3
04.004 FGP: 0
04.005 ISR: 1
04.005 ISR: 0
04.006 HLL: 500
04.007 VLL: 500
04.008 CGA: 1
04.999 : FFA0FFA8 ... 0301FFA1 (655 bytes)
04.008 CGA: 0
04.999 : FFFFFFFF ... FFFFFFFF (250000 bytes)
NIST Type-09 (IDC 0)
09.001 LEN: 00000266
09.002 IDC: 0
......@@ -2785,7 +2804,7 @@ class NISTf( NIST_traditional ):
self.set_field( "14.005", self.date, idc )
with fuckit:
try:
w, h = size
self.set_field( "14.006", w, idc )
self.set_field( "14.007", h, idc )
......@@ -2795,14 +2814,20 @@ class NISTf( NIST_traditional ):
imgdata = options.get( "img" )
self.set_field( "14.999", imgdata, idc )
except:
pass
with fuckit:
try:
fpc = options.get( "fpc" )
self.set_field( "14.013", fpc, idc )
except:
pass
with fuckit:
try:
gca = options.get( "gca" )
self.set_field( "14.011", gca, idc )
except:
pass
def add_Type15( self, idc = 1, **options ):
"""
......
......@@ -209,10 +209,9 @@ def changeFormatImage( input, outformat, **options ):
...
notImplemented: Input format not supported
>>> changeFormatImage( imgPIL, "WSQ" )
Traceback (most recent call last):
...
notImplemented: Output format not supported by PIL
>>> d = changeFormatImage( imgPIL, "WSQ" )
>>> d.startswith( "\\xff\\xa0\\xff\\xa8\\x00" )
True
"""
outformat = outformat.upper()
......@@ -225,6 +224,9 @@ def changeFormatImage( input, outformat, **options ):
buff = StringIO( input )
img = Image.open( buff )
if img.format in [ "TGA" ]:
raise Exception
except:
if string_to_hex( input[ 0 : 4 ] ) in [ "FFA0FFA4", "FFA0FFA5", "FFA0FFA6", "FFA0FFA2", "FFA0FFA8" ]:
img = RAWToPIL( WSQ().decode( input ), **options )
......
#!/usr/bin/python
# -*- coding: UTF-8 -*-
FINGER_POSITION_CODE = {
0: "unknown finger",
1: "right thumb",
2: "right index",
3: "right middel",
4: "right ring",
5: "right little",
6: "left thumb",
7: "left index",
8: "left middel",
9: "left ring",
10: "left little",
11: "plain right thumb",
12: "plain left thumb",
13: "plain right four fingers",
14: "plain left four fingers",
15: "left and right thumbs",
16: "right extra finger",
17: "left extra finger",
18: "unknown friction ridge",
19: "EJI or tip"
}
PALM_POSITION_CODE = {
20: "unknown palm",
21: "right full palm",
22: "right writer's palm",
23: "left full palm",
24: "left writer's palm",
25: "right lower palm",
26: "right upper palm",
27: "left lower palm",
28: "left upper palm",
29: "right other",
30: "left other",
31: "right interdigital",
32: "right thenar",
33: "right hypothenar",
34: "left interdigital",
35: "left thenar",
36: "left hypothenar",
37: "right grasp",
38: "left grasp",
81: "right carpal delta area",
82: "left carpal delta area",
83: "right full palm, including writer's palm",
84: "left full palm, including writer's palm",
85: "right wrist bracelet",
86: "left wrist bracelet"
}
......@@ -5,8 +5,6 @@ from __future__ import division
from PIL import Image
import fuckit
from MDmisc.boxer import boxer
from MDmisc.logger import debug
from MDmisc.map_r import map_r
......@@ -113,8 +111,10 @@ try:
"""
lst = super( NISTULWLQMetric, self ).get_minutiae( format = format, idc = idc, **options )
with fuckit:
try:
lst = self.add_LQMetric_data( lst )
except:
pass
lst.set_format( format )
return lst
......
......@@ -2,6 +2,7 @@
# -*- coding: UTF-8 -*-
from collections import OrderedDict
import cStringIO
import hashlib
import os
......@@ -31,7 +32,13 @@ class NIST( NIST_Core ):
else:
self.read( p )
elif isinstance( p, ( cStringIO.OutputType ) ):
self.load( p.getvalue() )
elif isinstance( p, ( file ) ):
self.load( p.read() )
elif isinstance( p, ( NIST, dict ) ):
if isinstance( p, NIST ):
p = p.data
......@@ -58,7 +65,7 @@ class NIST( NIST_Core ):
:param data: Raw data read from file.
:type data: str
"""
debug.info( "Loading object" )
debug.debug( "Loading object" )
records = data.split( FS )
......@@ -200,7 +207,7 @@ class NIST( NIST_Core ):
:return: Binary representation of the NIST object.
:rtype: str
"""
debug.info( "Dumping NIST in binary" )
debug.debug( "Dumping NIST in binary" )
self.clean()
self.patch_to_standard()
......@@ -233,7 +240,7 @@ class NIST( NIST_Core ):
:param outfile: URI of the file to write to.
:type outfile: str
"""
debug.info( "Write the NIST object to '%s'" % outfile )
debug.debug( "Write the NIST object to '%s'" % outfile )
if not os.path.isdir( os.path.dirname( os.path.realpath( outfile ) ) ):
os.makedirs( os.path.dirname( os.path.realpath( outfile ) ) )
......
[versioneer]
VCS = git
versionfile_source = versioneer/_version.py
tag_prefix = v
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from setuptools import setup
################################################################################
#
# Version determination
#
################################################################################
try:
import versioneer
version = versioneer.get_version()
except:
version = "dev"
finally:
import os
os.chdir( os.path.split( os.path.abspath( __file__ ) )[ 0 ] )
with open( "NIST/version.py", "w+" ) as fp:
fp.write( "__version__ = '%s'" % version )
################################################################################
#
# Setup configuration
#
################################################################################
setup(
name = 'NIST',
version = version,
description = 'Python library for manipulating NIST files (Data Format for the Interchange of Fingerprint, Facial & Other Biometric Information)',
author = 'Marco De Donno',
author_email = 'Marco.DeDonno@unil.ch; mdedonno1337@gmail.com',
packages = [
'NIST',
'NIST.traditional',
'NIST.fingerprint',
'NIST.ULWLQMetric'
],
install_requires = [
'future',
'pillow',
],
)