<dependencies>
<!-- https://mvnrepository.com/artifact/com.machinezoo.sourceafis/sourceafis -->
<dependency>
<groupId>com.machinezoo.sourceafis</groupId>
<artifactId>sourceafis</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies
public static void main(String[] args) throws IOException {
byte[] probeImage = Files.readAllBytes(Paths.get("F:\\ye\\fingerprint\\1.jpg"));
byte[] candidateImage = Files.readAllBytes(Paths.get("F:\\ye\\fingerprint\\1.jpg"));
FingerprintTemplate probe = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(probeImage));
FingerprintTemplate candidate = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(candidateImage));
double score = new FingerprintMatcher()
.index(probe)
.match(candidate);
System.out.println(score);
double threshold = 40;
boolean matches = score >= threshold;
System.out.println(matches);
}
public static void main(String[] args) throws IOException {
List<UserFingerprint> candidates = new ArrayList<>();
// 加载指纹
String path = "F:\\ye\\fingerprint";
File file = new File(path); //获取其file对象
File[] fs = file.listFiles(); //遍历path下的文件和目录,放在File数组中
for(File f:fs){ //遍历File[]数组
byte[] finger = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
FingerprintTemplate candidate = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(finger));
UserFingerprint userFingerprint = new UserFingerprint();
userFingerprint.setUserId(f.getName().split("\\.")[0]);
userFingerprint.setTemplate(candidate);
candidates.add(userFingerprint);
}
byte[] probeImage = Files.readAllBytes(Paths.get("F:\\ye\\probe\\left1.jpg"));
FingerprintTemplate probe = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(probeImage));
UserFingerprint userFingerprint = find(probe, candidates);
System.out.println(userFingerprint.getUserId());
}
static UserFingerprint find(FingerprintTemplate probe, List<UserFingerprint> candidates) {
FingerprintMatcher matcher = new FingerprintMatcher()
.index(probe);
UserFingerprint match = null;
double high = 0;
for (UserFingerprint candidate : candidates) {
double score = matcher.match(candidate.template);
if (score > high) {
high = score;
match = candidate;
}
}
double threshold = 40;
return high >= threshold ? match : null;
}
public class UserFingerprint {
String userId;
FingerprintTemplate template;
}
官方地址: 点击查看