Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions python_nbis/bozorth.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* bozorth.i */
%module bozorth
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}
%include "typemaps.i"
%include "bz_comon.i"

Expand All @@ -21,9 +24,9 @@
int i;
for(i = 0; i < xyt_s.nrows; i++){
dict = PyList_GetItem($input, (Py_ssize_t)i);
xyt_s.xcol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AS_LONG(PyDict_GetItem(dict, llaveX)) : 0;
xyt_s.ycol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AS_LONG(PyDict_GetItem(dict, llaveY)) : 0;
xyt_s.thetacol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AS_LONG(PyDict_GetItem(dict, llaveT)) : 0;
xyt_s.xcol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AsLong(PyDict_GetItem(dict, llaveX)) : 0;
xyt_s.ycol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AsLong(PyDict_GetItem(dict, llaveY)) : 0;
xyt_s.thetacol[i] = PyDict_Contains(dict, llaveX) ? (int)PyInt_AsLong(PyDict_GetItem(dict, llaveT)) : 0;
}
}else{
printf("Bozorth: Received invalid object to build xyt_struct");
Expand Down
11 changes: 7 additions & 4 deletions python_nbis/lfs.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* lfs.i */
%module lfs
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}
%include "bz_comon.i"

%apply int *OUTPUT { int * };
Expand Down Expand Up @@ -37,7 +40,7 @@
}
%typemap(argout) MINUTIAE ** {
printf("\nReturning %d minutia using %d adress space...\n%ld\n", (**$1).num, (**$1).alloc, (**$1).num*sizeof(MINUTIAE));
$result = SWIG_Python_AppendOutput(resultobj, PyString_FromStringAndSize((const char*)(*$1), (**$1).alloc));
$result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), (**$1).alloc));

FILE *fp;
if((fp = fopen("out/minutiaeBefore.bin", "wb")) == (FILE *)NULL){
Expand Down Expand Up @@ -78,7 +81,7 @@
$1 = &oIntP;
}
%typemap(argout) (int **){
// $result = SWIG_Python_AppendOutput(resultobj, PyString_FromStringAndSize((const char*)(*$1), *$2));
// $result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), *$2));
}
%typemap(in,numinputs=0) int * (int oInt){
$1 = &oInt;
Expand All @@ -91,15 +94,15 @@
}
%typemap(argout) (unsigned char **){
printf("Returning char **");
// $result = SWIG_Python_AppendOutput(resultobj, PyString_FromStringAndSize((const char*)(*$1), *$2));
// $result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), *$2));
}

%typemap(in,numinputs=0) LFSPARMS *{
$1 = &lfsparms_V2;
}
%typemap(argout) (LFSPARMS *){
printf("Returning LFSPARMS\n");
// $result = SWIG_Python_AppendOutput(resultobj, PyString_FromStringAndSize((const char*)(*$1), *$2));
// $result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), *$2));
}

%{
Expand Down
3 changes: 3 additions & 0 deletions python_nbis/nfiq.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* nfiq.i */
%module nfiq
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}
%include "typemaps.i"

%apply int *OUTPUT { int * };
Expand Down
27 changes: 14 additions & 13 deletions python_nbis/test-pyNBIS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import array
import wsq
Expand Down Expand Up @@ -34,41 +35,41 @@
depth = 8
ppi = 500

print "\n\nTesting NFIQ:"
print("\n\nTesting NFIQ:")
result = nfiq.comp_nfiq(huella, w, h, depth, depth)
print "Scan quality from pyNBIS: ", result, " vs quality from nfiq: "
print("Scan quality from pyNBIS: ", result, " vs quality from nfiq: ")
call(["../install_dir/bin/nfiq", "-d", huella_raw, "-raw", "%d,%d,%d"%(w, h,depth)])

if debug:
print "Debug -> executing NFIQ"
print "../install_dir/bin/nfiq", "-d", huella_raw, "-raw", "%d,%d,%d"%(w, h,depth)
print("Debug -> executing NFIQ")
print("../install_dir/bin/nfiq", "-d", huella_raw, "-raw", "%d,%d,%d"%(w, h,depth))


print "\n\nTesting WSQ codification:"
result = wsq.wsq_encode_mem(bitrate, huella, w, h, depth, ppi, "")
print result[:2]
print("\n\nTesting WSQ codification:")
result = wsq.wsq_encode_mem(bitrate, huella, w, h, depth, ppi, b"")
print(result[:2])
with open(huella_raw.split(".")[0]+"_py.wsq", "wb") as raw_file:
raw_file.write(result[2])
call(["../install_dir/bin/cwsq", "%f"%bitrate, "wsq", huella_raw, "-raw_in", "%d,%d,%d,%d"%(w, h, depth, ppi), "/dev/null"])
#TODO: Compare MD5 Sum and output https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file

if debug:
print "Debug -> executing WSQ"
print "../install_dir/bin/cwsq", "%f"%bitrate, "wsq", huella_raw, "-raw_in", "%d,%d,%d,%d"%(w, h, depth, ppi), "/dev/null"
print("Debug -> executing WSQ")
print("../install_dir/bin/cwsq", "%f"%bitrate, "wsq", huella_raw, "-raw_in", "%d,%d,%d,%d"%(w, h, depth, ppi), "/dev/null")

print "\n\nTesting MINDTCT"
print("\n\nTesting MINDTCT")
#Note: We don't need to use WSQ to extract minutiae!!

salida = lfs.get_minutiae(huella, w, h, depth, ppi)
lfs.write_minutiae_XYTQ("out/testMINDTCTpy.xyt", lfs.NIST_INTERNAL_XYT_REP, salida[1], w, h)
lfs.write_minutiae_XYTQ("out/testMINDTCTpy.xyt".encode('utf-8'), lfs.NIST_INTERNAL_XYT_REP, salida[1], w, h)
# lfs.free_minutiae(salida[1])
#TODO: Run OS mindtct and compare output

print "\n\nTesting BOZORTH"
print("\n\nTesting BOZORTH")
xyt1 = lfs.get_XYT(lfs.NIST_INTERNAL_XYT_REP, huella, w, h, depth, ppi)
xyt2 = lfs.get_XYT(lfs.NIST_INTERNAL_XYT_REP, huella2, w, h, depth, ppi)

[match, xyt1, xyt2] = bozorth.bozorth_main(xyt1, xyt2)
#TODO: Run OS bozorth and compare output

print "Match:", match
print("Match:", match)
42 changes: 42 additions & 0 deletions python_nbis/test-wsq_decode_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
import wsq

from PIL import Image

from subprocess import call


huella = "dedo9"

with open(huella + '.wsq', "rb") as wsq_file:
print("\n\nTesting WSQ decodification:")

wsq_file.seek(0, os.SEEK_END)
size = wsq_file.tell()
wsq_file.seek(0, os.SEEK_SET)
result = wsq.wsq_decode_mem(wsq_file.read(), size)
wsq = {
'odata': result[6],
'ow': result[5],
'oh': result[4],
'od': result[3],
'oppi': result[2],
'loosyflag': result[1],
'wsq_decode_mem': result[0],
}
# print(wsq)

with open(huella + ".dwsq_py.raw", "wb") as raw_file:
raw_file.write(wsq['odata'])

# call(["../install_dir/bin/cwsq", "2.25", "wsq", huella + ".dwsq_py.raw", "-raw_in", "%d,%d,%d,%d"%(wsq['ow'], wsq['oh'], wsq['od'], wsq['oppi']), "/dev/null"])

call(["../install_dir/bin/dwsq", "raw", huella + '.wsq', "-raw_out"])
img = Image.frombuffer('L', [wsq['ow'], wsq['oh']], wsq['odata'], "raw", 'L', 0, 1)
img.show()

# TODO: Compare MD5 Sum and output https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
29 changes: 26 additions & 3 deletions python_nbis/wsq.i
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
/* wsq.i */
%module wsq
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}
%include "typemaps.i"

%apply char* {unsigned char*};

%typemap(in) unsigned char* = char*;

%typemap(in,numinputs=0) (unsigned char **, int *)(unsigned char *odata, int * olen){
$1 = &odata;
$2 = &olen;
$1 = (unsigned char **)&odata;
$2 = (int *)&olen;
}
%typemap(argout) (unsigned char **, int *){
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$2)));
$result = SWIG_Python_AppendOutput(resultobj, PyString_FromStringAndSize((const char*)(*$1), *$2));
$result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), *$2));
}

%typemap(in,numinputs=0) (unsigned char **, int *, int *, int *, int *, int *)(unsigned char *odata, int *ow, int *oh, int *od, int *oppi, int *loosyflag){
$1 = (unsigned char **)&odata;
$2 = (int *)&ow;
$3 = (int *)&oh;
$4 = (int *)&od;
$5 = (int *)&oppi;
$6 = (int *)&loosyflag;
}
%typemap(argout) (unsigned char **, int *, int *, int *, int *, int *){
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$6)));
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$5)));
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$4)));
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$3)));
$result = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*$2)));
$result = SWIG_Python_AppendOutput(resultobj, PyBytes_FromStringAndSize((const char*)(*$1), ((*$2)*(*$3))));
}

%{
Expand All @@ -23,3 +43,6 @@ int debug=0;
%include "wsq.h"
//extern int wsq_encode_mem(unsigned char **, int *, const float, unsigned char *,
// const int, const int, const int, const int, char *);
//extern int wsq_decode_mem(unsigned char **, int *, int *, int *, int *, int *,
// unsigned char *, const int);