-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFingerPrint.java
More file actions
148 lines (116 loc) · 3.99 KB
/
FingerPrint.java
File metadata and controls
148 lines (116 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import jlibfprint.*;
import java.io.*;
import java.util.*;
public class FingerPrint {
protected static HashMap<String, JlibFprint.fp_print_data> _print_data;
public static void syntax() {
System.out.println("Syntax:");
System.out.println();
System.out.println("FingerPrint enroll <name> - Enrolls the person named");
System.out.println("FingerPrint verify - Verifies a print and tells you who it belongs to");
System.exit(1);
}
public static void main(String[] args) {
if (args.length < 1)
syntax();
_print_data = read_from_files();
if (args[0].equals("enroll") && args.length < 2)
syntax();
else if (args[0].equals("enroll"))
enroll(args[1]);
if (args[0].equals("verify"))
verify((args.length > 1));
}
public static JlibFprint.fp_print_data get_print(String prefix, boolean repeat) {
JlibFprint jlibfprint = new JlibFprint();
boolean broked = false;
JlibFprint.fp_print_data print11 = null;
JlibFprint.fp_print_data print12 = null;
do {
if (broked)
System.err.println("Sorry, they didn't match. Try again!\n");
try {
System.out.println(prefix+" print please");
print11 = jlibfprint.enroll_finger();
if (repeat) {
System.out.println(prefix+" print again please");
print12 = jlibfprint.enroll_finger();
broked = (JlibFprint.img_compare_print_data(print11, print12) < JlibFprint.BOZORTH_THRESHOLD);
}
else {
broked = false;
}
}
catch (JlibFprint.EnrollException e) {
broked = true;
}
} while (broked);
return print11;
}
public static void enroll(String name) {
JlibFprint.fp_print_data print1 = get_print("First", true);
JlibFprint.fp_print_data print2 = get_print("Second", true);
serialize_to_file(name+"-1", print1);
serialize_to_file(name+"-2", print2);
}
public static void verify(boolean debug) {
// Get a print to compare
JlibFprint.fp_print_data fpd = get_print("Your", false);
if (fpd != null) {
// Loop HashMap and compare with each print
Iterator it = _print_data.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
JlibFprint.fp_print_data compare = (JlibFprint.fp_print_data)entry.getValue();
int matchValue = JlibFprint.img_compare_print_data(fpd, compare);
if (debug) {
System.out.println("Print compares to "+entry.getKey()+" with a Bozorth value of "+matchValue+" (threshold = "+JlibFprint.BOZORTH_THRESHOLD+")");
}
if (matchValue > JlibFprint.BOZORTH_THRESHOLD) {
String name = (String)entry.getKey();
String[] name_split = name.split("-");
System.out.println("This print belongs to " + name_split[0]);
return;
}
}
}
System.out.println("No match found");
}
public static void serialize_to_file(String name, JlibFprint.fp_print_data fpd) {
try {
FileOutputStream fout = new FileOutputStream("prints/"+name+".ser");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(fpd);
}
catch (IOException e) {
System.err.println("Failed to write to prints/"+name+".ser");
}
}
public static HashMap<String, JlibFprint.fp_print_data> read_from_files() {
HashMap<String, JlibFprint.fp_print_data> rtn = new HashMap<String, JlibFprint.fp_print_data>();
File dir = new File("prints");
for (File child : dir.listFiles()) {
// Skip dot files
if (child.getName().charAt(0) == '.') {
continue;
}
try {
// Get the name from the file
String name = child.getName().split("\\.")[0];
// Get the object from the file
InputStream file = new FileInputStream("prints/"+child.getName());
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream(buffer);
JlibFprint.fp_print_data data = (JlibFprint.fp_print_data)input.readObject();
rtn.put(name, data);
}
catch(ClassNotFoundException e) {
System.err.println("Failed to deserialize as class wasn't found");
}
catch(IOException e) {
System.err.println("Failed to read file prints/"+child.getName());
}
}
return rtn;
}
}